Naveen-2007 commited on
Commit
0d541cd
·
1 Parent(s): 4351cdd

Fix backend URL for Hugging Face deployment, improve startup health check

Browse files
Files changed (2) hide show
  1. startup.sh +12 -2
  2. streamlit_app.py +2 -2
startup.sh CHANGED
@@ -1,13 +1,23 @@
1
  #!/bin/bash
2
  set -e
3
 
 
 
 
4
  echo "Starting FastAPI backend on port 8000..."
5
  uvicorn app.api:app --host 0.0.0.0 --port 8000 &
6
  BACKEND_PID=$!
7
 
8
- # Wait for backend to be ready
9
  echo "Waiting for backend to start..."
10
- sleep 10
 
 
 
 
 
 
 
11
 
12
  # Check if backend is running
13
  if ! kill -0 $BACKEND_PID 2>/dev/null; then
 
1
  #!/bin/bash
2
  set -e
3
 
4
+ # Export environment variables for the app
5
+ export BACKEND_URL="http://127.0.0.1:8000"
6
+
7
  echo "Starting FastAPI backend on port 8000..."
8
  uvicorn app.api:app --host 0.0.0.0 --port 8000 &
9
  BACKEND_PID=$!
10
 
11
+ # Wait for backend to be ready with health check
12
  echo "Waiting for backend to start..."
13
+ for i in {1..30}; do
14
+ if curl -s http://127.0.0.1:8000/health > /dev/null 2>&1; then
15
+ echo "Backend is healthy!"
16
+ break
17
+ fi
18
+ echo "Waiting... ($i/30)"
19
+ sleep 2
20
+ done
21
 
22
  # Check if backend is running
23
  if ! kill -0 $BACKEND_PID 2>/dev/null; then
streamlit_app.py CHANGED
@@ -38,8 +38,8 @@ if "product_ideas" not in st.session_state:
38
  # =====================================
39
  # CONFIGURATION
40
  # =====================================
41
- # Use environment variable for Azure deployment, fallback to localhost for local dev
42
- API_URL = os.getenv("BACKEND_URL", "http://localhost:8000")
43
  WORKSPACE = "default"
44
 
45
  # MODE MAPPING - All 8 modes with correct backend endpoints
 
38
  # =====================================
39
  # CONFIGURATION
40
  # =====================================
41
+ # For Hugging Face Spaces - backend runs internally on same container
42
+ API_URL = os.getenv("BACKEND_URL", "http://127.0.0.1:8000")
43
  WORKSPACE = "default"
44
 
45
  # MODE MAPPING - All 8 modes with correct backend endpoints