Update app_gradio.py
Browse files- app_gradio.py +17 -1
app_gradio.py
CHANGED
|
@@ -68,6 +68,22 @@ from data.loader import get_dataset_districts, get_dataset_governorates
|
|
| 68 |
from rag.retriever import StudentProfile
|
| 69 |
from core import engine
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
NO_TRACK = "غير محدد"
|
| 72 |
LANG_FLAGS = {"العربية": "🇱🇧", "الانكليزية": "🇬🇧", "الفرنسية": "🇫🇷"}
|
| 73 |
# (label, value) pairs: the flagged label is presentation; the engine still
|
|
@@ -1095,4 +1111,4 @@ with gr.Blocks(title=PAGE_TITLE) as demo:
|
|
| 1095 |
if __name__ == "__main__":
|
| 1096 |
# Gradio 6 takes presentation options at launch time. Hugging Face Spaces
|
| 1097 |
# runs this file as __main__, so this path serves the Space too.
|
| 1098 |
-
demo.launch(theme=theme, css=CSS, head=FORCE_LIGHT)
|
|
|
|
| 68 |
from rag.retriever import StudentProfile
|
| 69 |
from core import engine
|
| 70 |
|
| 71 |
+
# Build the semantic-search index on cold start, if it is not already built.
|
| 72 |
+
# HF Spaces' free tier gives no terminal access to run
|
| 73 |
+
# `python -m src.rag.vectorstore` manually, so this runs it once per restart
|
| 74 |
+
# instead. Guarded so a missing optional dependency degrades to no semantic
|
| 75 |
+
# search rather than crashing the whole app.
|
| 76 |
+
try:
|
| 77 |
+
from rag.vectorstore import get_vectorstore
|
| 78 |
+
|
| 79 |
+
_vs = get_vectorstore()
|
| 80 |
+
if _vs.collection.count() == 0:
|
| 81 |
+
print("Building semantic search index (first run)...")
|
| 82 |
+
_vs.build_index()
|
| 83 |
+
print(f"Index built: {_vs.collection.count()} documents")
|
| 84 |
+
except Exception as _e:
|
| 85 |
+
print(f"Semantic index not built (optional feature disabled): {_e}")
|
| 86 |
+
|
| 87 |
NO_TRACK = "غير محدد"
|
| 88 |
LANG_FLAGS = {"العربية": "🇱🇧", "الانكليزية": "🇬🇧", "الفرنسية": "🇫🇷"}
|
| 89 |
# (label, value) pairs: the flagged label is presentation; the engine still
|
|
|
|
| 1111 |
if __name__ == "__main__":
|
| 1112 |
# Gradio 6 takes presentation options at launch time. Hugging Face Spaces
|
| 1113 |
# runs this file as __main__, so this path serves the Space too.
|
| 1114 |
+
demo.launch(theme=theme, css=CSS, head=FORCE_LIGHT)
|