Spaces:
Running
Running
update
Browse files
app.py
CHANGED
|
@@ -68,13 +68,41 @@ def respond(
|
|
| 68 |
if 'content' in delta:
|
| 69 |
content = delta['content']
|
| 70 |
if content:
|
| 71 |
-
content = content.replace('<', '<').replace('>', '>')
|
| 72 |
-
content = content.replace('*', '\\*')
|
| 73 |
current_response += content
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
except json.JSONDecodeError:
|
| 76 |
continue
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
else:
|
| 79 |
print(f"[ERROR] Bad status code: {r.status_code}, response: {r.text}")
|
| 80 |
yield "Service temporarily unavailable"
|
|
@@ -100,7 +128,40 @@ demo = gr.ChatInterface(
|
|
| 100 |
label="Top-p (nucleus sampling)",
|
| 101 |
),
|
| 102 |
],
|
| 103 |
-
type="messages"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
)
|
| 105 |
|
| 106 |
|
|
|
|
| 68 |
if 'content' in delta:
|
| 69 |
content = delta['content']
|
| 70 |
if content:
|
|
|
|
|
|
|
| 71 |
current_response += content
|
| 72 |
+
|
| 73 |
+
if len(current_response) > 16:
|
| 74 |
+
if '<think>' in current_response:
|
| 75 |
+
current_response = current_response.replace('<think>', '<details open><summary>Thinking</summary>\n\n```')
|
| 76 |
+
if '</think>' in current_response:
|
| 77 |
+
current_response = current_response.replace('</think>', '```\n\n</details>')
|
| 78 |
+
if '**Final Answer**' in current_response:
|
| 79 |
+
current_response = current_response.replace('**Final Answer**', '')
|
| 80 |
+
|
| 81 |
+
formatted_response = current_response[:-16]
|
| 82 |
+
|
| 83 |
+
formatted_response = formatted_response.replace('<', '<').replace('>', '>')
|
| 84 |
+
formatted_response = formatted_response.replace('<details open>', '<details open>')
|
| 85 |
+
formatted_response = formatted_response.replace('</details>', '</details>')
|
| 86 |
+
formatted_response = formatted_response.replace('<summary>', '<summary>')
|
| 87 |
+
formatted_response = formatted_response.replace('</summary>', '</summary>')
|
| 88 |
+
formatted_response = formatted_response.replace('*', '\\*')
|
| 89 |
+
yield formatted_response
|
| 90 |
except json.JSONDecodeError:
|
| 91 |
continue
|
| 92 |
+
if current_response:
|
| 93 |
+
# current_response = current_response.replace('<details open>', '<details>')
|
| 94 |
+
if '**Final Answer**' in current_response:
|
| 95 |
+
current_response = current_response.replace('**Final Answer**', '')
|
| 96 |
+
|
| 97 |
+
formatted_response = current_response
|
| 98 |
+
formatted_response = formatted_response.replace('<', '<').replace('>', '>')
|
| 99 |
+
formatted_response = formatted_response.replace('<details open>', '<details open>')
|
| 100 |
+
# formatted_response = formatted_response.replace('<details>', '<details>')
|
| 101 |
+
formatted_response = formatted_response.replace('</details>', '</details>')
|
| 102 |
+
formatted_response = formatted_response.replace('<summary>', '<summary>')
|
| 103 |
+
formatted_response = formatted_response.replace('</summary>', '</summary>')
|
| 104 |
+
formatted_response = formatted_response.replace('*', '\\*')
|
| 105 |
+
yield formatted_response
|
| 106 |
else:
|
| 107 |
print(f"[ERROR] Bad status code: {r.status_code}, response: {r.text}")
|
| 108 |
yield "Service temporarily unavailable"
|
|
|
|
| 128 |
label="Top-p (nucleus sampling)",
|
| 129 |
),
|
| 130 |
],
|
| 131 |
+
type="messages",
|
| 132 |
+
css="""
|
| 133 |
+
.prose pre {
|
| 134 |
+
white-space: pre-wrap !important;
|
| 135 |
+
word-wrap: break-word !important;
|
| 136 |
+
overflow-wrap: break-word !important;
|
| 137 |
+
max-width: 100% !important;
|
| 138 |
+
margin-bottom: 1.5em !important;
|
| 139 |
+
}
|
| 140 |
+
.prose code {
|
| 141 |
+
white-space: pre-wrap !important;
|
| 142 |
+
word-wrap: break-word !important;
|
| 143 |
+
overflow-wrap: break-word !important;
|
| 144 |
+
max-width: 100% !important;
|
| 145 |
+
}
|
| 146 |
+
.prose pre code {
|
| 147 |
+
white-space: pre-wrap !important;
|
| 148 |
+
word-wrap: break-word !important;
|
| 149 |
+
overflow-wrap: break-word !important;
|
| 150 |
+
max-width: 100% !important;
|
| 151 |
+
}
|
| 152 |
+
.accordion {
|
| 153 |
+
margin: 0 !important;
|
| 154 |
+
border: none !important;
|
| 155 |
+
}
|
| 156 |
+
.accordion-header {
|
| 157 |
+
background: #f0f0f0 !important;
|
| 158 |
+
padding: 8px !important;
|
| 159 |
+
cursor: pointer !important;
|
| 160 |
+
}
|
| 161 |
+
.accordion-content {
|
| 162 |
+
padding: 8px !important;
|
| 163 |
+
}
|
| 164 |
+
"""
|
| 165 |
)
|
| 166 |
|
| 167 |
|