Spaces:
Sleeping
Sleeping
Placebo Deploy commited on
Commit ·
b74b3f4
1
Parent(s): d7a6400
Fix HF Spaces boot timeout by initializing bot in background
Browse files56 unmodified lines5758596061626364656667686970717273747556 unmodified lines# Disable default docs to allow our custom /docs route to work# Global chatbot instancebot = None@asynccontextmanagerasync def lifespan(app: FastAPI):global bottry:print("Initializing Medical Chatbot Engine...")bot = MedicalChatbot()print("--- VECTOR STORE VERIFICATION ---")print("Skipped verification search during startup to prevent boot hanging (useful when Ollama is processing background ingestion tasks).")print("---------------------------------")except Exception as e:print(f"Chatbot initialization error: {e}")yield# Disable default docs to allow our custom /docs route to work56 unmodified lines57585960616263646566676869707172737475767778798081828356 unmodified lines# Disable default docs to allow our custom /docs route to work# Global chatbot instanceimport asynciobot = None@asynccontextmanagerasync def lifespan(app: FastAPI):def init_bot():global bottry:print("Initializing Medical Chatbot Engine in background...")bot = MedicalChatbot()print("--- VECTOR STORE VERIFICATION ---")print("Skipped verification search during startup to prevent boot hanging (useful when Ollama is processing background ingestion tasks).")print("---------------------------------")print("MedicalChatbot initialization complete.")except Exception as e:print(f"Chatbot initialization error: {e}")# Run in background executor to prevent blocking Uvicorn's port bindingloop = asyncio.get_running_loop()loop.run_in_executor(None, init_bot)yield# Disable default docs to allow our custom /docs route to work
src/app.py+17-9