Reality123b
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -626,30 +626,6 @@ class XylariaChat:
|
|
626 |
|
627 |
def create_interface(self):
|
628 |
def streaming_response(message, chat_history, image_filepath, math_ocr_image_path):
|
629 |
-
# Placeholder for image generation
|
630 |
-
loading_svg = """<svg width="256" height="256" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
|
631 |
-
<style>
|
632 |
-
rect {
|
633 |
-
animation: fillAnimation 3s ease-in-out infinite;
|
634 |
-
}
|
635 |
-
@keyframes fillAnimation {
|
636 |
-
0% { fill: #626262; }
|
637 |
-
50% { fill: #111111; }
|
638 |
-
100% { fill: #626262; }
|
639 |
-
}
|
640 |
-
text {
|
641 |
-
font-family: 'Helvetica Neue', Arial, sans-serif;
|
642 |
-
font-weight: 300;
|
643 |
-
text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.4);
|
644 |
-
}
|
645 |
-
</style>
|
646 |
-
<rect width="256" height="256" rx="20" fill="#888888" />
|
647 |
-
<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-size="24" fill="white" opacity="0.8">
|
648 |
-
<tspan>{/}</tspan>
|
649 |
-
<tspan x="50%" dy="1.2em"></tspan>
|
650 |
-
</text>
|
651 |
-
</svg>"""
|
652 |
-
|
653 |
if message.strip().lower().startswith("/image"):
|
654 |
|
655 |
image_prompt = message.strip().lower()[len("/image"):].strip()
|
@@ -658,8 +634,7 @@ class XylariaChat:
|
|
658 |
|
659 |
|
660 |
chat_history.append([message, ""])
|
661 |
-
|
662 |
-
yield "", chat_history, None, None, None
|
663 |
|
664 |
|
665 |
image_bytes = self.generate_image(image_prompt)
|
@@ -671,20 +646,18 @@ class XylariaChat:
|
|
671 |
|
672 |
chat_history[-1] = ("", image_html)
|
673 |
|
674 |
-
|
675 |
self.conversation_history.append(ChatMessage(role="user", content=message).to_dict())
|
676 |
self.conversation_history.append(ChatMessage(role="assistant", content=image_html).to_dict())
|
677 |
|
678 |
-
|
679 |
self.save_chat()
|
680 |
all_chats = self.load_all_chats()
|
681 |
chat_titles = [f"{chat['timestamp']}: {chat['conversation'][0]['content'][:30]}..." if len(chat['conversation']) > 0 and chat['conversation'][0]['content'] else f"{chat['timestamp']}: Empty Chat" for chat in all_chats]
|
682 |
|
683 |
-
yield "", chat_history, None, None
|
684 |
else:
|
685 |
|
686 |
chat_history[-1] = ("", image_bytes)
|
687 |
-
yield "", chat_history, None, None
|
688 |
return
|
689 |
|
690 |
ocr_text = ""
|
@@ -692,7 +665,7 @@ class XylariaChat:
|
|
692 |
ocr_text = self.perform_math_ocr(math_ocr_image_path)
|
693 |
if ocr_text.startswith("Error"):
|
694 |
updated_history = chat_history + [[message, ocr_text]]
|
695 |
-
yield "", updated_history, None, None
|
696 |
return
|
697 |
else:
|
698 |
message = f"Math OCR Result: {ocr_text}\n\nUser's message: {message}"
|
@@ -704,7 +677,7 @@ class XylariaChat:
|
|
704 |
|
705 |
if isinstance(response_stream, str):
|
706 |
updated_history = chat_history + [[message, response_stream]]
|
707 |
-
yield "", updated_history, None, None
|
708 |
return
|
709 |
|
710 |
full_response = ""
|
@@ -712,7 +685,7 @@ class XylariaChat:
|
|
712 |
|
713 |
if isinstance(response_stream, str):
|
714 |
updated_history = chat_history + [[message, response_stream]]
|
715 |
-
yield "", updated_history, None, None
|
716 |
return
|
717 |
|
718 |
try:
|
@@ -722,12 +695,7 @@ class XylariaChat:
|
|
722 |
full_response += chunk.token.text
|
723 |
updated_history[-1][1] = full_response
|
724 |
|
725 |
-
|
726 |
-
|
727 |
-
#self.conversation_history.append(ChatMessage(role="user", content=message).to_dict())
|
728 |
-
#self.conversation_history.append(ChatMessage(role="assistant", content=full_response).to_dict())
|
729 |
-
|
730 |
-
yield "", updated_history, None, None, None
|
731 |
|
732 |
except Exception as e:
|
733 |
print(f"Streaming error: {e}")
|
|
|
626 |
|
627 |
def create_interface(self):
|
628 |
def streaming_response(message, chat_history, image_filepath, math_ocr_image_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
629 |
if message.strip().lower().startswith("/image"):
|
630 |
|
631 |
image_prompt = message.strip().lower()[len("/image"):].strip()
|
|
|
634 |
|
635 |
|
636 |
chat_history.append([message, ""])
|
637 |
+
yield "", chat_history, None, None
|
|
|
638 |
|
639 |
|
640 |
image_bytes = self.generate_image(image_prompt)
|
|
|
646 |
|
647 |
chat_history[-1] = ("", image_html)
|
648 |
|
|
|
649 |
self.conversation_history.append(ChatMessage(role="user", content=message).to_dict())
|
650 |
self.conversation_history.append(ChatMessage(role="assistant", content=image_html).to_dict())
|
651 |
|
|
|
652 |
self.save_chat()
|
653 |
all_chats = self.load_all_chats()
|
654 |
chat_titles = [f"{chat['timestamp']}: {chat['conversation'][0]['content'][:30]}..." if len(chat['conversation']) > 0 and chat['conversation'][0]['content'] else f"{chat['timestamp']}: Empty Chat" for chat in all_chats]
|
655 |
|
656 |
+
yield "", chat_history, None, None
|
657 |
else:
|
658 |
|
659 |
chat_history[-1] = ("", image_bytes)
|
660 |
+
yield "", chat_history, None, None
|
661 |
return
|
662 |
|
663 |
ocr_text = ""
|
|
|
665 |
ocr_text = self.perform_math_ocr(math_ocr_image_path)
|
666 |
if ocr_text.startswith("Error"):
|
667 |
updated_history = chat_history + [[message, ocr_text]]
|
668 |
+
yield "", updated_history, None, None
|
669 |
return
|
670 |
else:
|
671 |
message = f"Math OCR Result: {ocr_text}\n\nUser's message: {message}"
|
|
|
677 |
|
678 |
if isinstance(response_stream, str):
|
679 |
updated_history = chat_history + [[message, response_stream]]
|
680 |
+
yield "", updated_history, None, None
|
681 |
return
|
682 |
|
683 |
full_response = ""
|
|
|
685 |
|
686 |
if isinstance(response_stream, str):
|
687 |
updated_history = chat_history + [[message, response_stream]]
|
688 |
+
yield "", updated_history, None, None
|
689 |
return
|
690 |
|
691 |
try:
|
|
|
695 |
full_response += chunk.token.text
|
696 |
updated_history[-1][1] = full_response
|
697 |
|
698 |
+
yield "", updated_history, None, None
|
|
|
|
|
|
|
|
|
|
|
699 |
|
700 |
except Exception as e:
|
701 |
print(f"Streaming error: {e}")
|