Spaces:
Runtime error
Runtime error
Download app.py from AsyncCoder-10/my-moderation-api: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/AsyncCoder-10/my-moderation-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/AsyncCoder-10/my-moderation-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AsyncCoder-10/my-moderation-api/resolve/main/app.py
1.31 kB
| 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 | |
| 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) |