Upload app.py
Browse files
app.py
CHANGED
|
@@ -114,17 +114,12 @@ with gr.Blocks() as demo:
|
|
| 114 |
|
| 115 |
# Sohbet geçmişi
|
| 116 |
chatbox = gr.HTML(value="", label="Sohbet Geçmişi")
|
| 117 |
-
|
| 118 |
-
with gr.Column(scale=1):
|
| 119 |
-
# Seçenekler
|
| 120 |
-
grade_dropdown = gr.Dropdown(["İlkokul", "Ortaokul", "Lise"], label="Sınıf Seviyesi")
|
| 121 |
-
subject_dropdown = gr.Dropdown(["Matematik", "Türkçe", "Tarih", "Fen Bilimleri"], label="Konu")
|
| 122 |
|
| 123 |
with gr.Column(scale=1):
|
| 124 |
# Sohbeti kaydetme ve temizleme butonları
|
| 125 |
-
clear_btn = gr.Button("♻️ Geçmişi Temizle")
|
| 126 |
-
save_btn = gr.Button("💾 Sohbeti Kaydet")
|
| 127 |
-
download_file = gr.File()
|
| 128 |
|
| 129 |
# Sohbeti temizleme fonksiyonu
|
| 130 |
def clear_chat():
|
|
@@ -142,18 +137,25 @@ with gr.Blocks() as demo:
|
|
| 142 |
save_btn.click(fn=save_chat_to_file, inputs=[chatbox], outputs=download_file)
|
| 143 |
|
| 144 |
# Soru gönderme fonksiyonu
|
| 145 |
-
def handle_question(user_question,
|
| 146 |
# Soruyu kullanarak yanıt al
|
| 147 |
-
|
| 148 |
-
result = qa_chain.run(query)
|
| 149 |
|
| 150 |
# Geçmişi güncelle ve toplam soru sayısını arttır
|
| 151 |
-
chat_history += f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
total_questions += 1
|
| 153 |
return chat_history, total_questions
|
| 154 |
|
| 155 |
# Gönder butonuna tıklanınca soru gönderme işlemi
|
| 156 |
-
send_btn.click(fn=handle_question, inputs=[user_input,
|
| 157 |
outputs=[chatbox, total_q])
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
| 114 |
|
| 115 |
# Sohbet geçmişi
|
| 116 |
chatbox = gr.HTML(value="", label="Sohbet Geçmişi")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
with gr.Column(scale=1):
|
| 119 |
# Sohbeti kaydetme ve temizleme butonları
|
| 120 |
+
clear_btn = gr.Button("♻️ Geçmişi Temizle", variant="primary")
|
| 121 |
+
save_btn = gr.Button("💾 Sohbeti Kaydet", variant="primary")
|
| 122 |
+
download_file = gr.File(label="İndir")
|
| 123 |
|
| 124 |
# Sohbeti temizleme fonksiyonu
|
| 125 |
def clear_chat():
|
|
|
|
| 137 |
save_btn.click(fn=save_chat_to_file, inputs=[chatbox], outputs=download_file)
|
| 138 |
|
| 139 |
# Soru gönderme fonksiyonu
|
| 140 |
+
def handle_question(user_question, total_questions, chat_history):
|
| 141 |
# Soruyu kullanarak yanıt al
|
| 142 |
+
result = qa_chain.run(user_question)
|
|
|
|
| 143 |
|
| 144 |
# Geçmişi güncelle ve toplam soru sayısını arttır
|
| 145 |
+
chat_history += f"""
|
| 146 |
+
<div style="background-color:#d1f7c4; padding: 10px; border-radius: 15px; margin-bottom: 5px;">
|
| 147 |
+
<b>Soru:</b> {user_question}
|
| 148 |
+
</div>
|
| 149 |
+
<div style="background-color:#f0f8ff; padding: 10px; border-radius: 15px; margin-bottom: 5px;">
|
| 150 |
+
<b>Cevap:</b> {result}
|
| 151 |
+
</div>
|
| 152 |
+
"""
|
| 153 |
total_questions += 1
|
| 154 |
return chat_history, total_questions
|
| 155 |
|
| 156 |
# Gönder butonuna tıklanınca soru gönderme işlemi
|
| 157 |
+
send_btn.click(fn=handle_question, inputs=[user_input, total_q, chatbox],
|
| 158 |
outputs=[chatbox, total_q])
|
| 159 |
|
| 160 |
+
# Gradio UI'sini başlatma
|
| 161 |
+
demo.launch()
|