Spaces:
Sleeping
Sleeping
| """ | |
| FastAPI Backend for Physical AI & Humanoid Robotics Textbook | |
| Features: RAG Chatbot, Authentication, Urdu Translation | |
| """ | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| app = FastAPI( | |
| title="Physical AI Textbook API", | |
| description="RAG Chatbot, Auth, and Translation services", | |
| version="1.0.0" | |
| ) | |
| # CORS Configuration | |
| allowed_origins = os.getenv("ALLOWED_ORIGINS", "http://localhost:3000").split(",") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=allowed_origins, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Import routes | |
| from api.routes import chat, auth, translate, personalize | |
| # from api.routes import rag # Disabled: RAG dependencies not installed | |
| app.include_router(chat.router, prefix="/api/chat", tags=["RAG Chatbot"]) | |
| app.include_router(auth.router, prefix="/api/auth", tags=["Authentication"]) | |
| app.include_router(translate.router, prefix="/api/translate", tags=["Translation"]) | |
| app.include_router(personalize.router, prefix="/api/personalize", tags=["Personalization"]) | |
| # app.include_router(rag.router, prefix="/api", tags=["RAG System"]) # Disabled | |
| async def root(): | |
| return { | |
| "message": "Physical AI Textbook API", | |
| "features": ["RAG Chatbot (+50 pts)", "Personalization (+50 pts)", "Auth (+30 pts)", "Translation (+50 pts)"], | |
| "status": "ready", | |
| "docs": "/docs" | |
| } | |
| async def health_check(): | |
| """Health check endpoint for deployment""" | |
| return { | |
| "status": "healthy", | |
| "services": { | |
| "api": "running", | |
| "openai": "configured" if os.getenv("OPENAI_API_KEY") else "missing", | |
| "qdrant": "configured" if os.getenv("QDRANT_URL") else "missing", | |
| "database": "configured" if os.getenv("DATABASE_URL") else "missing" | |
| } | |
| } | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) | |