rihancloud commited on
Commit
e98edba
·
1 Parent(s): 78e6694

Mount FastAPI app with Gradio to keep server alive

Browse files
Files changed (2) hide show
  1. app.py +11 -29
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,34 +1,16 @@
1
- import sys
2
- import subprocess
3
- import importlib
4
 
5
- # 🚀 Self-Healing Auto-Installer
6
- while True:
7
- try:
8
- from main import app
9
- break
10
- except ModuleNotFoundError as e:
11
- missing = e.name
12
- mapping = {
13
- "pkg_resources": "setuptools",
14
- "fitz": "PyMuPDF",
15
- "PIL": "Pillow",
16
- "docx": "python-docx",
17
- "pptx": "python-pptx",
18
- "bs4": "beautifulsoup4",
19
- "dns": "dnspython",
20
- "yaml": "pyyaml",
21
- "cv2": "opencv-python-headless",
22
- "jwt": "pyjwt",
23
- "mac_vendor_lookup": "mac-vendor-lookup",
24
- "barcode": "python-barcode",
25
- }
26
- pkg = mapping.get(missing, missing)
27
- print(f"⚡ [AUTO-INSTALL] Missing module '{missing}'. Installing '{pkg}' via pip...")
28
- subprocess.check_call([sys.executable, "-m", "pip", "install", pkg])
29
- importlib.invalidate_caches()
30
 
31
- import uvicorn
 
32
 
33
  if __name__ == "__main__":
34
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
+ import uvicorn
2
+ import gradio as gr
3
+ from main import app # Your full FastAPI backend
4
 
5
+ # Create a clean landing page for Hugging Face
6
+ with gr.Blocks(title="Tools Backend API") as demo:
7
+ gr.Markdown("# 🚀 CloudAiRambo Tools API Running")
8
+ gr.Markdown("FastAPI Backend is running live with in-memory database and 16 GB RAM.")
9
+ gr.Markdown("- **Interactive Swagger Docs:** [/docs](/docs)")
10
+ gr.Markdown("- **Health Check:** [/health](/health)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # Mount Gradio onto your FastAPI app
13
+ app = gr.mount_gradio_app(app, demo, path="/")
14
 
15
  if __name__ == "__main__":
16
  uvicorn.run(app, host="0.0.0.0", port=7860)
requirements.txt CHANGED
@@ -77,3 +77,6 @@ pytesseract
77
  python-barcode
78
  setuptools
79
  celery
 
 
 
 
77
  python-barcode
78
  setuptools
79
  celery
80
+ qrcode
81
+ sqlparse
82
+ xmltodict