Download app/main.py from acpcchatbotadmin/acpcchatbot_testing_first: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/spaces/acpcchatbotadmin/acpcchatbot_testing_first/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/acpcchatbotadmin/acpcchatbot_testing_first/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/acpcchatbotadmin/acpcchatbot_testing_first/resolve/main/app/main.py
1.97 kB
| import logging | |
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from app.config import settings | |
| from app.agent.graph import get_graph | |
| from app.retrieval.qdrant_store import get_vector_store | |
| from app.monitoring.langfuse_setup import get_langfuse_callback_handler, flush_langfuse | |
| from app.memory.session_store import start_cleanup_task, stop_cleanup_task | |
| from app.routers import chat, stt, ingest, health, sessions | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", | |
| ) | |
| logger = logging.getLogger(__name__) | |
| async def lifespan(app: FastAPI): | |
| """Application startup / shutdown lifecycle.""" | |
| logger.info("Starting ACPC Chatbot backend...") | |
| # Pre-warm non-network singletons | |
| get_graph() | |
| get_langfuse_callback_handler() | |
| start_cleanup_task() | |
| # NOTE: Qdrant vector store is lazily initialized on first query | |
| # (avoids startup failure if Qdrant Cloud is temporarily unreachable) | |
| logger.info("Backend ready.") | |
| yield | |
| # Shutdown | |
| stop_cleanup_task() | |
| flush_langfuse() | |
| logger.info("Backend shut down cleanly.") | |
| app = FastAPI( | |
| title="ACPC Gujarat Chatbot API", | |
| description="Agentic RAG chatbot for ACPC Gujarat admissions queries", | |
| version="1.0.0", | |
| lifespan=lifespan, | |
| ) | |
| # CORS — restrict to configured origins | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.allowed_origins, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Mount routers | |
| app.include_router(chat.router) | |
| app.include_router(stt.router) | |
| app.include_router(ingest.router) | |
| app.include_router(health.router) | |
| app.include_router(sessions.router) | |
| async def root(): | |
| return {"status": "ok", "service": "ACPC Gujarat Chatbot API", "version": "1.0.0"} | |