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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import gradio as gr
2
  import spaces
3
- import uvicorn
4
 
5
- # Import your FastAPI app and logic
6
- from app.main import app as fastapi_app, moderate_text, TextRequest
 
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 CRITICAL FIX: Mount Gradio at "/ui" and let FastAPI own the rest
44
- app = gr.mount_gradio_app(fastapi_app, demo, path="/ui")
 
 
 
45
 
 
46
  if __name__ == "__main__":
47
- # Run the combined app
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)