AsyncCoder-10 commited on
Commit
5bfa65d
·
verified ·
1 Parent(s): c8295b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -30
app.py CHANGED
@@ -1,44 +1,30 @@
1
  import gradio as gr
2
  import spaces
 
3
 
4
- from app.main import moderate_text, TextRequest
5
-
6
  @spaces.GPU
7
  def _satisfy_zerogpu_startup_check():
8
  return "GPU available"
9
 
10
- async def moderate_ui(text):
11
- if not text.strip():
12
- return "Please enter some text."
13
-
14
- try:
15
- request = TextRequest(text=text)
16
- response = await moderate_text(request)
17
-
18
- result = f"🚨 Flagged: {response.is_flagged}\n\n"
19
- result += f"📝 Original: {response.original_text}\n\n"
20
-
21
- if response.is_flagged and response.rewritten_text:
22
- result += "✅ Suggested Proper Sentences:\n"
23
- # Loop through the 5 suggestions and format them
24
- for i, suggestion in enumerate(response.rewritten_text, 1):
25
- result += f"{i}. {suggestion}\n"
26
- elif response.is_flagged:
27
- result += "✅ Suggested Proper Sentence: (Model could not generate a rewrite)"
28
- else:
29
- result += "✅ This text is clean. No proper sentence needed."
30
-
31
- return result
32
- except Exception as e:
33
- return f"Error: {str(e)}"
34
 
35
  demo = gr.Interface(
36
  fn=moderate_ui,
37
- inputs=gr.Textbox(lines=3, placeholder="Type a toxic sentence here..."),
38
- outputs=gr.Textbox(lines=12, label="Moderation Result"), # Increased lines for output
39
- title="Multilingual Moderation API",
40
- description="Enter text to detect abuse/threats and get suggested proper sentences."
41
  )
42
 
 
 
 
 
 
 
 
 
43
  if __name__ == "__main__":
44
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import gradio as gr
2
  import spaces
3
+ from app.main import app as fastapi_app
4
 
5
+ # Dummy function to pass ZeroGPU check
 
6
  @spaces.GPU
7
  def _satisfy_zerogpu_startup_check():
8
  return "GPU available"
9
 
10
+ # Create the Gradio Interface
11
+ def moderate_ui(text):
12
+ return f"Processing text: {text}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  demo = gr.Interface(
15
  fn=moderate_ui,
16
+ inputs="text",
17
+ outputs="text",
18
+ title="Multilingual Moderation API"
 
19
  )
20
 
21
+ # Mount FastAPI onto Gradio's app
22
+ # We also explicitly add the docs URL route so it's accessible
23
+ demo.app.mount("/api", fastapi_app)
24
+
25
+ # This line is the key: it exposes the /api/docs route on the main server
26
+ # by re-mounting the FastAPI app's docs endpoint.
27
+ demo.app.add_route("/api/docs", fastapi_app.docs_ui_router)
28
+
29
  if __name__ == "__main__":
30
  demo.launch(server_name="0.0.0.0", server_port=7860)