-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
70 lines (60 loc) · 1.86 KB
/
Copy pathapp.py
File metadata and controls
70 lines (60 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
HuggingFace Spaces Docker entry point.
Starts FastAPI in background thread, then Streamlit on port 7860.
"""
import subprocess
import threading
import time
import sys
import os
os.environ["LANGCHAIN_TRACING_V2"] = "false"
os.environ["TOKENIZERS_PARALLELISM"] = "false"
os.environ["PYTHONUNBUFFERED"] = "1"
def start_fastapi():
import uvicorn
print("[API] Starting FastAPI on port 8000...")
try:
uvicorn.run(
"api.rag_api:app",
host="0.0.0.0",
port=8000,
log_level="warning"
)
except Exception as e:
print(f"[API] Error: {e}")
def wait_for_api(max_retries=40, delay=3):
import requests
print("[API] Waiting for FastAPI...")
for attempt in range(1, max_retries + 1):
try:
r = requests.get("http://localhost:8000/health", timeout=2)
if r.ok:
print(f"[API] Ready after {attempt} attempts")
return True
except Exception:
pass
print(f"[API] Attempt {attempt}/{max_retries}...")
time.sleep(delay)
print("[API] WARNING: Starting Streamlit anyway")
return False
if __name__ == "__main__":
print("=" * 50)
print("Enterprise RAG Platform — Starting")
print("=" * 50)
api_thread = threading.Thread(target=start_fastapi, daemon=True)
api_thread.start()
wait_for_api()
print("[UI] Starting Streamlit on port 7860...")
result = subprocess.run([
sys.executable, "-m", "streamlit", "run",
"ui/streamlit_app.py",
"--server.port=7860",
"--server.address=0.0.0.0",
"--server.headless=true",
"--server.fileWatcherType=none",
"--server.enableCORS=false",
"--server.enableXsrfProtection=false",
"--browser.gatherUsageStats=false",
"--logger.level=warning"
])
sys.exit(result.returncode)