Spaces:
Running on Zero
Running on Zero
Upload 34 files
Browse filesFiles changed (2)
- app.py+5-5
- src/llm_client.py+27-2
29 unmodified lines3031323334353667 unmodified lines104105106107108109110382 unmodified lines49349449549649749849950050150229 unmodified linesfrom src.data_generation import generate_inventory_db, generate_orders_dbfrom src.intent_model import INTENT_DESCRIPTIONS, load_pipeline, predict as intent_predictfrom src.inventory_db import query_inventory, query_ordersfrom src.llm_client import answer_query, test_connectionfrom src.retriever import KBRetrieverROOT = os.path.dirname(os.path.abspath(__file__))67 unmodified linesretrieval_eval = _load_json("retrieval_eval.json")latency_eval = _load_json("latency_eval.json")HF_TOKEN_SET = bool(os.environ.get("HF_TOKEN"))# --------------------------------------------------------------------------# ZeroGPU compatibility shim382 unmodified lines)if not HF_TOKEN_SET:gr.Markdown("> ⚠️ **No `HF_TOKEN` secret detected.** The AI Assistant tab will run in ""**retrieval-only fallback mode** (still functional, just not LLM-generated ""prose). Add an `HF_TOKEN` secret in *Space settings → Variables and secrets* ""to enable full LLM responses.")with gr.Tab("💬 AI Assistant"):29 unmodified lines3031323334353667 unmodified lines104105106107108109110382 unmodified lines49349449549649749849950050150229 unmodified linesfrom src.data_generation import generate_inventory_db, generate_orders_dbfrom src.intent_model import INTENT_DESCRIPTIONS, load_pipeline, predict as intent_predictfrom src.inventory_db import query_inventory, query_ordersfrom src.llm_client import answer_query, test_connection, _get_hf_token, TOKEN_ENV_VAR_CANDIDATESfrom src.retriever import KBRetrieverROOT = os.path.dirname(os.path.abspath(__file__))67 unmodified linesretrieval_eval = _load_json("retrieval_eval.json")latency_eval = _load_json("latency_eval.json")HF_TOKEN_SET = bool(_get_hf_token())# --------------------------------------------------------------------------# ZeroGPU compatibility shim382 unmodified lines)if not HF_TOKEN_SET:gr.Markdown("> ⚠️ **No HF token secret detected.** The AI Assistant tab will run in ""**retrieval-only fallback mode** (still functional, just not LLM-generated "f"prose). Add a secret named `HF_TOKEN` (or one of: {', '.join(TOKEN_ENV_VAR_CANDIDATES[1:])}) ""in *Space settings → Variables and secrets* to enable full LLM responses.")with gr.Tab("💬 AI Assistant"):
46 unmodified lines47484950515243 unmodified lines969798991001011023 unmodified lines10610710810911011111246 unmodified linesDEFAULT_MODEL_ID = MODEL_CANDIDATES[0]SYSTEM_PROMPT = ("You are the Smart Warehouse AI Assistant, a helpful operations copilot ""for a large automated distribution center (conveyors, AS/RS, AGVs/AMRs, "43 unmodified linessources = retriever.retrieve(query, k=k)context_block = "\n\n".join(f"[{s.title}]\n{s.text}" for s in sources)hf_token = os.environ.get("HF_TOKEN")if not hf_token:answer = _extractive_fallback(query, sources)3 unmodified linessources=sources,latency_s=time.time() - start,model_id="extractive-fallback",debug_errors=["No HF_TOKEN secret is set on this Space."],)try:46 unmodified lines47484950515253545556575859606162636465666768697071727343 unmodified lines1171181191201211221233 unmodified lines12712812913013113213313413513613746 unmodified linesDEFAULT_MODEL_ID = MODEL_CANDIDATES[0]# The token is normally expected as `HF_TOKEN`, but we also accept a few# common alternate secret names in case the Space was set up with a# different name. First one found wins. Add your own name here if needed.TOKEN_ENV_VAR_CANDIDATES = ["HF_TOKEN","Smart_Warehouse","HUGGINGFACE_TOKEN","HUGGINGFACEHUB_API_TOKEN","HF_API_TOKEN","HUGGING_FACE_HUB_TOKEN","HF_ACCESS_TOKEN",]def _get_hf_token() -> Optional[str]:for var in TOKEN_ENV_VAR_CANDIDATES:val = os.environ.get(var)if val:return valreturn NoneSYSTEM_PROMPT = ("You are the Smart Warehouse AI Assistant, a helpful operations copilot ""for a large automated distribution center (conveyors, AS/RS, AGVs/AMRs, "43 unmodified linessources = retriever.retrieve(query, k=k)context_block = "\n\n".join(f"[{s.title}]\n{s.text}" for s in sources)hf_token = _get_hf_token()if not hf_token:answer = _extractive_fallback(query, sources)3 unmodified linessources=sources,latency_s=time.time() - start,model_id="extractive-fallback",debug_errors=["No HF token secret found. Checked env vars: "+ ", ".join(TOKEN_ENV_VAR_CANDIDATES)+ ". Set one of these as a Space secret (Settings -> Variables and secrets)."],)try:
app.py+5-5
src/llm_client.py+27-2