aidevhund commited on
Commit
a3d4f4f
·
verified ·
1 Parent(s): da591c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -23
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 answer(message, history):
53
- bot_response = query_with_retry(message)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
- # Eğer bot cevabından metin almak gerekiyorsa, .text ile metin almak gerekiyor.
56
- bot_text = bot_response.text if hasattr(bot_response, 'text') else str(bot_response)
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
- # Gradio Chat arayüzünü oluşturma
65
- def create_interface():
66
- # Gradio arayüzü oluşturma
67
- interface = gr.ChatInterface(
68
- fn=answer,
69
- type="messages",
70
- title="Hund Ecosystem Question Answering",
71
- description="Ask questions based on the Hund Ecosystem PDF document you uploaded.",
72
- )
73
- return interface
 
 
 
 
 
 
 
74
 
75
- # Çalıştırma
76
  if __name__ == "__main__":
77
- # Arayüzü başlatıyoruz
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()