AsyncCoder-10 commited on
Commit
66432ae
·
verified ·
1 Parent(s): 1baa228

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -1,9 +1,10 @@
1
  import uvicorn
2
  import gradio as gr
3
  import spaces
 
4
 
5
  # Import your FastAPI app and logic
6
- from app.main import app as fastapi_app, moderate_text, TextRequest
7
 
8
  @spaces.GPU
9
  def _satisfy_zerogpu_startup_check():
@@ -39,9 +40,16 @@ demo = gr.Interface(
39
  title="Multilingual Moderation API",
40
  )
41
 
42
- # 🔥 THE MAGIC FIX: Mount Gradio INSIDE FastAPI, at the "/ui" path
43
- app = gr.mount_gradio_app(fastapi_app, demo, path="/ui")
44
 
 
 
 
 
45
  if __name__ == "__main__":
46
- # Run FastAPI (which now contains Gradio)
47
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
 
 
 
1
  import uvicorn
2
  import gradio as gr
3
  import spaces
4
+ from fastapi import FastAPI
5
 
6
  # Import your FastAPI app and logic
7
+ from app.main import app as original_fastapi_app, moderate_text, TextRequest
8
 
9
  @spaces.GPU
10
  def _satisfy_zerogpu_startup_check():
 
40
  title="Multilingual Moderation API",
41
  )
42
 
43
+ # ✅ THE FIX: Access Gradio's internal FastAPI app and attach your routes
44
+ app = demo.app
45
 
46
+ # Re-add your FastAPI routes to the app that Hugging Face is actually serving
47
+ app.include_router(original_fastapi_app.router)
48
+
49
+ # Launch Gradio (this properly initializes @spaces.GPU)
50
  if __name__ == "__main__":
51
+ demo.launch(
52
+ server_name="0.0.0.0",
53
+ server_port=7860,
54
+ share=False
55
+ )