AsyncCoder-10 commited on
Commit
5a3a2b2
·
verified ·
1 Parent(s): 779bd3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,9 +1,8 @@
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,7 +31,7 @@ async def moderate_ui(text):
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,12 +39,15 @@ demo = gr.Interface(
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)
 
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)