Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,23 +73,22 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 73 |
# Extract content between <user>...</user> tags
|
| 74 |
def extract_user_content(text):
|
| 75 |
"""
|
| 76 |
-
Extracts and returns content between <user>...</user> tags in the given text.
|
| 77 |
If multiple such sections exist, their contents are concatenated.
|
| 78 |
"""
|
| 79 |
-
pattern
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
return extracted_content
|
| 83 |
|
| 84 |
-
# Extract the normalized text
|
| 85 |
-
normalized_text = extract_user_content(generated_text)
|
| 86 |
-
|
| 87 |
-
# Stream the response token by token
|
| 88 |
-
response = ""
|
| 89 |
-
for token in normalized_text.split():
|
| 90 |
-
response += token + " "
|
| 91 |
-
yield response.strip()
|
| 92 |
-
|
| 93 |
# Gradio interface setup
|
| 94 |
demo = gr.ChatInterface(
|
| 95 |
respond,
|
|
|
|
| 73 |
# Extract content between <user>...</user> tags
|
| 74 |
def extract_user_content(text):
|
| 75 |
"""
|
| 76 |
+
Extracts and returns content between <user>...</user> tags or lines starting with 'output:' (case-insensitive) in the given text.
|
| 77 |
If multiple such sections exist, their contents are concatenated.
|
| 78 |
"""
|
| 79 |
+
# Compile the regular expression pattern with re.IGNORECASE flag
|
| 80 |
+
pattern = re.compile(r'<user>(.*?)</user>|^output:\s*(.*)', re.IGNORECASE | re.DOTALL)
|
| 81 |
+
|
| 82 |
+
# Find all matches in the text
|
| 83 |
+
matches = pattern.findall(text)
|
| 84 |
+
|
| 85 |
+
# Extract and concatenate the matched content
|
| 86 |
+
extracted_content = '\n'.join(
|
| 87 |
+
(match[0] or match[1]).strip() for match in matches if match
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
return extracted_content
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
# Gradio interface setup
|
| 93 |
demo = gr.ChatInterface(
|
| 94 |
respond,
|