Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import spaces # must be first
|
| 2 |
import gradio as gr
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from starlette.routing import Mount
|
|
@@ -34,14 +34,13 @@ with gr.Blocks(title="Multilingual Moderation API") as demo:
|
|
| 34 |
out = gr.Textbox(lines=12, label="Moderation Result")
|
| 35 |
btn.click(moderate_ui, inp, out, api_name="moderate_ui")
|
| 36 |
|
| 37 |
-
# Hidden event so the @spaces.GPU function
|
| 38 |
with gr.Row(visible=False):
|
| 39 |
h_in = gr.Textbox()
|
| 40 |
h_out = gr.JSON()
|
| 41 |
h_btn = gr.Button()
|
| 42 |
h_btn.click(generate_suggestions, h_in, h_out, api_name="rewrite")
|
| 43 |
|
| 44 |
-
# CORS goes on the sub-app (middleware can't be added to Gradio's app after launch)
|
| 45 |
moderation_api.add_middleware(
|
| 46 |
CORSMiddleware,
|
| 47 |
allow_origins=["*"], # restrict to your Angular domain in production
|
|
@@ -50,12 +49,10 @@ moderation_api.add_middleware(
|
|
| 50 |
)
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|
| 53 |
-
# launch() is what triggers ZeroGPU's startup detection
|
| 54 |
gradio_app, _, _ = demo.launch(
|
| 55 |
server_name="0.0.0.0",
|
| 56 |
server_port=7860,
|
| 57 |
prevent_thread_lock=True,
|
| 58 |
)
|
| 59 |
-
# Put /api first so it wins over any Gradio route
|
| 60 |
gradio_app.router.routes.insert(0, Mount("/api", app=moderation_api))
|
| 61 |
demo.block_thread()
|
|
|
|
| 1 |
+
import spaces # must be first
|
| 2 |
import gradio as gr
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from starlette.routing import Mount
|
|
|
|
| 34 |
out = gr.Textbox(lines=12, label="Moderation Result")
|
| 35 |
btn.click(moderate_ui, inp, out, api_name="moderate_ui")
|
| 36 |
|
| 37 |
+
# Hidden event so ZeroGPU detects the @spaces.GPU function
|
| 38 |
with gr.Row(visible=False):
|
| 39 |
h_in = gr.Textbox()
|
| 40 |
h_out = gr.JSON()
|
| 41 |
h_btn = gr.Button()
|
| 42 |
h_btn.click(generate_suggestions, h_in, h_out, api_name="rewrite")
|
| 43 |
|
|
|
|
| 44 |
moderation_api.add_middleware(
|
| 45 |
CORSMiddleware,
|
| 46 |
allow_origins=["*"], # restrict to your Angular domain in production
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
|
|
|
| 52 |
gradio_app, _, _ = demo.launch(
|
| 53 |
server_name="0.0.0.0",
|
| 54 |
server_port=7860,
|
| 55 |
prevent_thread_lock=True,
|
| 56 |
)
|
|
|
|
| 57 |
gradio_app.router.routes.insert(0, Mount("/api", app=moderation_api))
|
| 58 |
demo.block_thread()
|