Spaces:
Running
on
Zero
Running
on
Zero
Update Gradio app with multiple files
Browse files
app.py
CHANGED
|
@@ -80,11 +80,22 @@ def chat_with_model(message, history):
|
|
| 80 |
full_response = tokenizer.batch_decode(output)[0]
|
| 81 |
|
| 82 |
# Extract only the assistant's response
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
return assistant_response
|
| 90 |
|
|
|
|
| 80 |
full_response = tokenizer.batch_decode(output)[0]
|
| 81 |
|
| 82 |
# Extract only the assistant's response
|
| 83 |
+
# Find the start of assistant role
|
| 84 |
+
assistant_start = full_response.find('<|start_of_role|>assistant<|end_of_role|>')
|
| 85 |
+
if assistant_start != -1:
|
| 86 |
+
assistant_start += len('<|start_of_role|>assistant<|end_of_role|>')
|
| 87 |
+
assistant_response = full_response[assistant_start:].strip()
|
| 88 |
+
else:
|
| 89 |
+
# Fallback to original method if pattern not found
|
| 90 |
+
response_start = full_response.find('<|assistant|>')
|
| 91 |
+
if response_start != -1:
|
| 92 |
+
response_start += len('<|assistant|>')
|
| 93 |
+
assistant_response = full_response[response_start:].strip()
|
| 94 |
+
else:
|
| 95 |
+
assistant_response = full_response.strip()
|
| 96 |
+
|
| 97 |
+
# Clean up the response - remove end markers
|
| 98 |
+
assistant_response = assistant_response.replace('<|endoftext|>', '').replace('<|end_of_text|>', '').strip()
|
| 99 |
|
| 100 |
return assistant_response
|
| 101 |
|