SAAHMATHWORKS commited on
Commit
afbbb2b
·
1 Parent(s): 20abbdd

path and import fix

Browse files
Files changed (2) hide show
  1. Dockerfile +17 -7
  2. app.py +20 -3
Dockerfile CHANGED
@@ -1,22 +1,32 @@
1
  FROM python:3.11-slim
2
 
 
3
  WORKDIR /app
4
 
 
 
 
5
  # Install system dependencies
6
- RUN apt-get update && apt-get install -y \
7
  gcc \
8
  curl \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
- # Copy requirements and install Python dependencies
12
  COPY requirements.txt .
13
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
14
 
15
  # Copy application code
16
  COPY . .
17
 
18
- # Create non-root user
19
- RUN useradd -m -u 1000 user
 
 
 
20
  USER user
21
 
22
  # Expose port (Hugging Face uses 7860)
@@ -26,5 +36,5 @@ EXPOSE 7860
26
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
27
  CMD curl -f http://localhost:7860/health || exit 1
28
 
29
- # Start command
30
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.11-slim
2
 
3
+ # Set working directory
4
  WORKDIR /app
5
 
6
+ # Set Python path to ensure imports work
7
+ ENV PYTHONPATH=/app:$PYTHONPATH
8
+
9
  # Install system dependencies
10
+ RUN apt-get update && apt-get install -y --no-install-recommends \
11
  gcc \
12
  curl \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
+ # Copy requirements first (better layer caching)
16
  COPY requirements.txt .
17
+
18
+ # Install Python dependencies
19
+ RUN pip install --no-cache-dir --upgrade pip && \
20
+ pip install --no-cache-dir -r requirements.txt
21
 
22
  # Copy application code
23
  COPY . .
24
 
25
+ # Create non-root user and set permissions
26
+ RUN useradd -m -u 1000 user && \
27
+ chown -R user:user /app
28
+
29
+ # Switch to non-root user
30
  USER user
31
 
32
  # Expose port (Hugging Face uses 7860)
 
36
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
37
  CMD curl -f http://localhost:7860/health || exit 1
38
 
39
+ # Start command - Use python to run app.py (which then starts uvicorn)
40
+ CMD ["python", "app.py"]
app.py CHANGED
@@ -1,7 +1,24 @@
1
- # app.py - Main entry point for Hugging Face Spaces
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from api.main import app
3
 
4
- # Hugging Face Spaces will automatically use this 'app' variable
5
  if __name__ == "__main__":
6
  import uvicorn
7
- uvicorn.run(app, host="0.0.0.0", port=7860) # HF uses port 7860
 
 
 
 
 
 
1
+ # app.py
2
+ import sys
3
+ import os
4
+ from pathlib import Path
5
+
6
+ # Add project root to Python path
7
+ project_root = Path(__file__).parent.absolute()
8
+ sys.path.insert(0, str(project_root))
9
+
10
+ print(f"✅ Working directory: {os.getcwd()}")
11
+ print(f"✅ Project root: {project_root}")
12
+ print(f"✅ Python path configured")
13
+
14
+ # Import FastAPI app
15
  from api.main import app
16
 
 
17
  if __name__ == "__main__":
18
  import uvicorn
19
+ uvicorn.run(
20
+ app,
21
+ host="0.0.0.0",
22
+ port=7860,
23
+ log_level="info"
24
+ )