Update app.py
Browse files
app.py
CHANGED
@@ -49,30 +49,45 @@ def query_with_retry(query, max_retries=3, wait_time=5):
|
|
49 |
break
|
50 |
|
51 |
# Kullanıcı mesajlarını ve botun cevabını yönetmek
|
52 |
-
def
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
# Kullanıcı mesajını ve bot cevabını ekleyelim
|
59 |
-
history.append({"role": "user", "content": message})
|
60 |
-
history.append({"role": "bot", "content": bot_text.strip()})
|
61 |
-
|
62 |
-
return history
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
#
|
76 |
if __name__ == "__main__":
|
77 |
-
|
78 |
-
create_interface().launch()
|
|
|
49 |
break
|
50 |
|
51 |
# Kullanıcı mesajlarını ve botun cevabını yönetmek
|
52 |
+
def respond(message, history):
|
53 |
+
try:
|
54 |
+
# Sorguyu query_engine üzerinde çalıştır
|
55 |
+
response = query_engine.query(message)
|
56 |
+
|
57 |
+
# Loglama işlemi
|
58 |
+
print(f"\n{datetime.now()}:{llm.model_name}:: {message} --> {str(response)}\n")
|
59 |
+
|
60 |
+
return f"{llm.model_name}:\n{str(response)}"
|
61 |
+
except Exception as e:
|
62 |
+
if str(e) == "'NoneType' object has no attribute 'as_query_engine'":
|
63 |
+
return "Please upload a file."
|
64 |
+
return f"An error occurred: {e}"
|
65 |
+
# UI Setup
|
66 |
+
with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Roboto Mono")]), css='footer {visibility: hidden}') as demo:
|
67 |
+
gr.Markdown("# DocBot📄🤖")
|
68 |
|
69 |
+
with gr.Tabs():
|
70 |
+
with gr.TabItem("Intro"):
|
71 |
+
gr.Markdown("## Welcome to DocBot! 📄🤖\nAsk questions related to the uploaded document.")
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
with gr.TabItem("DocBot"):
|
74 |
+
with gr.Accordion("=== IMPORTANT: READ ME FIRST ===", open=False):
|
75 |
+
gr.Markdown("## Please ask questions about the uploaded document.\nYou can interact with the document once it's loaded.")
|
76 |
+
|
77 |
+
with gr.Row():
|
78 |
+
with gr.Column(scale=3):
|
79 |
+
gr.ChatInterface(
|
80 |
+
fn=respond, # `respond` fonksiyonu, kullanıcı sorularını cevaplamak için kullanılacak
|
81 |
+
chatbot=gr.Chatbot(height=500),
|
82 |
+
theme="soft",
|
83 |
+
show_progress='full',
|
84 |
+
textbox=gr.Textbox(placeholder="Step-1: Ask me questions about the uploaded document!", container=False)
|
85 |
+
)
|
86 |
+
|
87 |
+
# Set up Gradio interactions (Gerekli işlevlerin burada çalıştığından emin olun)
|
88 |
+
btn.click(fn=load_files, inputs=[file_input], outputs=output)
|
89 |
+
clear.click(lambda: [None] * 1, outputs=[file_input]) # Yalnızca dosya yükleme temizlenecek
|
90 |
|
91 |
+
# Launch the demo
|
92 |
if __name__ == "__main__":
|
93 |
+
demo.launch()
|
|