Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from api.coding_assistant import v1 as coding_assistant_v1 | |
| from config import ALLOWED_ORIGINS | |
| from database import init_db | |
| from fastapi_cache import FastAPICache | |
| from fastapi_cache.backends.inmemory import InMemoryBackend | |
| import asyncio | |
| import logging | |
| # Configure logging | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
| handlers=[ | |
| logging.FileHandler("app.log"), | |
| logging.StreamHandler() | |
| ] | |
| ) | |
| logger = logging.getLogger(__name__) | |
| app = FastAPI() | |
| # CORS middleware setup | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=ALLOWED_ORIGINS, | |
| allow_credentials=True, | |
| allow_methods=["GET", "POST"], | |
| allow_headers=["*"], | |
| ) | |
| # Include routers | |
| app.include_router(coding_assistant_v1.router) | |
| # app.include_router(news_assistant_v1.router) | |
| # app.include_router(search_assistant_v1.router) | |
| # app.include_router(followup_agent_v1.router) | |
| # app.include_router(followup_agent_v2.router) | |
| # app.include_router(followup_agent_v3.router) | |
| # app.include_router(followup_agent_v4.router) | |
| # app.include_router(digiyatra_followup_v1.router) | |
| async def startup_event(): | |
| logger.info("Starting up the application") | |
| FastAPICache.init(InMemoryBackend(), prefix="fastapi-cache") | |
| asyncio.create_task(clear_inactive_conversations()) | |
| init_db() | |
| if __name__ == "__main__": | |
| import uvicorn | |
| logger.info("Starting the application") | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |