| """ | |
| Main FastAPI application | |
| """ | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.staticfiles import StaticFiles | |
| from .api.routes import router | |
| from .config import CORS_ORIGINS, ASSETS_DIR, FRONTEND_DIST_DIR | |
| def create_app() -> FastAPI: | |
| """Create and configure the FastAPI application""" | |
| app = FastAPI(title="Edge LLM API") | |
| # Enable CORS for Hugging Face Space | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=CORS_ORIGINS, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Mount static files | |
| app.mount("/assets", StaticFiles(directory=ASSETS_DIR), name="assets") | |
| # Include API routes | |
| app.include_router(router) | |
| async def startup_event(): | |
| """Startup event - don't load models by default""" | |
| print("🚀 Edge LLM API is starting up...") | |
| print("💡 Models will be loaded on demand") | |
| return app | |
| # Create the app instance | |
| app = create_app() | |