afouda commited on
Commit
bf59962
Β·
verified Β·
1 Parent(s): 6cde267

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -34
app.py CHANGED
@@ -24,7 +24,16 @@ from prompt_template import (
24
  )
25
 
26
  # API Keys and Constants
27
- DEEPINFRA_API_KEY = "285LUJulGIprqT6hcPhiXtcrphU04FG4"
 
 
 
 
 
 
 
 
 
28
 
29
  # Initialize OpenAI client
30
  openai = OpenAI(
@@ -32,7 +41,7 @@ openai = OpenAI(
32
  base_url="https://api.deepinfra.com/v1/openai",
33
  )
34
 
35
- SESSION_ID = datetime.now().strftime("%Y%m%d_%H%M%S")
36
 
37
  # Chat Completion Helper
38
  def call_llm(model: str, messages: list[dict], temperature: float = 0.0, **kwargs) -> str:
@@ -203,41 +212,47 @@ def main_pipeline_with_doc(query, doc_file, doc_type):
203
  return f"[Old Document Uploaded]\n{status}\n\n{answer}"
204
  else:
205
  return "Invalid document type."
 
 
 
 
206
 
207
- with gr.Blocks(title="Wisal Main Pipeline & RAG") as demo:
208
- gr.Markdown("## πŸ€– Wisal: Autism AI Assistant")
209
-
210
- with gr.Tab("🧠 Main Chatbot"):
211
- with gr.Column():
212
- history = gr.Textbox(label="πŸ—¨οΈ Chat History", lines=20, interactive=False, show_label=False)
213
-
214
- with gr.Row():
215
- q = gr.Textbox(placeholder="Type your question here...", label="", lines=1)
216
- btn = gr.Button("Send", variant="primary")
217
-
218
- with gr.Row():
219
- doc_file = gr.File(label="πŸ“Ž Upload Document (PDF, DOCX, TXT)", file_types=[".pdf", ".docx", ".txt"])
220
- doc_type = gr.Radio(
221
- ["None", "Knowledge Document", "User-Specific Document", "Old Document"],
222
- value="None",
223
- label="Document Type"
224
- )
225
-
226
- btn.click(
227
- fn=main_pipeline_with_doc_and_history,
228
- inputs=[q, doc_file, doc_type, history],
229
- outputs=[history]
230
- )
231
-
232
- with gr.Tab("πŸ“˜ Domain Knowledge RAG"):
233
- RAG_Domain_know_doc.demo.render()
234
- with gr.Tab("πŸ“ User-Specific Documents"):
235
- User_Specific_Documents.demo.render()
236
- with gr.Tab("πŸ•°οΈ Old Documents"):
237
- Old_Document.demo.render()
 
 
238
 
239
  if __name__ == "__main__":
240
  demo.launch(debug=True)
241
-
242
 
243
 
 
24
  )
25
 
26
  # API Keys and Constants
27
+ GEMINI_API_KEY="AIzaSyCUCivstFpC9pq_jMHMYdlPrmh9Bx97dFo"
28
+ TAVILY_API_KEY="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"
29
+ OPENAI_API_KEY="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"
30
+ QDRANT_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOiJtIiwiZXhwIjoxNzUxMDUxNzg4fQ.I9J-K7OM0BtcNKgj2d4uVM8QYAHYfFCVAyP4rlZkK2E"
31
+ QDRANT_URL="https://6a3aade6-e8ad-4a6c-a579-21f5af90b7e8.us-east4-0.gcp.cloud.qdrant.io"
32
+ OPENAI_API_KEY="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"
33
+ WEAVIATE_URL="https://xbvlj5rpqyiswspww0tthq.c0.us-west3.gcp.weaviate.cloud"
34
+ WEAVIATE_API_KEY="RU9acU1CYnNRTjY1S1ZFc18zNS9tQktaWlcwTzFEUjlscEVCUGF4YU5xRWx2MDhmTUtIdUhnOWdOTGVZPV92MjAw"
35
+ DEEPINFRA_API_KEY="285LUJulGIprqT6hcPhiXtcrphU04FG4"
36
+ DEEPINFRA_BASE_URL="https://api.deepinfra.com/v1/openai"
37
 
38
  # Initialize OpenAI client
39
  openai = OpenAI(
 
41
  base_url="https://api.deepinfra.com/v1/openai",
42
  )
43
 
44
+ SESSION_ID = "default"
45
 
46
  # Chat Completion Helper
47
  def call_llm(model: str, messages: list[dict], temperature: float = 0.0, **kwargs) -> str:
 
212
  return f"[Old Document Uploaded]\n{status}\n\n{answer}"
213
  else:
214
  return "Invalid document type."
215
+ def pipeline_with_history(message, doc_file, doc_type, history):
216
+ response = main_pipeline_with_doc(message, doc_file, doc_type)
217
+ history = history + [[message, response]]
218
+ return history, ""
219
 
220
+ with gr.Blocks(title="Wisal Chatbot", theme=gr.themes.Base()) as demo:
221
+ gr.Markdown("# πŸ€– Wisal: Autism AI Assistant")
222
+
223
+ chatbot = gr.Chatbot(label="Wisal Chat", height=500)
224
+
225
+ with gr.Row():
226
+ user_input = gr.Textbox(placeholder="Type your question here...", label="", lines=1)
227
+ send_btn = gr.Button("Send")
228
+
229
+ doc_file = gr.File(label="πŸ“Ž Upload Document (PDF, DOCX, TXT)", file_types=[".pdf", ".docx", ".txt"])
230
+ doc_type = gr.Radio(
231
+ ["None", "Knowledge Document", "User-Specific Document", "Old Document"],
232
+ value="None",
233
+ label="Document Type"
234
+ )
235
+
236
+ send_btn.click(
237
+ fn=pipeline_with_history,
238
+ inputs=[user_input, doc_file, doc_type, chatbot],
239
+ outputs=[chatbot, user_input]
240
+ )
241
+
242
+ # clear_btn = gr.Button("Clear Chat")
243
+ # clear_btn.click(lambda: [], outputs=[chatbot])
244
+
245
+ # with gr.Tab("πŸ“˜ Domain Knowledge RAG"):
246
+ # RAG_Domain_know_doc.demo.render()
247
+
248
+ # with gr.Tab("πŸ“ User-Specific Documents"):
249
+ # User_Specific_Documents.demo.render()
250
+
251
+ # with gr.Tab("πŸ•°οΈ Old Documents"):
252
+ # Old_Document.demo.render()
253
 
254
  if __name__ == "__main__":
255
  demo.launch(debug=True)
256
+
257
 
258