File size: 1,271 Bytes
21446aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# api/app_new.py
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .config import setup_logging, check_system_resources, optimize_memory, CORS_ORIGINS, validate_environment
from .routes import router

# ✅ Validate environment
validate_environment()

# ✅ Setup logging
logger = setup_logging()
logger.info("🍳 Starting Cooking Tutor API...")

# ✅ Monitor system resources
check_system_resources(logger)

# ✅ Optimize memory usage
optimize_memory()

# ✅ Initialize FastAPI app
app = FastAPI(
    title="Cooking Tutor API",
    description="AI-powered cooking lesson and recipe tutoring with web search",
    version="1.0.0"
)

# ✅ Add CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=CORS_ORIGINS,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# No database initialization required for cooking tutor (web-search only)

# ✅ Include routes
app.include_router(router)

# ✅ Run Uvicorn
if __name__ == "__main__":
    logger.info("[System] ✅ Starting FastAPI Server...")
    try:
        uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
    except Exception as e:
        logger.error(f"❌ Server Startup Failed: {e}")
        exit(1)