Update app.py
Browse files
app.py
CHANGED
|
@@ -223,25 +223,32 @@ Answer conversationally:
|
|
| 223 |
return f"{answer}\n\nSources Used:\n{metadata}"
|
| 224 |
|
| 225 |
# =======================================================
|
| 226 |
-
# 10) Gradio Chat Interface (INTRO only once)
|
| 227 |
# =======================================================
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
"content": INTRO_TEXT
|
| 231 |
-
}
|
| 232 |
|
| 233 |
def chat_api(message, history):
|
| 234 |
-
history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
reply = generate_with_rag(message)
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
| 237 |
return history, history
|
| 238 |
|
|
|
|
| 239 |
with gr.Blocks() as demo:
|
| 240 |
gr.Markdown("## Canada Residential Tenancy Assistant (RAG + Mistral 7B)")
|
| 241 |
|
| 242 |
chatbot = gr.Chatbot(
|
| 243 |
-
value=[
|
| 244 |
-
height=500
|
| 245 |
)
|
| 246 |
|
| 247 |
user_box = gr.Textbox(
|
|
@@ -254,5 +261,6 @@ with gr.Blocks() as demo:
|
|
| 254 |
send_btn.click(chat_api, inputs=[user_box, chatbot], outputs=[chatbot, chatbot])
|
| 255 |
user_box.submit(chat_api, inputs=[user_box, chatbot], outputs=[chatbot, chatbot])
|
| 256 |
|
|
|
|
| 257 |
if __name__ == "__main__":
|
| 258 |
-
demo.launch()
|
|
|
|
| 223 |
return f"{answer}\n\nSources Used:\n{metadata}"
|
| 224 |
|
| 225 |
# =======================================================
|
| 226 |
+
# 10) Gradio Chat Interface (INTRO only once, FIXED)
|
| 227 |
# =======================================================
|
| 228 |
+
|
| 229 |
+
INTRO_TUPLE = (None, INTRO_TEXT)
|
|
|
|
|
|
|
| 230 |
|
| 231 |
def chat_api(message, history):
|
| 232 |
+
# history is a list of tuples: [(user, bot), ...]
|
| 233 |
+
|
| 234 |
+
# Add user message
|
| 235 |
+
history.append((message, None))
|
| 236 |
+
|
| 237 |
+
# Generate bot reply
|
| 238 |
reply = generate_with_rag(message)
|
| 239 |
+
|
| 240 |
+
# Replace last tuple with completed (user, bot) pair
|
| 241 |
+
history[-1] = (message, reply)
|
| 242 |
+
|
| 243 |
return history, history
|
| 244 |
|
| 245 |
+
|
| 246 |
with gr.Blocks() as demo:
|
| 247 |
gr.Markdown("## Canada Residential Tenancy Assistant (RAG + Mistral 7B)")
|
| 248 |
|
| 249 |
chatbot = gr.Chatbot(
|
| 250 |
+
value=[INTRO_TUPLE], # must be a list of tuples!
|
| 251 |
+
height=500,
|
| 252 |
)
|
| 253 |
|
| 254 |
user_box = gr.Textbox(
|
|
|
|
| 261 |
send_btn.click(chat_api, inputs=[user_box, chatbot], outputs=[chatbot, chatbot])
|
| 262 |
user_box.submit(chat_api, inputs=[user_box, chatbot], outputs=[chatbot, chatbot])
|
| 263 |
|
| 264 |
+
|
| 265 |
if __name__ == "__main__":
|
| 266 |
+
demo.launch(share=True)
|