AsyncCoder-10 commited on
Commit
b520f67
·
verified ·
1 Parent(s): 0608d7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,28 +1,31 @@
1
  import gradio as gr
2
- from app.main import app as fastapi_app
3
-
4
  import spaces
 
5
 
6
-
7
  @spaces.GPU
8
  def _satisfy_zerogpu_startup_check():
9
  """Dummy function to bypass ZeroGPU startup requirement."""
10
- return None
11
 
 
12
 
13
- # Create a simple Gradio interface
14
  def moderate_ui(text):
15
  return f"Processing text: {text}"
16
 
17
-
18
- gradio_interface = gr.Interface(
19
- fn=moderate_ui, inputs="text", outputs="text", title="Multilingual Moderation API"
 
 
20
  )
21
 
22
- # Mount FastAPI onto Gradio
23
- app = gr.mount_gradio_app(fastapi_app, gradio_interface, path="/")
 
 
24
 
 
25
  if __name__ == "__main__":
26
- import uvicorn
27
-
28
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
  import gradio as gr
 
 
2
  import spaces
3
+ import uvicorn
4
 
5
+ # Dummy GPU function at the module level to pass ZeroGPU startup check
6
  @spaces.GPU
7
  def _satisfy_zerogpu_startup_check():
8
  """Dummy function to bypass ZeroGPU startup requirement."""
9
+ return "GPU available"
10
 
11
+ from app.main import app as fastapi_app
12
 
13
+ # 1. Create the Gradio Interface
14
  def moderate_ui(text):
15
  return f"Processing text: {text}"
16
 
17
+ demo = gr.Interface(
18
+ fn=moderate_ui,
19
+ inputs="text",
20
+ outputs="text",
21
+ title="Multilingual Moderation API"
22
  )
23
 
24
+ # 2. Mount your FastAPI app onto Gradio's underlying FastAPI instance
25
+ # This keeps your /moderate and /health endpoints accessible.
26
+ # We mount it under the "/api" path to avoid conflicts.
27
+ demo.app.mount("/api", fastapi_app)
28
 
29
+ # 3. Launch Gradio (required for ZeroGPU)
30
  if __name__ == "__main__":
31
+ demo.launch(server_name="0.0.0.0", server_port=7860)