afouda commited on
Commit
addc6d4
Β·
verified Β·
1 Parent(s): 31fdbee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -13
app.py CHANGED
@@ -189,10 +189,14 @@ def process_query(query: str, first_turn: bool = False):
189
 
190
  _save_process_log(process_log)
191
  return intro + result
 
 
 
 
 
 
192
  # Utility to save process log to a txt file
193
  def _save_process_log(log_lines, filename="process_output.txt"):
194
- import datetime
195
- import os
196
  # Ensure logs directory exists
197
  logs_dir = os.path.join(os.path.dirname(__file__), "logs")
198
  os.makedirs(logs_dir, exist_ok=True)
@@ -254,19 +258,35 @@ def main_pipeline_with_doc(query, doc_file, doc_type):
254
  return "Invalid document type."
255
 
256
  with gr.Blocks(title="Wisal Main Pipeline & RAG") as demo:
257
- gr.Markdown("## Wisal: Autism AI Assistant (Main Pipeline)")
258
- with gr.Tab("Main Pipeline"):
259
- q = gr.Textbox(placeholder="Your question...", lines=2, label="Ask Wisal")
260
- doc_file = gr.File(label="Optional: Upload Document (PDF, DOCX, TXT)")
261
- doc_type = gr.Radio(["None", "Knowledge Document", "User-Specific Document", "Old Document"], value="None", label="Document Type")
262
- btn = gr.Button("Submit")
263
- out = gr.Textbox(label="Wisal Answer", lines=8, interactive=False)
264
- btn.click(fn=main_pipeline_with_doc, inputs=[q, doc_file, doc_type], outputs=out)
265
- with gr.Tab("Domain Knowledge RAG"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  RAG_Domain_know_doc.demo.render()
267
- with gr.Tab("User-Specific Documents"):
268
  User_Specific_Documents.demo.render()
269
- with gr.Tab("Old Documents"):
270
  Old_Document.demo.render()
271
 
272
  if __name__ == "__main__":
 
189
 
190
  _save_process_log(process_log)
191
  return intro + result
192
+
193
+ def main_pipeline_with_doc_and_history(query, doc_file, doc_type, history):
194
+ response = main_pipeline_with_doc(query, doc_file, doc_type)
195
+ updated_history = history + f"\nUser: {query}\nWisal: {response}\n"
196
+ return response, updated_history
197
+
198
  # Utility to save process log to a txt file
199
  def _save_process_log(log_lines, filename="process_output.txt"):
 
 
200
  # Ensure logs directory exists
201
  logs_dir = os.path.join(os.path.dirname(__file__), "logs")
202
  os.makedirs(logs_dir, exist_ok=True)
 
258
  return "Invalid document type."
259
 
260
  with gr.Blocks(title="Wisal Main Pipeline & RAG") as demo:
261
+ gr.Markdown("## πŸ€– Wisal: Autism AI Assistant")
262
+
263
+ with gr.Tab("🧠 Main Chatbot"):
264
+ with gr.Column():
265
+ history = gr.Textbox(label="πŸ—¨οΈ Chat History", lines=20, interactive=False, show_label=False)
266
+
267
+ with gr.Row():
268
+ q = gr.Textbox(placeholder="Type your question here...", label="", lines=1)
269
+ btn = gr.Button("Send", variant="primary")
270
+
271
+ with gr.Row():
272
+ doc_file = gr.File(label="πŸ“Ž Upload Document (PDF, DOCX, TXT)", file_types=[".pdf", ".docx", ".txt"])
273
+ doc_type = gr.Radio(
274
+ ["None", "Knowledge Document", "User-Specific Document", "Old Document"],
275
+ value="None",
276
+ label="Document Type"
277
+ )
278
+
279
+ btn.click(
280
+ fn=main_pipeline_with_doc_and_history,
281
+ inputs=[q, doc_file, doc_type, history],
282
+ outputs=[history]
283
+ )
284
+
285
+ with gr.Tab("πŸ“˜ Domain Knowledge RAG"):
286
  RAG_Domain_know_doc.demo.render()
287
+ with gr.Tab("πŸ“ User-Specific Documents"):
288
  User_Specific_Documents.demo.render()
289
+ with gr.Tab("πŸ•°οΈ Old Documents"):
290
  Old_Document.demo.render()
291
 
292
  if __name__ == "__main__":