Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, Request | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.staticfiles import StaticFiles | |
| from api.endpoints import router | |
| app = FastAPI( | |
| title="LangChain Chat Bot (Groq LLM, FastAPI)", | |
| description="Advanced chatbot API using LangChain and Groq models", | |
| version="2.0.0" | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(router, prefix="/api") | |
| # Serve the UI folder at the root | |
| app.mount("/", StaticFiles(directory="ui", html=True), name="ui") | |
| async def log_requests(request: Request, call_next): | |
| import time | |
| start_time = time.time() | |
| response = await call_next(request) | |
| process_time = time.time() - start_time | |
| print(f"π {request.method} {request.url.path} β {response.status_code} ({process_time:.2f}s)") | |
| return response | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7861) | |