Melika Kheirieh commited on
Commit
329daab
·
1 Parent(s): 4287d48

fix(runtime): use unified start.py to keep FastAPI & Gradio alive on HF

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. start.py +29 -0
Dockerfile CHANGED
@@ -53,4 +53,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
53
  EXPOSE 7860
54
 
55
  # Run both FastAPI (backend) and Gradio (frontend)
56
- CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port 8000 --proxy-headers --workers ${UVICORN_WORKERS:-1} & python -m demo.app"]
 
53
  EXPOSE 7860
54
 
55
  # Run both FastAPI (backend) and Gradio (frontend)
56
+ CMD ["python", "start.py"]
start.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import threading
3
+ import os
4
+
5
+
6
+ def run_fastapi():
7
+ subprocess.run(
8
+ [
9
+ "uvicorn",
10
+ "app.main:app",
11
+ "--host",
12
+ "0.0.0.0",
13
+ "--port",
14
+ "8000",
15
+ "--proxy-headers",
16
+ "--workers",
17
+ str(os.getenv("UVICORN_WORKERS", 1)),
18
+ ]
19
+ )
20
+
21
+
22
+ def run_gradio():
23
+ pass # noqa: just import to launch
24
+
25
+
26
+ if __name__ == "__main__":
27
+ t = threading.Thread(target=run_fastapi, daemon=True)
28
+ t.start()
29
+ run_gradio()