Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,22 +81,29 @@ def generate_response(
|
|
| 81 |
# Remove leftover special tokens
|
| 82 |
response = response.replace("<|im_end|>", "").strip()
|
| 83 |
|
| 84 |
-
# Remove any label and text following it on the same line
|
| 85 |
lines = response.splitlines()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
cleaned_lines = []
|
| 87 |
for line in lines:
|
| 88 |
for label in ["Assistant:", "assistant:", "User:", "user:"]:
|
| 89 |
if label in line:
|
| 90 |
line = line.split(label)[0].strip()
|
| 91 |
-
if line:
|
| 92 |
cleaned_lines.append(line)
|
| 93 |
|
| 94 |
response = "\n".join(cleaned_lines)
|
| 95 |
-
|
| 96 |
return response
|
| 97 |
|
| 98 |
|
| 99 |
|
|
|
|
| 100 |
# Respond function for Gradio
|
| 101 |
def respond(
|
| 102 |
message,
|
|
|
|
| 81 |
# Remove leftover special tokens
|
| 82 |
response = response.replace("<|im_end|>", "").strip()
|
| 83 |
|
|
|
|
| 84 |
lines = response.splitlines()
|
| 85 |
+
|
| 86 |
+
# If the first line starts with Assistant:, return only the rest of that line
|
| 87 |
+
first_line = lines[0].strip() if lines else ""
|
| 88 |
+
for label in ["Assistant:", "assistant:"]:
|
| 89 |
+
if first_line.lower().startswith(label.lower()):
|
| 90 |
+
return first_line[len(label):].strip()
|
| 91 |
+
|
| 92 |
+
# Otherwise, clean each line by removing any label and following text
|
| 93 |
cleaned_lines = []
|
| 94 |
for line in lines:
|
| 95 |
for label in ["Assistant:", "assistant:", "User:", "user:"]:
|
| 96 |
if label in line:
|
| 97 |
line = line.split(label)[0].strip()
|
| 98 |
+
if line:
|
| 99 |
cleaned_lines.append(line)
|
| 100 |
|
| 101 |
response = "\n".join(cleaned_lines)
|
|
|
|
| 102 |
return response
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
+
|
| 107 |
# Respond function for Gradio
|
| 108 |
def respond(
|
| 109 |
message,
|