sumitsingh830 commited on
Commit
58d5e14
·
verified ·
1 Parent(s): 10f8ce7

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +5 -5
  2. start.sh +19 -0
Dockerfile CHANGED
@@ -43,8 +43,9 @@ WORKDIR /app
43
  # Copy application code
44
  COPY app/ ./app/
45
  COPY server.py ./
46
- # Note: app.py exists but we use server.py as entry point
47
- # If app.py exists, it won't interfere since CMD specifies server:app
 
48
 
49
  # Create necessary directories
50
  RUN mkdir -p /app/models
@@ -56,8 +57,7 @@ EXPOSE 7860
56
  ENV PYTHONUNBUFFERED=1
57
  ENV SAM2_BUILD_CUDA=0
58
 
59
- # Run the FastAPI application
60
  # Hugging Face Spaces sets PORT environment variable automatically (usually 7860)
61
- # The application will listen on 0.0.0.0 to accept external connections
62
- CMD python -c "import os; port = int(os.environ.get('PORT', 7860)); import uvicorn; uvicorn.run('server:app', host='0.0.0.0', port=port, log_level='info')"
63
 
 
43
  # Copy application code
44
  COPY app/ ./app/
45
  COPY server.py ./
46
+ # Copy startup script
47
+ COPY start.sh ./start.sh
48
+ RUN chmod +x ./start.sh
49
 
50
  # Create necessary directories
51
  RUN mkdir -p /app/models
 
57
  ENV PYTHONUNBUFFERED=1
58
  ENV SAM2_BUILD_CUDA=0
59
 
60
+ # Run the FastAPI application using startup script
61
  # Hugging Face Spaces sets PORT environment variable automatically (usually 7860)
62
+ CMD ["./start.sh"]
 
63
 
start.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Get port from environment variable (Hugging Face Spaces sets this)
5
+ PORT=${PORT:-7860}
6
+
7
+ echo "Starting FastAPI application on port $PORT..."
8
+
9
+ # Verify critical imports before starting
10
+ echo "Verifying imports..."
11
+ python -c "import sys; sys.path.insert(0, '/app'); import server; print('✓ server.py imported successfully')" || {
12
+ echo "ERROR: Failed to import server.py"
13
+ exit 1
14
+ }
15
+
16
+ # Run the FastAPI application
17
+ echo "Starting uvicorn server..."
18
+ exec python -m uvicorn server:app --host 0.0.0.0 --port $PORT --log-level info
19
+