Upload app.py
Browse files
app.py
CHANGED
@@ -668,42 +668,46 @@ with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı") as demo:
|
|
668 |
if not message.strip():
|
669 |
return "", chat_history
|
670 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
671 |
# Session ID sistemi kaldırıldı - daha hızlı çalışma için
|
672 |
|
673 |
-
# Chat history'yi chatbot_fn için uygun formata çevir
|
674 |
formatted_history = []
|
675 |
-
if chat_history:
|
676 |
-
for user_msg, bot_msg in chat_history:
|
677 |
-
|
678 |
-
|
|
|
679 |
|
680 |
try:
|
681 |
# Enhanced chatbot fonksiyonunu çağır (image=None)
|
682 |
response_generator = chatbot_fn(message, formatted_history, None)
|
683 |
|
684 |
-
# Generator'dan
|
685 |
response = ""
|
686 |
for partial in response_generator:
|
687 |
response = partial
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
chat_history = []
|
692 |
-
chat_history.append((message, response))
|
693 |
|
694 |
# Profile kaydetme chatbot_fn içinde yapılıyor, burada duplikasyon yok
|
695 |
|
696 |
-
return "", chat_history
|
697 |
-
|
698 |
except Exception as e:
|
699 |
error_msg = f"Üzgünüm, bir hata oluştu: {str(e)}"
|
700 |
print(f"Chat error: {e}")
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
return "", chat_history
|
705 |
|
706 |
-
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
707 |
|
708 |
if __name__ == "__main__":
|
709 |
demo.launch(debug=True)
|
|
|
668 |
if not message.strip():
|
669 |
return "", chat_history
|
670 |
|
671 |
+
# Kullanıcı mesajını hemen göster
|
672 |
+
if chat_history is None:
|
673 |
+
chat_history = []
|
674 |
+
|
675 |
+
# Kullanıcı mesajını ekle ve hemen yield et
|
676 |
+
chat_history.append((message, None))
|
677 |
+
yield "", chat_history
|
678 |
+
|
679 |
# Session ID sistemi kaldırıldı - daha hızlı çalışma için
|
680 |
|
681 |
+
# Chat history'yi chatbot_fn için uygun formata çevir (son mesaj hariç)
|
682 |
formatted_history = []
|
683 |
+
if len(chat_history) > 1: # Son mesajı hariç tut
|
684 |
+
for user_msg, bot_msg in chat_history[:-1]:
|
685 |
+
if bot_msg: # Sadece tamamlanmış mesajlar
|
686 |
+
formatted_history.append({"role": "user", "content": user_msg})
|
687 |
+
formatted_history.append({"role": "assistant", "content": bot_msg})
|
688 |
|
689 |
try:
|
690 |
# Enhanced chatbot fonksiyonunu çağır (image=None)
|
691 |
response_generator = chatbot_fn(message, formatted_history, None)
|
692 |
|
693 |
+
# Generator'dan streaming cevap al
|
694 |
response = ""
|
695 |
for partial in response_generator:
|
696 |
response = partial
|
697 |
+
# Son mesajı güncelle ve yield et
|
698 |
+
chat_history[-1] = (message, response)
|
699 |
+
yield "", chat_history
|
|
|
|
|
700 |
|
701 |
# Profile kaydetme chatbot_fn içinde yapılıyor, burada duplikasyon yok
|
702 |
|
|
|
|
|
703 |
except Exception as e:
|
704 |
error_msg = f"Üzgünüm, bir hata oluştu: {str(e)}"
|
705 |
print(f"Chat error: {e}")
|
706 |
+
# Hata mesajıyla güncelle
|
707 |
+
chat_history[-1] = (message, error_msg)
|
708 |
+
yield "", chat_history
|
|
|
709 |
|
710 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot], show_progress=True)
|
711 |
|
712 |
if __name__ == "__main__":
|
713 |
demo.launch(debug=True)
|