Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
from app.main import moderate_text, TextRequest
|
| 7 |
|
| 8 |
# 1. Dummy function to pass ZeroGPU check
|
| 9 |
@spaces.GPU
|
|
@@ -32,7 +31,7 @@ async def moderate_ui(text):
|
|
| 32 |
except Exception as e:
|
| 33 |
return f"Error: {str(e)}"
|
| 34 |
|
| 35 |
-
# 3. Create
|
| 36 |
demo = gr.Interface(
|
| 37 |
fn=moderate_ui,
|
| 38 |
inputs=gr.Textbox(lines=3, placeholder="Type a toxic sentence here..."),
|
|
@@ -40,12 +39,15 @@ demo = gr.Interface(
|
|
| 40 |
title="Multilingual Moderation API",
|
| 41 |
)
|
| 42 |
|
| 43 |
-
# 4.
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# 5. Launch
|
| 50 |
if __name__ == "__main__":
|
| 51 |
-
|
|
|
|
| 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 |
# 1. Dummy function to pass ZeroGPU check
|
| 8 |
@spaces.GPU
|
|
|
|
| 31 |
except Exception as e:
|
| 32 |
return f"Error: {str(e)}"
|
| 33 |
|
| 34 |
+
# 3. Create Gradio UI
|
| 35 |
demo = gr.Interface(
|
| 36 |
fn=moderate_ui,
|
| 37 |
inputs=gr.Textbox(lines=3, placeholder="Type a toxic sentence here..."),
|
|
|
|
| 39 |
title="Multilingual Moderation API",
|
| 40 |
)
|
| 41 |
|
| 42 |
+
# 4. ✅ THE FIX: Create a Server and mount your apps
|
| 43 |
+
server = gr.Server()
|
| 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 |
# 5. Launch
|
| 52 |
if __name__ == "__main__":
|
| 53 |
+
server.launch(server_name="0.0.0.0", server_port=7860)
|