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 lines57585960616263646566646566676869707172676869707172737475767778798081828356 unmodified lines
# Disable default docs to allow our custom /docs route to work# Global chatbot instanceimport asyncio
bot = None
@asynccontextmanagerasync def lifespan(app: FastAPI): def init_bot(): global bot try: 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}") global bot try: 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 binding loop = asyncio.get_running_loop() loop.run_in_executor(None, init_bot) yield
# Disable default docs to allow our custom /docs route to worksrc/app.py+17-9