Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from app.routes import chat | |
| from app.database import engine, Base | |
| from app.qdrant_client import init_qdrant_collection | |
| app = FastAPI(title="RAG Chatbot API") | |
| # CORS Configuration - Allow frontend to connect | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Include routers | |
| app.include_router(chat.router) | |
| async def startup_event(): | |
| # Create database tables | |
| try: | |
| Base.metadata.create_all(bind=engine) | |
| print("✅ Database tables created successfully") | |
| except Exception as e: | |
| print(f"⚠️ Warning: Database initialization failed: {e}") | |
| # Initialize Qdrant collection | |
| try: | |
| init_qdrant_collection() | |
| except Exception as e: | |
| print(f"⚠️ Warning: Qdrant initialization failed: {e}") | |
| print(" The API will still work but RAG features may be limited") | |
| async def root(): | |
| return {"message": "RAG Chatbot API"} | |
| async def health(): | |
| return {"status": "ok"} |