Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
-
import uvicorn
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
# 1. Dummy function to pass ZeroGPU check
|
| 9 |
@spaces.GPU
|
|
@@ -32,7 +32,7 @@ async def moderate_ui(text):
|
|
| 32 |
except Exception as e:
|
| 33 |
return f"Error: {str(e)}"
|
| 34 |
|
| 35 |
-
# 3. Create Gradio UI
|
| 36 |
demo = gr.Interface(
|
| 37 |
fn=moderate_ui,
|
| 38 |
inputs=gr.Textbox(lines=3, placeholder="Type a toxic sentence here..."),
|
|
@@ -40,9 +40,12 @@ demo = gr.Interface(
|
|
| 40 |
title="Multilingual Moderation API",
|
| 41 |
)
|
| 42 |
|
| 43 |
-
# 4. THE
|
| 44 |
-
app
|
|
|
|
|
|
|
|
|
|
| 45 |
|
|
|
|
| 46 |
if __name__ == "__main__":
|
| 47 |
-
|
| 48 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
|
|
|
| 3 |
|
| 4 |
+
# We ONLY import the logic and the request model from your main.py
|
| 5 |
+
# We do NOT import the FastAPI app object itself to avoid conflicts.
|
| 6 |
+
from app.main import moderate_text, TextRequest
|
| 7 |
|
| 8 |
# 1. Dummy function to pass ZeroGPU check
|
| 9 |
@spaces.GPU
|
|
|
|
| 32 |
except Exception as e:
|
| 33 |
return f"Error: {str(e)}"
|
| 34 |
|
| 35 |
+
# 3. Create the Gradio UI
|
| 36 |
demo = gr.Interface(
|
| 37 |
fn=moderate_ui,
|
| 38 |
inputs=gr.Textbox(lines=3, placeholder="Type a toxic sentence here..."),
|
|
|
|
| 40 |
title="Multilingual Moderation API",
|
| 41 |
)
|
| 42 |
|
| 43 |
+
# 4. 🔥 THE FIX: Attach your custom endpoint directly to Gradio's server
|
| 44 |
+
@demo.app.post("/moderate")
|
| 45 |
+
async def custom_moderate_endpoint(request: TextRequest):
|
| 46 |
+
# This directly reuses your AI logic from main.py
|
| 47 |
+
return await moderate_text(request)
|
| 48 |
|
| 49 |
+
# 5. Launch
|
| 50 |
if __name__ == "__main__":
|
| 51 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|