Spaces:
Running on Zero
Running on Zero
Download app.py from AsyncCoder-10/moderation-api: direct link, hf CLI and curl.
- Browser
- Download file 902 Bytes
-
https://huggingface.co/spaces/AsyncCoder-10/moderation-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/AsyncCoder-10/moderation-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AsyncCoder-10/moderation-api/resolve/main/app.py
902 Bytes
| import gradio as gr | |
| import spaces | |
| import uvicorn | |
| # Dummy GPU function at the module level to pass ZeroGPU startup check | |
| def _satisfy_zerogpu_startup_check(): | |
| """Dummy function to bypass ZeroGPU startup requirement.""" | |
| return "GPU available" | |
| from app.main import app as fastapi_app | |
| # 1. Create the Gradio Interface | |
| def moderate_ui(text): | |
| return f"Processing text: {text}" | |
| demo = gr.Interface( | |
| fn=moderate_ui, | |
| inputs="text", | |
| outputs="text", | |
| title="Multilingual Moderation API" | |
| ) | |
| # 2. Mount your FastAPI app onto Gradio's underlying FastAPI instance | |
| # This keeps your /moderate and /health endpoints accessible. | |
| # We mount it under the "/api" path to avoid conflicts. | |
| demo.app.mount("/api", fastapi_app) | |
| # 3. Launch Gradio (required for ZeroGPU) | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) |