Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,16 @@ from prompt_template import (
|
|
24 |
)
|
25 |
|
26 |
# API Keys and Constants
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 =
|
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
|
208 |
-
gr.Markdown("
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
with gr.Tab("π Domain Knowledge RAG"):
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
|
|
|
|
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 |
|