Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
-
|
| 4 |
-
# Import your FastAPI app and logic
|
| 5 |
from app.main import app as fastapi_app, moderate_text, TextRequest
|
| 6 |
|
| 7 |
-
#
|
| 8 |
@spaces.GPU
|
| 9 |
def _satisfy_zerogpu_startup_check():
|
| 10 |
return "GPU available"
|
| 11 |
|
| 12 |
-
#
|
| 13 |
async def moderate_ui(text):
|
| 14 |
if not text.strip():
|
| 15 |
return "Please enter some text."
|
|
@@ -31,7 +29,7 @@ async def moderate_ui(text):
|
|
| 31 |
except Exception as e:
|
| 32 |
return f"Error: {str(e)}"
|
| 33 |
|
| 34 |
-
#
|
| 35 |
demo = gr.Interface(
|
| 36 |
fn=moderate_ui,
|
| 37 |
inputs=gr.Textbox(lines=3, placeholder="Type a toxic sentence here..."),
|
|
@@ -39,15 +37,10 @@ demo = gr.Interface(
|
|
| 39 |
title="Multilingual Moderation API",
|
| 40 |
)
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# Mount your FastAPI app (this brings in your /moderate route)
|
| 46 |
-
server.mount("/api", fastapi_app)
|
| 47 |
-
|
| 48 |
-
# Mount the Gradio UI at a different path
|
| 49 |
-
server.mount("/ui", demo)
|
| 50 |
|
| 51 |
-
#
|
| 52 |
if __name__ == "__main__":
|
| 53 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
|
|
|
|
|
|
| 3 |
from app.main import app as fastapi_app, moderate_text, TextRequest
|
| 4 |
|
| 5 |
+
# Dummy function to pass ZeroGPU check
|
| 6 |
@spaces.GPU
|
| 7 |
def _satisfy_zerogpu_startup_check():
|
| 8 |
return "GPU available"
|
| 9 |
|
| 10 |
+
# The UI function
|
| 11 |
async def moderate_ui(text):
|
| 12 |
if not text.strip():
|
| 13 |
return "Please enter some text."
|
|
|
|
| 29 |
except Exception as e:
|
| 30 |
return f"Error: {str(e)}"
|
| 31 |
|
| 32 |
+
# Create Gradio UI
|
| 33 |
demo = gr.Interface(
|
| 34 |
fn=moderate_ui,
|
| 35 |
inputs=gr.Textbox(lines=3, placeholder="Type a toxic sentence here..."),
|
|
|
|
| 37 |
title="Multilingual Moderation API",
|
| 38 |
)
|
| 39 |
|
| 40 |
+
# ✅ THE FIX: Mount your FastAPI routes onto Gradio's internal app
|
| 41 |
+
# This makes your /moderate endpoint live alongside the UI.
|
| 42 |
+
demo.app.mount("/api", fastapi_app)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
# Launch Gradio
|
| 45 |
if __name__ == "__main__":
|
| 46 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|