MEOW commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -116,6 +116,22 @@ def chat(message,history):
|
|
| 116 |
except Exception as e:
|
| 117 |
return history + [(message,f"Error processing query: {str(e)}")]
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
with gr.Blocks() as iface:
|
| 120 |
gr.Markdown("# Multi-document RAG Chatbot 🦀 ") # Title using Markdown
|
| 121 |
gr.Markdown("Upload various documents or HTML URL for Q&A")
|
|
@@ -136,7 +152,7 @@ with gr.Blocks() as iface:
|
|
| 136 |
chatbot = gr.Chatbot()
|
| 137 |
msg = gr.Textbox(label="Enter your question")
|
| 138 |
# Use the chat function with Gurardrails
|
| 139 |
-
msg.submit(
|
| 140 |
clear_button = gr.Button("Clear")
|
| 141 |
clear_button.click(lambda: None, None, chatbot, queue=False)
|
| 142 |
|
|
|
|
| 116 |
except Exception as e:
|
| 117 |
return history + [(message,f"Error processing query: {str(e)}")]
|
| 118 |
|
| 119 |
+
# Function to stream responses
|
| 120 |
+
def stream_response(message,history):
|
| 121 |
+
global query_engine
|
| 122 |
+
if query_engine is None:
|
| 123 |
+
yield history + [("Please upload a file first.",None)]
|
| 124 |
+
return
|
| 125 |
+
|
| 126 |
+
try:
|
| 127 |
+
response = query_engine.query(message)
|
| 128 |
+
partial_response = ""
|
| 129 |
+
for text in response.response_gen:
|
| 130 |
+
partial_response += text
|
| 131 |
+
yield history + [(message,partial_response)]
|
| 132 |
+
except Exception as e:
|
| 133 |
+
yield history + [(message, f"Error processing query: {str(e)}")]
|
| 134 |
+
|
| 135 |
with gr.Blocks() as iface:
|
| 136 |
gr.Markdown("# Multi-document RAG Chatbot 🦀 ") # Title using Markdown
|
| 137 |
gr.Markdown("Upload various documents or HTML URL for Q&A")
|
|
|
|
| 152 |
chatbot = gr.Chatbot()
|
| 153 |
msg = gr.Textbox(label="Enter your question")
|
| 154 |
# Use the chat function with Gurardrails
|
| 155 |
+
msg.submit(stream_response, inputs=[msg, chatbot], outputs=[chatbot])
|
| 156 |
clear_button = gr.Button("Clear")
|
| 157 |
clear_button.click(lambda: None, None, chatbot, queue=False)
|
| 158 |
|