Spaces:
Sleeping
Sleeping
File size: 2,253 Bytes
ba2fc46 4f47bd4 370480b efe7f8f 370480b 3f23aac 370480b 3f23aac 370480b 3f23aac 370480b efe7f8f ba2fc46 370480b 3f23aac 5408bf6 370480b 3f23aac 370480b 3f23aac 370480b ba2fc46 370480b 3f23aac 370480b 3f23aac |
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 |
# backend/src/main.py
# --- EXTERNAL IMPORTS ---
import os
# import asyncio
# import sys
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from backend.src.core.config import settings
# --- API Route Imports ---
from backend.src.api.routes import visual, chat, ingestion, auth, settings as settings_route
# # ==========================================
# # π₯ WINDOWS FIX FOR DB TIMEOUTS π₯
# # ==========================================
# if sys.platform.startswith("win"):
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
# 1. App Initialize karein
app = FastAPI(
title=settings.PROJECT_NAME,
version=settings.VERSION,
description="OmniAgent Core API - The Intelligent Employee"
)
# 2. CORS Setup (Security)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=False,
allow_methods=["*"],
allow_headers=["*"],
)
# 3. Mount Static Files
if not os.path.exists("static"):
os.makedirs("static")
app.mount("/static", StaticFiles(directory="static"), name="static")
# 4. Health Check Route
@app.get("/")
async def root():
return {
"message": "Welcome to OmniAgent Core π",
"status": "active",
"widget_url": "/static/widget.js"
}
# 5. API Router Includes
app.include_router(auth.router, prefix=settings.API_V1_STR, tags=["Authentication"])
app.include_router(settings_route.router, prefix=settings.API_V1_STR, tags=["User Settings"])
app.include_router(chat.router, prefix=settings.API_V1_STR, tags=["Chat"])
app.include_router(ingestion.router, prefix=settings.API_V1_STR, tags=["Ingestion"])
app.include_router(visual.router, prefix=settings.API_V1_STR, tags=["Visual Search"])
# ==========================================
# π₯ UNIVERSAL START LOGIC π₯
# ==========================================
if __name__ == "__main__":
import uvicorn
# Environment se PORT uthao, agar na mile to 8000 use karo
# Yeh logic Local + Deployment dono jagah chalegi
port = int(os.environ.get("PORT", 8000))
print(f"π Starting Server on Port: {port}")
uvicorn.run("backend.src.main:app", host="0.0.0.0", port=port, reload=True) |