Update app.py
Browse files
app.py
CHANGED
@@ -48,46 +48,30 @@ def query_with_retry(query, max_retries=3, wait_time=5):
|
|
48 |
print(f"An error occurred: {e}")
|
49 |
break
|
50 |
|
51 |
-
#
|
52 |
-
def
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
#
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
#submit-btn {background-color: #607D8B; color: #fff; border-radius: 8px; padding: 10px 20px; font-weight: bold;}
|
67 |
-
#retry-btn {background-color: #8e8e8e; color: #fff; border-radius: 8px; padding: 10px 20px; font-weight: bold;}
|
68 |
-
#clear-btn {background-color: #f44336; color: #fff; border-radius: 8px; padding: 10px 20px; font-weight: bold;}
|
69 |
-
#undo-btn {background-color: #2196F3; color: #fff; border-radius: 8px; padding: 10px 20px; font-weight: bold;}
|
70 |
-
#output-box {background-color: #2e2e2e; color: #fff;}
|
71 |
-
#submit-btn:hover, #retry-btn:hover, #clear-btn:hover, #undo-btn:hover {cursor: pointer; opacity: 0.9;}
|
72 |
-
#buttons {display: flex; justify-content: space-between; font-size: 0.85em;}
|
73 |
-
""") as demo:
|
74 |
-
# Chatbot UI
|
75 |
-
with gr.Column():
|
76 |
-
chatbox = gr.Chatbot(label="Chatbot", elem_id="chatbox")
|
77 |
-
input_text = gr.Textbox(label="Ask a question", placeholder="Type your question here...", lines=2, elem_id="input-box")
|
78 |
-
|
79 |
-
# Butonlar: Retry, Clear, Undo butonları küçük şekilde düzenlendi
|
80 |
-
with gr.Row(elem_id="buttons"):
|
81 |
-
retry_btn = gr.Button("Retry", elem_id="retry-btn", scale=0.8)
|
82 |
-
clear_btn = gr.Button("Clear", elem_id="clear-btn", scale=0.8)
|
83 |
-
undo_btn = gr.Button("Undo", elem_id="undo-btn", scale=0.8)
|
84 |
-
|
85 |
-
submit_btn = gr.Button("Ask", elem_id="submit-btn")
|
86 |
-
|
87 |
-
# Button actions
|
88 |
-
submit_btn.click(chatbot_interface, inputs=[input_text, chatbox], outputs=[chatbox, input_text])
|
89 |
-
retry_btn.click(chatbot_interface, inputs=[input_text, chatbox], outputs=[chatbox, input_text]) # Retry işlemi
|
90 |
-
clear_btn.click(clear_all, outputs=[chatbox, input_text])
|
91 |
-
undo_btn.click(clear_all, outputs=[chatbox, input_text]) # Undo işlevi Clear olarak kullanıldı
|
92 |
-
|
93 |
-
demo.launch()
|
|
|
48 |
print(f"An error occurred: {e}")
|
49 |
break
|
50 |
|
51 |
+
# Kullanıcı inputu ve chatbot arayüzü fonksiyonu
|
52 |
+
def answer(message, history):
|
53 |
+
bot_response = query_with_retry(message)
|
54 |
+
|
55 |
+
# Kullanıcı mesajını ve bot cevabını ekleyelim
|
56 |
+
history.append(("User", message))
|
57 |
+
history.append(("Bot", bot_response.strip()))
|
58 |
+
|
59 |
+
return history
|
60 |
|
61 |
+
# Gradio'da kullanıcı arayüzü
|
62 |
+
def create_interface():
|
63 |
+
# Gradio arayüzü oluşturma
|
64 |
+
interface = gr.ChatInterface(
|
65 |
+
fn=answer,
|
66 |
+
type="messages",
|
67 |
+
title="Hund Ecosystem Question Answering",
|
68 |
+
description="Ask questions based on the Hund Ecosystem PDF document you uploaded.",
|
69 |
+
textbox=gr.MultimodalTextbox(file_types=[".pdf", ".txt"]),
|
70 |
+
multimodal=True
|
71 |
+
)
|
72 |
+
return interface
|
73 |
|
74 |
+
# Çalıştırma
|
75 |
+
if __name__ == "__main__":
|
76 |
+
# Arayüzü başlatıyoruz
|
77 |
+
create_interface().launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|