Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
-
import spaces # must be first
|
| 2 |
import gradio as gr
|
| 3 |
import uvicorn
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
|
| 7 |
-
|
| 8 |
-
from main import app as moderation_api, moderate_text, TextRequest, generate_suggestions
|
| 9 |
-
# If main.py is inside an app/ folder, use: from app.main import ...
|
| 10 |
|
| 11 |
|
| 12 |
async def moderate_ui(text):
|
|
@@ -37,7 +35,7 @@ with gr.Blocks(title="Multilingual Moderation API") as demo:
|
|
| 37 |
out = gr.Textbox(lines=12, label="Moderation Result")
|
| 38 |
btn.click(moderate_ui, inp, out, api_name="moderate_ui")
|
| 39 |
|
| 40 |
-
# Hidden event
|
| 41 |
with gr.Row(visible=False):
|
| 42 |
h_in = gr.Textbox()
|
| 43 |
h_out = gr.JSON()
|
|
@@ -53,7 +51,7 @@ root.add_middleware(
|
|
| 53 |
allow_headers=["*"],
|
| 54 |
)
|
| 55 |
|
| 56 |
-
root.mount("/api", moderation_api)
|
| 57 |
app = gr.mount_gradio_app(root, demo, path="/")
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
import spaces # must be first, before torch/transformers
|
| 2 |
import gradio as gr
|
| 3 |
import uvicorn
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
|
| 7 |
+
from app.main import app as moderation_api, moderate_text, TextRequest, generate_suggestions
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
async def moderate_ui(text):
|
|
|
|
| 35 |
out = gr.Textbox(lines=12, label="Moderation Result")
|
| 36 |
btn.click(moderate_ui, inp, out, api_name="moderate_ui")
|
| 37 |
|
| 38 |
+
# Hidden event so ZeroGPU detects the @spaces.GPU function at startup
|
| 39 |
with gr.Row(visible=False):
|
| 40 |
h_in = gr.Textbox()
|
| 41 |
h_out = gr.JSON()
|
|
|
|
| 51 |
allow_headers=["*"],
|
| 52 |
)
|
| 53 |
|
| 54 |
+
root.mount("/api", moderation_api) # -> /api/moderate and /api/health
|
| 55 |
app = gr.mount_gradio_app(root, demo, path="/")
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|