rihancloud commited on
Commit
f8430db
Β·
1 Parent(s): 826cabf

Use demo.app.include_router and demo.launch to fix port collision

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -2,10 +2,10 @@ import sys
2
  import subprocess
3
  import importlib
4
 
5
- # πŸš€ 1. Self-Healing Auto-Installer: Catches any missing library, installs it, and retries!
6
  while True:
7
  try:
8
- from main import app
9
  break
10
  except ModuleNotFoundError as e:
11
  missing = e.name
@@ -30,16 +30,17 @@ while True:
30
  importlib.invalidate_caches()
31
 
32
  import gradio as gr
33
- import uvicorn
34
 
35
- # πŸš€ 2. Mount Gradio landing page so Hugging Face keeps the container alive 24/7
36
  with gr.Blocks(title="Tools Backend API") as demo:
37
  gr.Markdown("# πŸš€ CloudAiRambo Tools API Running")
38
  gr.Markdown("FastAPI Backend running live with in-memory database and 16 GB RAM.")
39
  gr.Markdown("- **Interactive Swagger Docs:** [/docs](/docs)")
40
  gr.Markdown("- **Health Check:** [/health](/health)")
41
 
42
- app = gr.mount_gradio_app(app, demo, path="/")
 
43
 
 
44
  if __name__ == "__main__":
45
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
2
  import subprocess
3
  import importlib
4
 
5
+ # πŸš€ 1. Self-Healing Auto-Installer
6
  while True:
7
  try:
8
+ from main import app as fastapi_app
9
  break
10
  except ModuleNotFoundError as e:
11
  missing = e.name
 
30
  importlib.invalidate_caches()
31
 
32
  import gradio as gr
 
33
 
34
+ # πŸš€ 2. Create Gradio interface
35
  with gr.Blocks(title="Tools Backend API") as demo:
36
  gr.Markdown("# πŸš€ CloudAiRambo Tools API Running")
37
  gr.Markdown("FastAPI Backend running live with in-memory database and 16 GB RAM.")
38
  gr.Markdown("- **Interactive Swagger Docs:** [/docs](/docs)")
39
  gr.Markdown("- **Health Check:** [/health](/health)")
40
 
41
+ # πŸš€ 3. Inject all your FastAPI endpoints directly into Gradio
42
+ demo.app.include_router(fastapi_app.router)
43
 
44
+ # πŸš€ 4. Launch natively via Gradio (prevents port 7860 collision)
45
  if __name__ == "__main__":
46
+ demo.launch()