AsyncCoder-10 commited on
Commit
f02f394
Β·
verified Β·
1 Parent(s): 4027cdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -12
app.py CHANGED
@@ -2,27 +2,18 @@ import gradio as gr
2
  import spaces
3
  from app.main import app as fastapi_app, moderate_text, TextRequest
4
 
5
- # Dummy function to pass ZeroGPU check
6
  @spaces.GPU
7
  def _satisfy_zerogpu_startup_check():
8
  return "GPU available"
9
 
10
- # The real UI function that calls your FastAPI logic
11
  async def moderate_ui(text):
12
  if not text.strip():
13
  return "Please enter some text."
14
-
15
  try:
16
- # Create the Pydantic request object
17
  request = TextRequest(text=text)
18
-
19
- # Call your FastAPI function directly
20
  response = await moderate_text(request)
21
-
22
- # Format the output for the Gradio UI
23
  result = f"🚨 Flagged: {response.is_flagged}\n\n"
24
  result += f"πŸ“ Original: {response.original_text}\n\n"
25
-
26
  if response.is_flagged and response.rewritten_text:
27
  result += "βœ… Suggested Proper Sentences:\n"
28
  for i, suggestion in enumerate(response.rewritten_text, 1):
@@ -31,12 +22,10 @@ async def moderate_ui(text):
31
  result += "βœ… Suggested Proper Sentence: (Model could not generate a rewrite)"
32
  else:
33
  result += "βœ… This text is clean. No proper sentence needed."
34
-
35
  return result
36
  except Exception as e:
37
  return f"Error: {str(e)}"
38
 
39
- # Build the Gradio Interface
40
  demo = gr.Interface(
41
  fn=moderate_ui,
42
  inputs=gr.Textbox(lines=3, placeholder="Type a toxic sentence here..."),
@@ -45,7 +34,6 @@ demo = gr.Interface(
45
  description="Enter text to detect abuse/threats and get suggested proper sentences."
46
  )
47
 
48
- # Mount FastAPI onto Gradio for your external apps to use
49
  demo.app.mount("/api", fastapi_app)
50
 
51
  if __name__ == "__main__":
 
2
  import spaces
3
  from app.main import app as fastapi_app, moderate_text, TextRequest
4
 
 
5
  @spaces.GPU
6
  def _satisfy_zerogpu_startup_check():
7
  return "GPU available"
8
 
 
9
  async def moderate_ui(text):
10
  if not text.strip():
11
  return "Please enter some text."
 
12
  try:
 
13
  request = TextRequest(text=text)
 
 
14
  response = await moderate_text(request)
 
 
15
  result = f"🚨 Flagged: {response.is_flagged}\n\n"
16
  result += f"πŸ“ Original: {response.original_text}\n\n"
 
17
  if response.is_flagged and response.rewritten_text:
18
  result += "βœ… Suggested Proper Sentences:\n"
19
  for i, suggestion in enumerate(response.rewritten_text, 1):
 
22
  result += "βœ… Suggested Proper Sentence: (Model could not generate a rewrite)"
23
  else:
24
  result += "βœ… This text is clean. No proper sentence needed."
 
25
  return result
26
  except Exception as e:
27
  return f"Error: {str(e)}"
28
 
 
29
  demo = gr.Interface(
30
  fn=moderate_ui,
31
  inputs=gr.Textbox(lines=3, placeholder="Type a toxic sentence here..."),
 
34
  description="Enter text to detect abuse/threats and get suggested proper sentences."
35
  )
36
 
 
37
  demo.app.mount("/api", fastapi_app)
38
 
39
  if __name__ == "__main__":