Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,20 +33,31 @@ def load_model():
|
|
| 33 |
print("Model loaded successfully!")
|
| 34 |
|
| 35 |
def format_thinking_text(text):
|
| 36 |
-
"""Format text to properly display <think> tags in Gradio with
|
| 37 |
if not text:
|
| 38 |
return text
|
| 39 |
|
| 40 |
-
# More sophisticated formatting for thinking blocks
|
| 41 |
-
# Replace <think> and </think> tags with styled markdown
|
| 42 |
formatted_text = text
|
| 43 |
|
| 44 |
-
# Handle thinking blocks with proper
|
| 45 |
thinking_pattern = r'<think>(.*?)</think>'
|
| 46 |
|
| 47 |
def replace_thinking_block(match):
|
| 48 |
thinking_content = match.group(1).strip()
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
formatted_text = re.sub(thinking_pattern, replace_thinking_block, formatted_text, flags=re.DOTALL)
|
| 52 |
|
|
@@ -171,26 +182,25 @@ custom_css = """
|
|
| 171 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 172 |
}
|
| 173 |
|
| 174 |
-
/*
|
| 175 |
.thinking-block {
|
| 176 |
background: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%);
|
| 177 |
border-left: 4px solid #4a90e2;
|
| 178 |
border-radius: 8px;
|
| 179 |
padding: 12px 16px;
|
| 180 |
margin: 12px 0;
|
| 181 |
-
font-family: '
|
| 182 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 183 |
position: relative;
|
| 184 |
}
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
font-size: 16px;
|
| 194 |
}
|
| 195 |
|
| 196 |
/* Message styling */
|
|
@@ -305,6 +315,7 @@ with gr.Blocks(
|
|
| 305 |
show_share_button=True,
|
| 306 |
avatar_images=("👤", "🤖"),
|
| 307 |
render_markdown=True,
|
|
|
|
| 308 |
latex_delimiters=[
|
| 309 |
{"left": "$$", "right": "$$", "display": True},
|
| 310 |
{"left": "$", "right": "$", "display": False}
|
|
|
|
| 33 |
print("Model loaded successfully!")
|
| 34 |
|
| 35 |
def format_thinking_text(text):
|
| 36 |
+
"""Format text to properly display <think> tags in Gradio with blue border styling like HelpingAI"""
|
| 37 |
if not text:
|
| 38 |
return text
|
| 39 |
|
| 40 |
+
# More sophisticated formatting for thinking blocks with blue styling
|
|
|
|
| 41 |
formatted_text = text
|
| 42 |
|
| 43 |
+
# Handle thinking blocks with proper HTML-like styling for Gradio
|
| 44 |
thinking_pattern = r'<think>(.*?)</think>'
|
| 45 |
|
| 46 |
def replace_thinking_block(match):
|
| 47 |
thinking_content = match.group(1).strip()
|
| 48 |
+
# Use HTML div with inline CSS for blue border styling like HelpingAI
|
| 49 |
+
return f'''
|
| 50 |
+
|
| 51 |
+
<div style="border-left: 4px solid #4a90e2; background: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%); padding: 16px 20px; margin: 16px 0; border-radius: 12px; font-family: 'Segoe UI', sans-serif; box-shadow: 0 2px 8px rgba(74, 144, 226, 0.15); border: 1px solid rgba(74, 144, 226, 0.2);">
|
| 52 |
+
<div style="color: #4a90e2; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; font-size: 14px;">
|
| 53 |
+
<span style="margin-right: 8px;">🧠</span> Think
|
| 54 |
+
</div>
|
| 55 |
+
<div style="color: #2c3e50; line-height: 1.6; font-size: 14px;">
|
| 56 |
+
{thinking_content}
|
| 57 |
+
</div>
|
| 58 |
+
</div>
|
| 59 |
+
|
| 60 |
+
'''
|
| 61 |
|
| 62 |
formatted_text = re.sub(thinking_pattern, replace_thinking_block, formatted_text, flags=re.DOTALL)
|
| 63 |
|
|
|
|
| 182 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 183 |
}
|
| 184 |
|
| 185 |
+
/* Enhanced thinking block styling - now handled via inline HTML */
|
| 186 |
.thinking-block {
|
| 187 |
background: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%);
|
| 188 |
border-left: 4px solid #4a90e2;
|
| 189 |
border-radius: 8px;
|
| 190 |
padding: 12px 16px;
|
| 191 |
margin: 12px 0;
|
| 192 |
+
font-family: 'Segoe UI', sans-serif;
|
| 193 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 194 |
position: relative;
|
| 195 |
}
|
| 196 |
|
| 197 |
+
/* Support for HTML content in chatbot */
|
| 198 |
+
.chatbot .message {
|
| 199 |
+
overflow: visible;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.chatbot .message div {
|
| 203 |
+
max-width: none;
|
|
|
|
| 204 |
}
|
| 205 |
|
| 206 |
/* Message styling */
|
|
|
|
| 315 |
show_share_button=True,
|
| 316 |
avatar_images=("👤", "🤖"),
|
| 317 |
render_markdown=True,
|
| 318 |
+
sanitize_html=False, # Allow HTML for thinking blocks
|
| 319 |
latex_delimiters=[
|
| 320 |
{"left": "$$", "right": "$$", "display": True},
|
| 321 |
{"left": "$", "right": "$", "display": False}
|