Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -33,19 +33,18 @@ 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
|
41 |
formatted_text = text
|
42 |
|
43 |
-
# Handle thinking blocks with
|
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);">
|
@@ -59,10 +58,30 @@ def format_thinking_text(text):
|
|
59 |
|
60 |
'''
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
formatted_text = re.sub(thinking_pattern, replace_thinking_block, formatted_text, flags=re.DOTALL)
|
|
|
63 |
|
64 |
-
# Clean up any remaining raw tags
|
65 |
-
formatted_text = re.sub(r'</?think>', '', formatted_text)
|
66 |
|
67 |
return formatted_text.strip()
|
68 |
|
@@ -174,176 +193,433 @@ def chat_interface(message, history, max_tokens, temperature, top_p):
|
|
174 |
print("Initializing model...")
|
175 |
load_model()
|
176 |
|
177 |
-
#
|
178 |
custom_css = """
|
179 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
.chatbot {
|
181 |
-
font-size:
|
182 |
-
font-family: '
|
|
|
|
|
|
|
|
|
183 |
}
|
184 |
|
185 |
-
|
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 |
-
|
193 |
-
|
194 |
-
position: relative;
|
195 |
}
|
196 |
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
|
|
200 |
}
|
201 |
|
202 |
-
.chatbot .message
|
203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
}
|
205 |
|
206 |
-
/*
|
207 |
-
.
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
|
|
|
|
212 |
}
|
213 |
|
214 |
-
.
|
215 |
-
|
216 |
-
|
217 |
-
border-bottom-right-radius: 4px;
|
218 |
}
|
219 |
|
220 |
-
.
|
221 |
-
|
222 |
-
|
223 |
-
|
|
|
|
|
|
|
224 |
}
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
border: 1px solid #e9ecef;
|
230 |
-
border-radius: 6px;
|
231 |
-
padding: 12px;
|
232 |
-
overflow-x: auto;
|
233 |
-
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
234 |
-
font-size: 13px;
|
235 |
-
line-height: 1.4;
|
236 |
}
|
237 |
|
238 |
/* Button styling */
|
239 |
.gradio-button {
|
240 |
-
border-radius:
|
241 |
-
font-weight:
|
242 |
-
|
|
|
|
|
|
|
|
|
243 |
}
|
244 |
|
245 |
-
.gradio-button
|
246 |
-
|
247 |
-
|
|
|
248 |
}
|
249 |
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
border: 2px solid #e0e0e0;
|
254 |
-
transition: border-color 0.2s ease;
|
255 |
}
|
256 |
|
257 |
-
.gradio-
|
258 |
-
|
259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
}
|
261 |
|
262 |
/* Slider styling */
|
263 |
.gradio-slider {
|
264 |
-
margin:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
}
|
266 |
|
267 |
/* Examples styling */
|
268 |
.gradio-examples {
|
269 |
-
margin-top:
|
270 |
}
|
271 |
|
272 |
.gradio-examples .gradio-button {
|
273 |
-
background:
|
274 |
-
border: 1px solid
|
275 |
-
color: #
|
276 |
-
font-size: 13px;
|
277 |
-
padding:
|
|
|
|
|
|
|
278 |
}
|
279 |
|
280 |
.gradio-examples .gradio-button:hover {
|
281 |
-
background: linear-gradient(135deg, #
|
282 |
-
color:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
}
|
284 |
"""
|
285 |
|
286 |
-
# Create Gradio interface
|
287 |
with gr.Blocks(
|
288 |
-
title="
|
289 |
theme=gr.themes.Soft(),
|
290 |
-
css=custom_css
|
|
|
|
|
|
|
|
|
291 |
) as demo:
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
with gr.Column(scale=4):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
chatbot = gr.Chatbot(
|
310 |
[],
|
311 |
elem_id="chatbot",
|
|
|
312 |
bubble_full_width=False,
|
313 |
-
height=
|
314 |
show_copy_button=True,
|
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}
|
322 |
-
]
|
|
|
|
|
323 |
)
|
324 |
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
max_tokens = gr.Slider(
|
341 |
minimum=50,
|
342 |
maximum=8192,
|
343 |
value=2048,
|
344 |
step=50,
|
345 |
label="๐ฏ Max Tokens",
|
346 |
-
info="Maximum number of tokens to generate"
|
|
|
347 |
)
|
348 |
|
349 |
temperature = gr.Slider(
|
@@ -352,7 +628,8 @@ with gr.Blocks(
|
|
352 |
value=0.7,
|
353 |
step=0.1,
|
354 |
label="๐ก๏ธ Temperature",
|
355 |
-
info="Higher = more creative, Lower = more focused"
|
|
|
356 |
)
|
357 |
|
358 |
top_p = gr.Slider(
|
@@ -361,22 +638,76 @@ with gr.Blocks(
|
|
361 |
value=0.9,
|
362 |
step=0.05,
|
363 |
label="๐ฒ Top-p",
|
364 |
-
info="Nucleus sampling threshold"
|
|
|
365 |
)
|
366 |
|
|
|
367 |
with gr.Row():
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
""
|
378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
380 |
# Event handlers
|
381 |
def clear_chat():
|
382 |
"""Clear the chat history"""
|
@@ -406,43 +737,65 @@ with gr.Blocks(
|
|
406 |
show_progress=False
|
407 |
)
|
408 |
|
409 |
-
#
|
410 |
-
with gr.Row():
|
411 |
-
gr.
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
|
445 |
if __name__ == "__main__":
|
|
|
446 |
demo.queue(
|
447 |
max_size=20,
|
448 |
default_concurrency_limit=1
|
@@ -451,5 +804,9 @@ if __name__ == "__main__":
|
|
451 |
server_port=7860,
|
452 |
share=False,
|
453 |
show_error=True,
|
454 |
-
quiet=False
|
|
|
|
|
|
|
|
|
455 |
)
|
|
|
33 |
print("Model loaded successfully!")
|
34 |
|
35 |
def format_thinking_text(text):
|
36 |
+
"""Format text to properly display <think> and <ser> tags in Gradio with styled borders"""
|
37 |
if not text:
|
38 |
return text
|
39 |
|
40 |
+
# More sophisticated formatting for thinking and ser blocks
|
41 |
formatted_text = text
|
42 |
|
43 |
+
# Handle thinking blocks with blue styling
|
44 |
thinking_pattern = r'<think>(.*?)</think>'
|
45 |
|
46 |
def replace_thinking_block(match):
|
47 |
thinking_content = match.group(1).strip()
|
|
|
48 |
return f'''
|
49 |
|
50 |
<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);">
|
|
|
58 |
|
59 |
'''
|
60 |
|
61 |
+
# Handle ser blocks with green styling
|
62 |
+
ser_pattern = r'<ser>(.*?)</ser>'
|
63 |
+
|
64 |
+
def replace_ser_block(match):
|
65 |
+
ser_content = match.group(1).strip()
|
66 |
+
return f'''
|
67 |
+
|
68 |
+
<div style="border-left: 4px solid #28a745; background: linear-gradient(135deg, #f0fff4 0%, #e6ffed 100%); padding: 16px 20px; margin: 16px 0; border-radius: 12px; font-family: 'Segoe UI', sans-serif; box-shadow: 0 2px 8px rgba(40, 167, 69, 0.15); border: 1px solid rgba(40, 167, 69, 0.2);">
|
69 |
+
<div style="color: #28a745; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; font-size: 14px;">
|
70 |
+
<span style="margin-right: 8px;">๐</span> Ser
|
71 |
+
</div>
|
72 |
+
<div style="color: #155724; line-height: 1.6; font-size: 14px;">
|
73 |
+
{ser_content}
|
74 |
+
</div>
|
75 |
+
</div>
|
76 |
+
|
77 |
+
'''
|
78 |
+
|
79 |
+
# Apply both patterns
|
80 |
formatted_text = re.sub(thinking_pattern, replace_thinking_block, formatted_text, flags=re.DOTALL)
|
81 |
+
formatted_text = re.sub(ser_pattern, replace_ser_block, formatted_text, flags=re.DOTALL)
|
82 |
|
83 |
+
# Clean up any remaining raw tags
|
84 |
+
formatted_text = re.sub(r'</?(?:think|ser)>', '', formatted_text)
|
85 |
|
86 |
return formatted_text.strip()
|
87 |
|
|
|
193 |
print("Initializing model...")
|
194 |
load_model()
|
195 |
|
196 |
+
# Advanced CSS for professional UI design
|
197 |
custom_css = """
|
198 |
+
/* Import Google Fonts */
|
199 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');
|
200 |
+
|
201 |
+
/* Global styling */
|
202 |
+
* {
|
203 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
204 |
+
}
|
205 |
+
|
206 |
+
/* Main container */
|
207 |
+
.gradio-container {
|
208 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
209 |
+
min-height: 100vh;
|
210 |
+
}
|
211 |
+
|
212 |
+
/* Header styling */
|
213 |
+
.header-container {
|
214 |
+
background: rgba(255, 255, 255, 0.95);
|
215 |
+
backdrop-filter: blur(20px);
|
216 |
+
border-radius: 20px;
|
217 |
+
padding: 24px;
|
218 |
+
margin-bottom: 24px;
|
219 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
220 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
221 |
+
}
|
222 |
+
|
223 |
+
/* Main chat container */
|
224 |
+
.chat-container {
|
225 |
+
background: rgba(255, 255, 255, 0.95);
|
226 |
+
backdrop-filter: blur(20px);
|
227 |
+
border-radius: 20px;
|
228 |
+
padding: 24px;
|
229 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
230 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
231 |
+
}
|
232 |
+
|
233 |
+
/* Chatbot styling */
|
234 |
.chatbot {
|
235 |
+
font-size: 15px;
|
236 |
+
font-family: 'Inter', sans-serif;
|
237 |
+
background: transparent;
|
238 |
+
border: none;
|
239 |
+
border-radius: 16px;
|
240 |
+
overflow: hidden;
|
241 |
}
|
242 |
|
243 |
+
.chatbot .message {
|
|
|
|
|
|
|
|
|
|
|
244 |
margin: 12px 0;
|
245 |
+
padding: 0;
|
246 |
+
background: transparent;
|
|
|
247 |
}
|
248 |
|
249 |
+
.chatbot .message.user {
|
250 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
251 |
+
color: white;
|
252 |
+
border-radius: 18px 18px 4px 18px;
|
253 |
+
padding: 16px 20px;
|
254 |
+
margin-left: 20%;
|
255 |
+
box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3);
|
256 |
}
|
257 |
|
258 |
+
.chatbot .message.bot {
|
259 |
+
background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
|
260 |
+
color: #2c3e50;
|
261 |
+
border-radius: 18px 18px 18px 4px;
|
262 |
+
padding: 16px 20px;
|
263 |
+
margin-right: 20%;
|
264 |
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
|
265 |
+
border: 1px solid rgba(0, 0, 0, 0.05);
|
266 |
}
|
267 |
|
268 |
+
/* Input styling */
|
269 |
+
.input-container {
|
270 |
+
background: rgba(255, 255, 255, 0.9);
|
271 |
+
border-radius: 25px;
|
272 |
+
padding: 8px;
|
273 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
274 |
+
border: 2px solid transparent;
|
275 |
+
transition: all 0.3s ease;
|
276 |
}
|
277 |
|
278 |
+
.input-container:focus-within {
|
279 |
+
border-color: #667eea;
|
280 |
+
box-shadow: 0 4px 20px rgba(102, 126, 234, 0.2);
|
|
|
281 |
}
|
282 |
|
283 |
+
.gradio-textbox {
|
284 |
+
border: none !important;
|
285 |
+
background: transparent !important;
|
286 |
+
font-size: 15px;
|
287 |
+
padding: 12px 20px;
|
288 |
+
border-radius: 20px;
|
289 |
+
font-family: 'Inter', sans-serif;
|
290 |
}
|
291 |
|
292 |
+
.gradio-textbox:focus {
|
293 |
+
outline: none !important;
|
294 |
+
box-shadow: none !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
}
|
296 |
|
297 |
/* Button styling */
|
298 |
.gradio-button {
|
299 |
+
border-radius: 20px !important;
|
300 |
+
font-weight: 600 !important;
|
301 |
+
font-family: 'Inter', sans-serif !important;
|
302 |
+
transition: all 0.3s ease !important;
|
303 |
+
border: none !important;
|
304 |
+
font-size: 14px !important;
|
305 |
+
padding: 12px 24px !important;
|
306 |
}
|
307 |
|
308 |
+
.gradio-button.primary {
|
309 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
310 |
+
color: white !important;
|
311 |
+
box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3) !important;
|
312 |
}
|
313 |
|
314 |
+
.gradio-button.primary:hover {
|
315 |
+
transform: translateY(-2px) !important;
|
316 |
+
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4) !important;
|
|
|
|
|
317 |
}
|
318 |
|
319 |
+
.gradio-button.secondary {
|
320 |
+
background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%) !important;
|
321 |
+
color: #495057 !important;
|
322 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
|
323 |
+
}
|
324 |
+
|
325 |
+
.gradio-button.secondary:hover {
|
326 |
+
transform: translateY(-1px) !important;
|
327 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
|
328 |
+
}
|
329 |
+
|
330 |
+
/* Parameter panel styling */
|
331 |
+
.parameter-panel {
|
332 |
+
background: rgba(255, 255, 255, 0.9);
|
333 |
+
backdrop-filter: blur(20px);
|
334 |
+
border-radius: 20px;
|
335 |
+
padding: 24px;
|
336 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
337 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
338 |
}
|
339 |
|
340 |
/* Slider styling */
|
341 |
.gradio-slider {
|
342 |
+
margin: 16px 0 !important;
|
343 |
+
}
|
344 |
+
|
345 |
+
.gradio-slider .wrap {
|
346 |
+
background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
|
347 |
+
border-radius: 12px;
|
348 |
+
padding: 16px;
|
349 |
+
border: 1px solid rgba(0, 0, 0, 0.05);
|
350 |
}
|
351 |
|
352 |
/* Examples styling */
|
353 |
.gradio-examples {
|
354 |
+
margin-top: 20px;
|
355 |
}
|
356 |
|
357 |
.gradio-examples .gradio-button {
|
358 |
+
background: rgba(255, 255, 255, 0.8) !important;
|
359 |
+
border: 1px solid rgba(102, 126, 234, 0.2) !important;
|
360 |
+
color: #667eea !important;
|
361 |
+
font-size: 13px !important;
|
362 |
+
padding: 10px 16px !important;
|
363 |
+
margin: 4px !important;
|
364 |
+
border-radius: 15px !important;
|
365 |
+
transition: all 0.2s ease !important;
|
366 |
}
|
367 |
|
368 |
.gradio-examples .gradio-button:hover {
|
369 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
370 |
+
color: white !important;
|
371 |
+
transform: translateY(-1px) !important;
|
372 |
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
|
373 |
+
}
|
374 |
+
|
375 |
+
/* Footer styling */
|
376 |
+
.footer-container {
|
377 |
+
background: rgba(255, 255, 255, 0.9);
|
378 |
+
backdrop-filter: blur(20px);
|
379 |
+
border-radius: 20px;
|
380 |
+
padding: 20px;
|
381 |
+
margin-top: 24px;
|
382 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
383 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
384 |
+
text-align: center;
|
385 |
+
}
|
386 |
+
|
387 |
+
/* Animations */
|
388 |
+
@keyframes fadeInUp {
|
389 |
+
from {
|
390 |
+
opacity: 0;
|
391 |
+
transform: translateY(30px);
|
392 |
+
}
|
393 |
+
to {
|
394 |
+
opacity: 1;
|
395 |
+
transform: translateY(0);
|
396 |
+
}
|
397 |
+
}
|
398 |
+
|
399 |
+
@keyframes pulse {
|
400 |
+
0%, 100% {
|
401 |
+
opacity: 1;
|
402 |
+
}
|
403 |
+
50% {
|
404 |
+
opacity: 0.5;
|
405 |
+
}
|
406 |
+
}
|
407 |
+
|
408 |
+
@keyframes slideIn {
|
409 |
+
from {
|
410 |
+
opacity: 0;
|
411 |
+
transform: translateX(-20px);
|
412 |
+
}
|
413 |
+
to {
|
414 |
+
opacity: 1;
|
415 |
+
transform: translateX(0);
|
416 |
+
}
|
417 |
+
}
|
418 |
+
|
419 |
+
.animate-fade-in {
|
420 |
+
animation: fadeInUp 0.6s ease-out;
|
421 |
+
}
|
422 |
+
|
423 |
+
.animate-slide-in {
|
424 |
+
animation: slideIn 0.4s ease-out;
|
425 |
+
}
|
426 |
+
|
427 |
+
/* Loading states */
|
428 |
+
.loading {
|
429 |
+
position: relative;
|
430 |
+
overflow: hidden;
|
431 |
+
}
|
432 |
+
|
433 |
+
.loading::after {
|
434 |
+
content: '';
|
435 |
+
position: absolute;
|
436 |
+
top: 0;
|
437 |
+
left: -100%;
|
438 |
+
width: 100%;
|
439 |
+
height: 100%;
|
440 |
+
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
|
441 |
+
animation: shimmer 1.5s infinite;
|
442 |
+
}
|
443 |
+
|
444 |
+
@keyframes shimmer {
|
445 |
+
0% { left: -100%; }
|
446 |
+
100% { left: 100%; }
|
447 |
+
}
|
448 |
+
|
449 |
+
/* Responsive design */
|
450 |
+
@media (max-width: 768px) {
|
451 |
+
.chat-container, .parameter-panel, .header-container {
|
452 |
+
margin: 12px;
|
453 |
+
padding: 16px;
|
454 |
+
border-radius: 16px;
|
455 |
+
}
|
456 |
+
|
457 |
+
.chatbot .message.user {
|
458 |
+
margin-left: 10%;
|
459 |
+
}
|
460 |
+
|
461 |
+
.chatbot .message.bot {
|
462 |
+
margin-right: 10%;
|
463 |
+
}
|
464 |
+
}
|
465 |
+
|
466 |
+
/* Dark mode support */
|
467 |
+
@media (prefers-color-scheme: dark) {
|
468 |
+
.gradio-container {
|
469 |
+
background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
|
470 |
+
}
|
471 |
+
|
472 |
+
.chat-container, .parameter-panel, .header-container, .footer-container {
|
473 |
+
background: rgba(45, 55, 72, 0.95);
|
474 |
+
color: #e2e8f0;
|
475 |
+
}
|
476 |
+
|
477 |
+
.chatbot .message.bot {
|
478 |
+
background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
|
479 |
+
color: #e2e8f0;
|
480 |
+
}
|
481 |
}
|
482 |
"""
|
483 |
|
484 |
+
# Create advanced Gradio interface with professional design
|
485 |
with gr.Blocks(
|
486 |
+
title="๏ฟฝ Dhanishtha-2.0-preview | Advanced Reasoning AI",
|
487 |
theme=gr.themes.Soft(),
|
488 |
+
css=custom_css,
|
489 |
+
head="""
|
490 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
491 |
+
<meta name="description" content="Chat with Dhanishtha-2.0-preview - The world's first LLM with multi-step reasoning capabilities">
|
492 |
+
"""
|
493 |
) as demo:
|
494 |
+
# Header Section
|
495 |
+
with gr.Row(elem_classes="header-container animate-fade-in"):
|
496 |
+
with gr.Column():
|
497 |
+
gr.HTML("""
|
498 |
+
<div style="text-align: center; padding: 20px 0;">
|
499 |
+
<h1 style="font-size: 3em; font-weight: 700; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin: 0; font-family: 'Inter', sans-serif;">
|
500 |
+
๐ง Dhanishtha-2.0-preview
|
501 |
+
</h1>
|
502 |
+
<p style="font-size: 1.2em; color: #6c757d; margin: 10px 0 0 0; font-weight: 400;">
|
503 |
+
Advanced Reasoning AI with Multi-Step Thinking
|
504 |
+
</p>
|
505 |
+
</div>
|
506 |
+
""")
|
507 |
+
|
508 |
+
# Feature highlights
|
509 |
+
with gr.Row():
|
510 |
+
with gr.Column(scale=1):
|
511 |
+
gr.HTML("""
|
512 |
+
<div style="text-align: center; padding: 15px; background: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%); border-radius: 15px; border-left: 4px solid #4a90e2;">
|
513 |
+
<div style="font-size: 2em; margin-bottom: 8px;">๐ง </div>
|
514 |
+
<div style="font-weight: 600; color: #4a90e2;">Think Blocks</div>
|
515 |
+
<div style="font-size: 0.9em; color: #6c757d;">Internal reasoning process</div>
|
516 |
+
</div>
|
517 |
+
""")
|
518 |
+
with gr.Column(scale=1):
|
519 |
+
gr.HTML("""
|
520 |
+
<div style="text-align: center; padding: 15px; background: linear-gradient(135deg, #f0fff4 0%, #e6ffed 100%); border-radius: 15px; border-left: 4px solid #28a745;">
|
521 |
+
<div style="font-size: 2em; margin-bottom: 8px;">๐</div>
|
522 |
+
<div style="font-weight: 600; color: #28a745;">Ser Blocks</div>
|
523 |
+
<div style="font-size: 0.9em; color: #6c757d;">Emotional understanding</div>
|
524 |
+
</div>
|
525 |
+
""")
|
526 |
+
with gr.Column(scale=1):
|
527 |
+
gr.HTML("""
|
528 |
+
<div style="text-align: center; padding: 15px; background: linear-gradient(135deg, #fff5f5 0%, #fed7d7 100%); border-radius: 15px; border-left: 4px solid #e53e3e;">
|
529 |
+
<div style="font-size: 2em; margin-bottom: 8px;">โก</div>
|
530 |
+
<div style="font-weight: 600; color: #e53e3e;">Real-time</div>
|
531 |
+
<div style="font-size: 0.9em; color: #6c757d;">Streaming responses</div>
|
532 |
+
</div>
|
533 |
+
""")
|
534 |
+
with gr.Column(scale=1):
|
535 |
+
gr.HTML("""
|
536 |
+
<div style="text-align: center; padding: 15px; background: linear-gradient(135deg, #fefcbf 0%, #fef08a 100%); border-radius: 15px; border-left: 4px solid #f59e0b;">
|
537 |
+
<div style="font-size: 2em; margin-bottom: 8px;">๐ฏ</div>
|
538 |
+
<div style="font-weight: 600; color: #f59e0b;">Precise</div>
|
539 |
+
<div style="font-size: 0.9em; color: #6c757d;">Step-by-step solutions</div>
|
540 |
+
</div>
|
541 |
+
""")
|
542 |
+
|
543 |
+
# Main Chat Interface
|
544 |
+
with gr.Row(elem_classes="chat-container animate-fade-in"):
|
545 |
with gr.Column(scale=4):
|
546 |
+
# Status indicator
|
547 |
+
gr.HTML("""
|
548 |
+
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; padding: 12px 20px; background: linear-gradient(135deg, #e8f5e8 0%, #f0fff4 100%); border-radius: 12px; border-left: 4px solid #28a745;">
|
549 |
+
<div style="display: flex; align-items: center;">
|
550 |
+
<div style="width: 8px; height: 8px; background: #28a745; border-radius: 50%; margin-right: 8px; animation: pulse 2s infinite;"></div>
|
551 |
+
<span style="font-weight: 600; color: #28a745;">Model Ready</span>
|
552 |
+
</div>
|
553 |
+
<div style="font-size: 0.9em; color: #6c757d;">
|
554 |
+
HelpingAI/Dhanishtha-2.0-preview
|
555 |
+
</div>
|
556 |
+
</div>
|
557 |
+
""")
|
558 |
+
|
559 |
chatbot = gr.Chatbot(
|
560 |
[],
|
561 |
elem_id="chatbot",
|
562 |
+
elem_classes="chat-container",
|
563 |
bubble_full_width=False,
|
564 |
+
height=650,
|
565 |
show_copy_button=True,
|
566 |
show_share_button=True,
|
567 |
+
avatar_images=("๐ค", "๏ฟฝ"),
|
568 |
render_markdown=True,
|
569 |
+
sanitize_html=False, # Allow HTML for thinking and ser blocks
|
570 |
latex_delimiters=[
|
571 |
{"left": "$$", "right": "$$", "display": True},
|
572 |
{"left": "$", "right": "$", "display": False}
|
573 |
+
],
|
574 |
+
container=True,
|
575 |
+
scale=1
|
576 |
)
|
577 |
|
578 |
+
# Enhanced input section
|
579 |
+
with gr.Row(elem_classes="input-container"):
|
580 |
+
with gr.Column(scale=1):
|
581 |
+
msg = gr.Textbox(
|
582 |
+
container=False,
|
583 |
+
placeholder="๐ญ Ask me anything! I'll show you my thinking and reasoning process...",
|
584 |
+
label="",
|
585 |
+
autofocus=True,
|
586 |
+
lines=1,
|
587 |
+
max_lines=4,
|
588 |
+
elem_classes="message-input"
|
589 |
+
)
|
590 |
+
with gr.Column(scale=0, min_width=120):
|
591 |
+
with gr.Row():
|
592 |
+
send_btn = gr.Button(
|
593 |
+
"๐ Send",
|
594 |
+
variant="primary",
|
595 |
+
size="lg",
|
596 |
+
elem_classes="send-button"
|
597 |
+
)
|
598 |
+
clear_btn = gr.Button(
|
599 |
+
"๐๏ธ",
|
600 |
+
variant="secondary",
|
601 |
+
size="lg",
|
602 |
+
elem_classes="clear-button"
|
603 |
+
)
|
604 |
+
|
605 |
+
with gr.Column(scale=1, min_width=320, elem_classes="parameter-panel"):
|
606 |
+
# Parameter header
|
607 |
+
gr.HTML("""
|
608 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
609 |
+
<h3 style="margin: 0; color: #4a5568; font-weight: 600;">โ๏ธ Generation Settings</h3>
|
610 |
+
<p style="margin: 5px 0 0 0; color: #6c757d; font-size: 0.9em;">Fine-tune the AI's responses</p>
|
611 |
+
</div>
|
612 |
+
""")
|
613 |
+
|
614 |
+
# Enhanced sliders with better styling
|
615 |
max_tokens = gr.Slider(
|
616 |
minimum=50,
|
617 |
maximum=8192,
|
618 |
value=2048,
|
619 |
step=50,
|
620 |
label="๐ฏ Max Tokens",
|
621 |
+
info="Maximum number of tokens to generate",
|
622 |
+
elem_classes="parameter-slider"
|
623 |
)
|
624 |
|
625 |
temperature = gr.Slider(
|
|
|
628 |
value=0.7,
|
629 |
step=0.1,
|
630 |
label="๐ก๏ธ Temperature",
|
631 |
+
info="Higher = more creative, Lower = more focused",
|
632 |
+
elem_classes="parameter-slider"
|
633 |
)
|
634 |
|
635 |
top_p = gr.Slider(
|
|
|
638 |
value=0.9,
|
639 |
step=0.05,
|
640 |
label="๐ฒ Top-p",
|
641 |
+
info="Nucleus sampling threshold",
|
642 |
+
elem_classes="parameter-slider"
|
643 |
)
|
644 |
|
645 |
+
# Action buttons
|
646 |
with gr.Row():
|
647 |
+
stop_btn = gr.Button(
|
648 |
+
"โน๏ธ Stop",
|
649 |
+
variant="stop",
|
650 |
+
scale=1,
|
651 |
+
elem_classes="action-button"
|
652 |
+
)
|
653 |
+
|
654 |
+
# Model information card
|
655 |
+
gr.HTML("""
|
656 |
+
<div style="margin-top: 24px; padding: 20px; background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%); border-radius: 16px; border: 1px solid rgba(0,0,0,0.05);">
|
657 |
+
<h4 style="margin: 0 0 12px 0; color: #4a5568; font-weight: 600; display: flex; align-items: center;">
|
658 |
+
<span style="margin-right: 8px;">๐ง </span> Model Information
|
659 |
+
</h4>
|
660 |
+
<div style="space-y: 8px;">
|
661 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 8px;">
|
662 |
+
<span style="color: #6c757d; font-size: 0.9em;">Model:</span>
|
663 |
+
<span style="color: #4a5568; font-weight: 500; font-size: 0.9em;">Dhanishtha-2.0-preview</span>
|
664 |
+
</div>
|
665 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 8px;">
|
666 |
+
<span style="color: #6c757d; font-size: 0.9em;">Type:</span>
|
667 |
+
<span style="color: #4a5568; font-weight: 500; font-size: 0.9em;">Reasoning LLM</span>
|
668 |
+
</div>
|
669 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 8px;">
|
670 |
+
<span style="color: #6c757d; font-size: 0.9em;">Features:</span>
|
671 |
+
<span style="color: #4a5568; font-weight: 500; font-size: 0.9em;">Think + Ser blocks</span>
|
672 |
+
</div>
|
673 |
+
<div style="margin-top: 12px; padding: 8px; background: rgba(74, 144, 226, 0.1); border-radius: 8px; border-left: 3px solid #4a90e2;">
|
674 |
+
<div style="font-size: 0.85em; color: #4a90e2; font-weight: 500;">๐ก Tip</div>
|
675 |
+
<div style="font-size: 0.8em; color: #6c757d; margin-top: 4px;">Ask complex questions to see multi-step reasoning in action!</div>
|
676 |
+
</div>
|
677 |
+
</div>
|
678 |
+
</div>
|
679 |
+
""")
|
680 |
|
681 |
+
# Enhanced Examples Section
|
682 |
+
with gr.Row(elem_classes="examples-container animate-fade-in"):
|
683 |
+
with gr.Column():
|
684 |
+
gr.HTML("""
|
685 |
+
<div style="text-align: center; margin: 24px 0 16px 0;">
|
686 |
+
<h3 style="margin: 0; color: #4a5568; font-weight: 600;">๐ก Try These Examples</h3>
|
687 |
+
<p style="margin: 5px 0 0 0; color: #6c757d; font-size: 0.9em;">Click any example to see the AI's thinking process</p>
|
688 |
+
</div>
|
689 |
+
""")
|
690 |
+
|
691 |
+
gr.Examples(
|
692 |
+
examples=[
|
693 |
+
["๐งฎ Solve this step by step: What is 15% of 240?"],
|
694 |
+
["๐ค How many letter 'r' are in the words 'strawberry' and 'raspberry'?"],
|
695 |
+
["๐ค Hello! Can you introduce yourself and show me how you think?"],
|
696 |
+
["โ๏ธ Explain quantum entanglement in simple terms with examples"],
|
697 |
+
["๐ Write a Python function to find the factorial of a number"],
|
698 |
+
["๐ฑ What are the pros and cons of renewable energy sources?"],
|
699 |
+
["๐ง What's the difference between AI and machine learning?"],
|
700 |
+
["๐จ Create a haiku about artificial intelligence and consciousness"],
|
701 |
+
["๐ Why is the sky blue? Explain using physics principles"],
|
702 |
+
["๐ Compare bubble sort and quick sort algorithms"],
|
703 |
+
["๐ฏ Plan a 7-day trip to Japan with budget considerations"],
|
704 |
+
["๐ฌ How does CRISPR gene editing work in simple terms?"]
|
705 |
+
],
|
706 |
+
inputs=msg,
|
707 |
+
examples_per_page=6,
|
708 |
+
elem_classes="example-grid"
|
709 |
+
)
|
710 |
+
|
711 |
# Event handlers
|
712 |
def clear_chat():
|
713 |
"""Clear the chat history"""
|
|
|
737 |
show_progress=False
|
738 |
)
|
739 |
|
740 |
+
# Enhanced Footer
|
741 |
+
with gr.Row(elem_classes="footer-container animate-fade-in"):
|
742 |
+
with gr.Column():
|
743 |
+
gr.HTML("""
|
744 |
+
<div style="text-align: center; padding: 20px 0;">
|
745 |
+
<div style="display: flex; justify-content: center; align-items: center; margin-bottom: 16px;">
|
746 |
+
<div style="height: 1px; background: linear-gradient(90deg, transparent, #667eea, transparent); flex: 1;"></div>
|
747 |
+
<span style="margin: 0 20px; color: #6c757d; font-weight: 500;">Technical Specifications</span>
|
748 |
+
<div style="height: 1px; background: linear-gradient(90deg, transparent, #667eea, transparent); flex: 1;"></div>
|
749 |
+
</div>
|
750 |
+
|
751 |
+
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 20px;">
|
752 |
+
<div style="text-align: center;">
|
753 |
+
<div style="font-size: 1.5em; margin-bottom: 8px;">๐ง </div>
|
754 |
+
<div style="font-weight: 600; color: #4a5568;">Model Architecture</div>
|
755 |
+
<div style="font-size: 0.9em; color: #6c757d;">Transformer-based reasoning</div>
|
756 |
+
</div>
|
757 |
+
<div style="text-align: center;">
|
758 |
+
<div style="font-size: 1.5em; margin-bottom: 8px;">โก</div>
|
759 |
+
<div style="font-weight: 600; color: #4a5568;">Real-time Streaming</div>
|
760 |
+
<div style="font-size: 0.9em; color: #6c757d;">Token-by-token generation</div>
|
761 |
+
</div>
|
762 |
+
<div style="text-align: center;">
|
763 |
+
<div style="font-size: 1.5em; margin-bottom: 8px;">๐ฏ</div>
|
764 |
+
<div style="font-weight: 600; color: #4a5568;">Advanced Reasoning</div>
|
765 |
+
<div style="font-size: 0.9em; color: #6c757d;">Multi-step thinking process</div>
|
766 |
+
</div>
|
767 |
+
<div style="text-align: center;">
|
768 |
+
<div style="font-size: 1.5em; margin-bottom: 8px;">๐ง</div>
|
769 |
+
<div style="font-weight: 600; color: #4a5568;">Custom Sampling</div>
|
770 |
+
<div style="font-size: 0.9em; color: #6c757d;">Temperature & Top-p control</div>
|
771 |
+
</div>
|
772 |
+
</div>
|
773 |
+
|
774 |
+
<div style="background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%); border-radius: 12px; padding: 16px; margin: 16px 0; border: 1px solid rgba(0,0,0,0.05);">
|
775 |
+
<div style="font-weight: 600; color: #4a5568; margin-bottom: 8px;">๐ Key Features</div>
|
776 |
+
<div style="display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;">
|
777 |
+
<span style="background: #e3f2fd; color: #1976d2; padding: 4px 12px; border-radius: 20px; font-size: 0.85em;">Think Blocks</span>
|
778 |
+
<span style="background: #e8f5e8; color: #2e7d32; padding: 4px 12px; border-radius: 20px; font-size: 0.85em;">Ser Blocks</span>
|
779 |
+
<span style="background: #fff3e0; color: #f57c00; padding: 4px 12px; border-radius: 20px; font-size: 0.85em;">Real-time Streaming</span>
|
780 |
+
<span style="background: #fce4ec; color: #c2185b; padding: 4px 12px; border-radius: 20px; font-size: 0.85em;">LaTeX Support</span>
|
781 |
+
<span style="background: #f3e5f5; color: #7b1fa2; padding: 4px 12px; border-radius: 20px; font-size: 0.85em;">Code Highlighting</span>
|
782 |
+
</div>
|
783 |
+
</div>
|
784 |
+
|
785 |
+
<div style="margin-top: 20px; padding-top: 16px; border-top: 1px solid rgba(0,0,0,0.1);">
|
786 |
+
<div style="color: #6c757d; font-size: 0.9em;">
|
787 |
+
Built with โค๏ธ using <strong>Gradio</strong> and <strong>Transformers</strong> |
|
788 |
+
Model: <strong>HelpingAI/Dhanishtha-2.0-preview</strong>
|
789 |
+
</div>
|
790 |
+
<div style="color: #6c757d; font-size: 0.8em; margin-top: 4px;">
|
791 |
+
Experience the future of AI reasoning with transparent thinking processes
|
792 |
+
</div>
|
793 |
+
</div>
|
794 |
+
</div>
|
795 |
+
""")
|
796 |
|
797 |
if __name__ == "__main__":
|
798 |
+
# Launch with enhanced configuration
|
799 |
demo.queue(
|
800 |
max_size=20,
|
801 |
default_concurrency_limit=1
|
|
|
804 |
server_port=7860,
|
805 |
share=False,
|
806 |
show_error=True,
|
807 |
+
quiet=False,
|
808 |
+
favicon_path=None,
|
809 |
+
ssl_verify=False,
|
810 |
+
show_tips=True,
|
811 |
+
enable_queue=True
|
812 |
)
|