Spaces:
Sleeping
Sleeping
Update chatbot_rag.py
Browse files- chatbot_rag.py +14 -0
chatbot_rag.py
CHANGED
|
@@ -54,3 +54,17 @@ def build_qa():
|
|
| 54 |
|
| 55 |
print("✅ QA pipeline ready.")
|
| 56 |
return qa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
print("✅ QA pipeline ready.")
|
| 56 |
return qa
|
| 57 |
+
|
| 58 |
+
# Build at import time (so it's ready when app runs)
|
| 59 |
+
try:
|
| 60 |
+
qa_pipeline = build_qa()
|
| 61 |
+
except Exception as e:
|
| 62 |
+
qa_pipeline = None
|
| 63 |
+
print("❌ Failed to build QA pipeline:", e)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def get_answer(query: str) -> str:
|
| 67 |
+
"""Takes user query and returns chatbot response."""
|
| 68 |
+
if qa_pipeline is None:
|
| 69 |
+
return "⚠️ QA pipeline not initialized."
|
| 70 |
+
return qa_pipeline.run(query)
|