Spaces:
Running
Running
Reality123b
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ class ChatMessage:
|
|
13 |
role: str
|
14 |
content: str
|
15 |
|
16 |
-
def
|
17 |
"""Converts ChatMessage to a dictionary for JSON serialization."""
|
18 |
return {"role": self.role, "content": self.content}
|
19 |
|
@@ -39,7 +39,7 @@ class XylariaChat:
|
|
39 |
self.persistent_memory = {}
|
40 |
|
41 |
# System prompt with more detailed instructions
|
42 |
-
self.system_prompt = """You are a helpful and harmless assistant. You are Xylaria developed by Sk Md Saad Amin
|
43 |
|
44 |
def store_information(self, key, value):
|
45 |
"""Store important information in persistent memory"""
|
@@ -297,14 +297,14 @@ class XylariaChat:
|
|
297 |
}
|
298 |
/* Image Upload Styling */
|
299 |
.image-container {
|
|
|
|
|
|
|
|
|
|
|
300 |
border: 1px solid #ccc;
|
301 |
border-radius: 8px;
|
302 |
padding: 10px;
|
303 |
-
margin-bottom: 10px;
|
304 |
-
display: flex;
|
305 |
-
flex-direction: column;
|
306 |
-
align-items: center;
|
307 |
-
gap: 10px;
|
308 |
background-color: #f8f8f8;
|
309 |
}
|
310 |
.image-preview {
|
@@ -312,20 +312,24 @@ class XylariaChat:
|
|
312 |
max-height: 200px;
|
313 |
border-radius: 8px;
|
314 |
}
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
}
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
color: white;
|
324 |
-
border: none;
|
325 |
-
cursor: pointer;
|
326 |
}
|
327 |
-
|
328 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
}
|
330 |
"""
|
331 |
|
@@ -340,26 +344,22 @@ class XylariaChat:
|
|
340 |
|
341 |
# Enhanced Image Upload Section
|
342 |
with gr.Accordion("Image Input", open=False):
|
343 |
-
with gr.
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
elem_classes="image-preview"
|
360 |
-
)
|
361 |
-
with gr.Row():
|
362 |
-
clear_math_ocr_btn = gr.Button("Clear Math Image")
|
363 |
|
364 |
# Input row with improved layout
|
365 |
with gr.Row():
|
@@ -376,22 +376,6 @@ class XylariaChat:
|
|
376 |
clear = gr.Button("Clear Conversation")
|
377 |
clear_memory = gr.Button("Clear Memory")
|
378 |
|
379 |
-
# Clear image functionality
|
380 |
-
clear_image_btn.click(
|
381 |
-
fn=lambda: None,
|
382 |
-
inputs=None,
|
383 |
-
outputs=[img],
|
384 |
-
queue=False
|
385 |
-
)
|
386 |
-
|
387 |
-
# Clear Math OCR image functionality
|
388 |
-
clear_math_ocr_btn.click(
|
389 |
-
fn=lambda: None,
|
390 |
-
inputs=None,
|
391 |
-
outputs=[math_ocr_img],
|
392 |
-
queue=False
|
393 |
-
)
|
394 |
-
|
395 |
# Submit functionality with streaming and image support
|
396 |
btn.click(
|
397 |
fn=streaming_response,
|
|
|
13 |
role: str
|
14 |
content: str
|
15 |
|
16 |
+
def to_dict__(self):
|
17 |
"""Converts ChatMessage to a dictionary for JSON serialization."""
|
18 |
return {"role": self.role, "content": self.content}
|
19 |
|
|
|
39 |
self.persistent_memory = {}
|
40 |
|
41 |
# System prompt with more detailed instructions
|
42 |
+
self.system_prompt = """You are a helpful and harmless assistant. You are Xylaria developed by Sk Md Saad Amin . You should think step-by-step."""
|
43 |
|
44 |
def store_information(self, key, value):
|
45 |
"""Store important information in persistent memory"""
|
|
|
297 |
}
|
298 |
/* Image Upload Styling */
|
299 |
.image-container {
|
300 |
+
display: flex;
|
301 |
+
gap: 10px;
|
302 |
+
margin-bottom: 10px;
|
303 |
+
}
|
304 |
+
.image-upload {
|
305 |
border: 1px solid #ccc;
|
306 |
border-radius: 8px;
|
307 |
padding: 10px;
|
|
|
|
|
|
|
|
|
|
|
308 |
background-color: #f8f8f8;
|
309 |
}
|
310 |
.image-preview {
|
|
|
312 |
max-height: 200px;
|
313 |
border-radius: 8px;
|
314 |
}
|
315 |
+
/* Remove clear image buttons */
|
316 |
+
.clear-button {
|
317 |
+
display: none;
|
318 |
}
|
319 |
+
/* Animate chatbot messages */
|
320 |
+
.chatbot-container .message {
|
321 |
+
opacity: 0;
|
322 |
+
animation: fadeIn 0.5s ease-in-out forwards;
|
|
|
|
|
|
|
323 |
}
|
324 |
+
@keyframes fadeIn {
|
325 |
+
from {
|
326 |
+
opacity: 0;
|
327 |
+
transform: translateY(20px);
|
328 |
+
}
|
329 |
+
to {
|
330 |
+
opacity: 1;
|
331 |
+
transform: translateY(0);
|
332 |
+
}
|
333 |
}
|
334 |
"""
|
335 |
|
|
|
344 |
|
345 |
# Enhanced Image Upload Section
|
346 |
with gr.Accordion("Image Input", open=False):
|
347 |
+
with gr.Row(elem_classes="image-container"): # Use a Row for side-by-side layout
|
348 |
+
with gr.Column(elem_classes="image-upload"):
|
349 |
+
img = gr.Image(
|
350 |
+
sources=["upload", "webcam"],
|
351 |
+
type="filepath",
|
352 |
+
label="Upload Image",
|
353 |
+
elem_classes="image-preview"
|
354 |
+
)
|
355 |
+
with gr.Column(elem_classes="image-upload"):
|
356 |
+
math_ocr_img = gr.Image(
|
357 |
+
sources=["upload", "webcam"],
|
358 |
+
type="filepath",
|
359 |
+
label="Upload Image for Math OCR",
|
360 |
+
elem_classes="image-preview"
|
361 |
+
)
|
362 |
+
# Removed clear buttons as per requirement
|
|
|
|
|
|
|
|
|
363 |
|
364 |
# Input row with improved layout
|
365 |
with gr.Row():
|
|
|
376 |
clear = gr.Button("Clear Conversation")
|
377 |
clear_memory = gr.Button("Clear Memory")
|
378 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
# Submit functionality with streaming and image support
|
380 |
btn.click(
|
381 |
fn=streaming_response,
|