forked from PhuocPhat1005/Advanced_Data_Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
68 lines (54 loc) · 1.95 KB
/
app.py
File metadata and controls
68 lines (54 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import uvicorn
from fastapi import FastAPI, Request
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from pydantic_settings import BaseSettings
from starlette.middleware.cors import CORSMiddleware
from backend.api.descriptive_analysis_endpoints import descriptive_router
from backend.api.diagnostic_analysis_endponts import diagnostic_router
from backend.api.llm_agent_endpoints import llm_agent_router
from backend.api.predictive_analysis_endpoints import predictive_router
class Settings(BaseSettings):
APP_TITLE: str = "Data Analysis Application"
APP_DESC: str = "API for Data Analysis Application"
APP_VERSION: str = "25.1"
HOST: str = "127.0.0.1"
PORT: int = 8000
RELOAD: bool = True
CORS_ORIGINS: list[str] = ["*"]
GOOGLE_API_KEY: str # ← thêm biến này
class Config:
env_file = ".env"
settings = Settings()
def create_app() -> FastAPI:
app = FastAPI(
title=settings.APP_TITLE,
description=settings.APP_DESC,
version=settings.APP_VERSION,
)
app.add_middleware(
CORSMiddleware,
allow_origins=['http://localhost:3000'],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc: RequestValidationError):
return JSONResponse(
status_code=422,
content={"detail": exc.errors(), "body": exc.body},
)
app.include_router(descriptive_router, prefix="/analysis")
app.include_router(diagnostic_router, prefix="/analysis")
app.include_router(predictive_router, prefix="/analysis")
app.include_router(llm_agent_router, prefix="/ai_agent")
return app
app = create_app()
if __name__ == "__main__":
uvicorn.run(
"app:app",
host=settings.HOST,
port=settings.PORT,
reload=settings.RELOAD,
)