File size: 997 Bytes
9bf7fc2
 
 
 
 
 
 
 
 
9609347
9bf7fc2
9609347
9bf7fc2
9609347
9bf7fc2
 
9609347
9bf7fc2
 
9609347
9bf7fc2
 
 
 
 
 
 
 
 
 
 
9609347
 
9bf7fc2
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
from fastapi.responses import RedirectResponse
import uvicorn
from fastapi import FastAPI
from server import router as mobile_router
from app import gradio_app  # your Blocks object
import gradio as gr
import logging
from fastapi.middleware import Middleware
from fastapi import Request

logging.basicConfig(level=logging.INFO)

app = FastAPI(title="Sanatan AI Unified Server")

# Mount mobile endpoints
app.include_router(mobile_router, prefix="/api")

# Convert Gradio Blocks to ASGI app
app = gr.mount_gradio_app(app, gradio_app,"/web")

# Redirect root URL to /web/
@app.get("/")
async def redirect_to_web():
    return RedirectResponse(url="/web/")

@app.middleware("http")
async def log_requests(request: Request, call_next):
    logging.info(f"Request: {request.method} {request.url}")
    response = await call_next(request)
    logging.info(f"Response status: {response.status_code}")
    return response

if __name__ == "__main__":
    uvicorn.run("main:app", host="0.0.0.0", port=7860)