Update app.py
Browse files
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
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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__":
|