Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,11 @@ import gradio as gr
|
|
| 4 |
from backend_app.ingest import run_ingestion
|
| 5 |
from backend_app.rag_hf import RAGEngineHF
|
| 6 |
from backend_app.config import (
|
| 7 |
-
DATA_DIR,
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
)
|
| 10 |
|
| 11 |
# ---------- Prepare data once ----------
|
|
@@ -16,25 +19,34 @@ if not (os.path.exists(FAISS_INDEX_PATH) and os.path.exists(DOCSTORE_PATH)):
|
|
| 16 |
|
| 17 |
rag = RAGEngineHF()
|
| 18 |
|
| 19 |
-
|
|
|
|
| 20 |
message = (message or "").strip()
|
| 21 |
if not message:
|
| 22 |
return ""
|
| 23 |
|
| 24 |
try:
|
| 25 |
-
result = rag.answer(message)
|
| 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 |
|
|
|
|
| 31 |
with gr.Blocks(title=BOT_NAME) as demo:
|
| 32 |
gr.Markdown(f"## {BOT_NAME}")
|
| 33 |
gr.Markdown(BOT_WELCOME)
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
gr.ChatInterface(
|
| 37 |
-
fn=respond
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
demo.queue()
|
|
|
|
| 4 |
from backend_app.ingest import run_ingestion
|
| 5 |
from backend_app.rag_hf import RAGEngineHF
|
| 6 |
from backend_app.config import (
|
| 7 |
+
DATA_DIR,
|
| 8 |
+
FAISS_INDEX_PATH,
|
| 9 |
+
DOCSTORE_PATH,
|
| 10 |
+
BOT_WELCOME,
|
| 11 |
+
BOT_NAME
|
| 12 |
)
|
| 13 |
|
| 14 |
# ---------- Prepare data once ----------
|
|
|
|
| 19 |
|
| 20 |
rag = RAGEngineHF()
|
| 21 |
|
| 22 |
+
|
| 23 |
+
def respond(message, history, lang):
|
| 24 |
message = (message or "").strip()
|
| 25 |
if not message:
|
| 26 |
return ""
|
| 27 |
|
| 28 |
try:
|
| 29 |
+
result = rag.answer(message, preferred_lang=lang)
|
| 30 |
answer = (result.get("answer") or "").strip()
|
| 31 |
return answer if answer else "I couldn’t find enough information to answer that. Please rephrase."
|
| 32 |
except Exception:
|
| 33 |
return "I ran into a temporary error while generating the answer. Please try again."
|
| 34 |
|
| 35 |
+
|
| 36 |
with gr.Blocks(title=BOT_NAME) as demo:
|
| 37 |
gr.Markdown(f"## {BOT_NAME}")
|
| 38 |
gr.Markdown(BOT_WELCOME)
|
| 39 |
|
| 40 |
+
lang = gr.Dropdown(
|
| 41 |
+
choices=["English"],
|
| 42 |
+
value="English",
|
| 43 |
+
label="Response language"
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# ✅ Minimal ChatInterface for maximum compatibility
|
| 47 |
gr.ChatInterface(
|
| 48 |
+
fn=respond,
|
| 49 |
+
additional_inputs=[lang]
|
| 50 |
)
|
| 51 |
|
| 52 |
demo.queue()
|