Spaces:
Runtime error
Runtime error
| import os | |
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from config import settings | |
| from routes.documents import router as documents_router | |
| from routes.chat import router as chat_router | |
| async def lifespan(app: FastAPI): | |
| """Application lifespan - create required directories on startup.""" | |
| os.makedirs(settings.UPLOAD_DIR, exist_ok=True) | |
| os.makedirs(settings.CHROMA_DB_PATH, exist_ok=True) | |
| print("✅ RAG Assistant API started") | |
| print(f" LLM Model: {settings.LLM_MODEL}") | |
| print(f" Embedding Model: {settings.EMBEDDING_MODEL}") | |
| print(f" ChromaDB Path: {settings.CHROMA_DB_PATH}") | |
| yield | |
| print("🛑 RAG Assistant API shutting down") | |
| app = FastAPI( | |
| title="RAG Assistant API", | |
| description="A Retrieval-Augmented Generation assistant that answers questions from uploaded PDF documents.", | |
| version="1.0.0", | |
| lifespan=lifespan, | |
| ) | |
| # CORS middleware for frontend | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["http://localhost:5173", "http://localhost:3000", "*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Register routers | |
| app.include_router(documents_router) | |
| app.include_router(chat_router) | |
| async def health_check(): | |
| return {"status": "healthy"} | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run("main:app", host="0.0.0.0", port=8001, reload=True) | |