Spaces:
Runtime error
Runtime error
Download app.py from cloudaiRambo/cloudairambo: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/app.py
- Command line
-
hf download hf://spaces/cloudaiRambo/cloudairambo/app.py
-
curl -L -o app.py https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/app.py
1.82 kB
| # 1. ZeroGPU MUST be imported before ANYTHING else | |
| import spaces | |
| # 2. Patch the asyncio -1 file descriptor cleanup bug | |
| import asyncio | |
| import asyncio.selector_events | |
| if hasattr(asyncio.selector_events.BaseSelectorEventLoop, "_close_self_pipe"): | |
| _orig_close_self_pipe = asyncio.selector_events.BaseSelectorEventLoop._close_self_pipe | |
| def _patched_close_self_pipe(self): | |
| try: | |
| _orig_close_self_pipe(self) | |
| except (ValueError, OSError): | |
| pass | |
| asyncio.selector_events.BaseSelectorEventLoop._close_self_pipe = _patched_close_self_pipe | |
| # 3. Imports | |
| import os | |
| import gradio as gr | |
| from fastapi.staticfiles import StaticFiles | |
| from main import app # your real FastAPI app: routers + CORS already set up | |
| # 4. ZeroGPU anchor | |
| def zero_gpu_keepalive(): | |
| return "GPU Active" | |
| # 5. Landing page | |
| with gr.Blocks(title="Tools Backend API") as demo: | |
| gr.Markdown("# 🚀 CloudAiRambo Tools API Running") | |
| gr.Markdown("- **Frontend Site:** [freetoolshub.cloudairambo.com](https://freetoolshub.cloudairambo.com)") | |
| gr.Markdown("- **Swagger Docs:** [/docs](/docs)") | |
| # Hidden hook so ZeroGPU sees the GPU function used in a Gradio event | |
| _out = gr.Textbox(visible=False) | |
| _btn = gr.Button("ping", visible=False) | |
| _btn.click(zero_gpu_keepalive, inputs=None, outputs=_out, api_name="gpu_ping") | |
| # 6. Static dirs (only if main.py hasn't already mounted them) | |
| for name in ("static", "uploads"): | |
| os.makedirs(name, exist_ok=True) | |
| if not any(getattr(r, "name", None) == name for r in app.routes): | |
| app.mount(f"/{name}", StaticFiles(directory=name), name=name) | |
| # 7. Gradio goes LAST so your API routes win | |
| app = gr.mount_gradio_app(app, demo, path="/") | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |