-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (55 loc) · 2.19 KB
/
Copy pathmain.py
File metadata and controls
66 lines (55 loc) · 2.19 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
from fastapi import FastAPI, HTTPException, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import logging
import os
from pathlib import Path
from app.core.config import settings
from app.services.heuristic_engine import HeuristicEvaluationEngine
from app.services.omniparser_client import OmniParserClient
from app.services.rag_knowledge_base import RAGKnowledgeBase
from app.api.routes import heuristic, evaluation, health
from app.utils.logging_config import setup_logging
app = FastAPI(
title="AI Heuristic Evaluation API",
description="AI-powered heuristic evaluation system using OmniParser and LLMs",
version="1.0.0"
)
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:8081", "http://127.0.0.1:8081"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(health.router, prefix="/health", tags=["health"])
app.include_router(heuristic.router, prefix="/api/v1/heuristic", tags=["heuristic"])
app.include_router(evaluation.router, prefix="/api/v1/evaluation", tags=["evaluation"])
@app.on_event("startup")
async def startup_event():
# Initialize OmniParser Client (Singleton)
app.state.omniparser_client = OmniParserClient()
await app.state.omniparser_client.initialize()
setup_logging()
logger = logging.getLogger(__name__)
logger.info("AI Heuristic Evaluation API starting up...")
# Initialize singleton OmniParser client to avoid re-initializing model on every request
app.state.omniparser_client = OmniParserClient()
await app.state.omniparser_client.initialize()
logger.info("OmniParser client initialized (singleton)")
heuristic_engine = HeuristicEvaluationEngine()
await heuristic_engine.initialize()
logger.info("Heuristic evaluation engine initialized")
@app.on_event("shutdown")
async def shutdown_event():
logger = logging.getLogger(__name__)
logger.info("AI Heuristic Evaluation API shutting down...")
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
host="0.0.0.0",
port=8000,
reload=True,
log_level=settings.LOG_LEVEL.lower()
)