Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ from backend_app.config import (
|
|
| 10 |
|
| 11 |
# ---------- Prepare data once ----------
|
| 12 |
os.makedirs(DATA_DIR, exist_ok=True)
|
|
|
|
| 13 |
if not (os.path.exists(FAISS_INDEX_PATH) and os.path.exists(DOCSTORE_PATH)):
|
| 14 |
run_ingestion()
|
| 15 |
|
|
@@ -20,10 +21,10 @@ def respond(message, history, lang):
|
|
| 20 |
if not message:
|
| 21 |
return ""
|
| 22 |
|
| 23 |
-
# RAG answer (NO sources)
|
| 24 |
try:
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
except Exception:
|
| 28 |
return "I ran into a temporary error while generating the answer. Please try again."
|
| 29 |
|
|
@@ -37,16 +38,13 @@ with gr.Blocks(title=BOT_NAME) as demo:
|
|
| 37 |
label="Response language"
|
| 38 |
)
|
| 39 |
|
| 40 |
-
|
|
|
|
| 41 |
fn=respond,
|
| 42 |
-
additional_inputs=[lang]
|
| 43 |
-
retry_btn=None,
|
| 44 |
-
undo_btn=None,
|
| 45 |
-
clear_btn="Clear"
|
| 46 |
)
|
| 47 |
|
| 48 |
demo.queue()
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
-
# HF provides the port automatically
|
| 52 |
demo.launch()
|
|
|
|
| 10 |
|
| 11 |
# ---------- Prepare data once ----------
|
| 12 |
os.makedirs(DATA_DIR, exist_ok=True)
|
| 13 |
+
|
| 14 |
if not (os.path.exists(FAISS_INDEX_PATH) and os.path.exists(DOCSTORE_PATH)):
|
| 15 |
run_ingestion()
|
| 16 |
|
|
|
|
| 21 |
if not message:
|
| 22 |
return ""
|
| 23 |
|
|
|
|
| 24 |
try:
|
| 25 |
+
result = rag.answer(message, preferred_lang=lang)
|
| 26 |
+
answer = (result.get("answer") or "").strip()
|
| 27 |
+
return answer if answer else "I couldn’t find enough information to answer that. Please rephrase."
|
| 28 |
except Exception:
|
| 29 |
return "I ran into a temporary error while generating the answer. Please try again."
|
| 30 |
|
|
|
|
| 38 |
label="Response language"
|
| 39 |
)
|
| 40 |
|
| 41 |
+
# ✅ Minimal ChatInterface for maximum compatibility
|
| 42 |
+
gr.ChatInterface(
|
| 43 |
fn=respond,
|
| 44 |
+
additional_inputs=[lang]
|
|
|
|
|
|
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
demo.queue()
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|
|
|
|
| 50 |
demo.launch()
|