File size: 1,312 Bytes
ca36815
 
 
4e2ae91
85aee19
ca36815
4e2ae91
 
 
85aee19
ca36815
 
 
 
a4d12b8
ca36815
 
5c0cac9
ca36815
 
 
 
 
85aee19
 
4e2ae91
85aee19
4e2ae91
 
85aee19
4e2ae91
 
 
 
 
85aee19
5c0cac9
 
85aee19
 
 
 
4e2ae91
85aee19
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
import spaces
import gradio as gr
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn

# Import your moderation router
from app.api.v1.endpoints.moderation import router as moderation_router

# 1. Dummy GPU function for ZeroGPU validation
@spaces.GPU
def dummy_gpu_check():
    return "ZeroGPU Hardware Connected!"

# 2. Build the Gradio UI
with gr.Blocks() as demo:
    gr.Markdown("# 🛡️ Moderation API")
    gr.Markdown("The API is live at `/api/v1/moderate`.")
    with gr.Row():
        btn = gr.Button("Test ZeroGPU Connection")
        output = gr.Textbox()
        btn.click(fn=dummy_gpu_check, inputs=[], outputs=output)

# 3. Create the main FastAPI application FIRST
app = FastAPI(title="Moderation API")

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

# 5. Include your moderation routes BEFORE mounting Gradio
app.include_router(moderation_router, prefix="/api/v1")

# 6. Mount Gradio at the root path with ssr_mode=False to prevent interception
app = gr.mount_gradio_app(app, demo, path="/", ssr_mode=False)

# 7. Run the FastAPI app (not demo.launch())
if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)