Spaces:
Sleeping
Sleeping
Abubakar740 commited on
Commit ·
da636fb
1
Parent(s): bd5df39
update dockerfile
Browse files- Dockerfile +12 -8
- main.py +10 -0
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# Use an official Python runtime
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
# Set environment variables
|
|
@@ -6,30 +6,34 @@ ENV PYTHONDONTWRITEBYTECODE=1
|
|
| 6 |
ENV PYTHONUNBUFFERED=1
|
| 7 |
ENV HOME=/home/user
|
| 8 |
|
| 9 |
-
# Install system dependencies
|
|
|
|
| 10 |
RUN apt-get update && apt-get install -y \
|
| 11 |
-
libgl1
|
| 12 |
libglib2.0-0 \
|
| 13 |
ffmpeg \
|
|
|
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
|
| 16 |
-
# Create a non-root user
|
| 17 |
RUN useradd -m -u 1000 user
|
| 18 |
USER user
|
|
|
|
| 19 |
WORKDIR $HOME/app
|
| 20 |
|
| 21 |
# Copy requirements and install
|
| 22 |
COPY --chown=user requirements.txt .
|
| 23 |
-
RUN pip install --no-cache-dir --upgrade
|
|
|
|
| 24 |
|
| 25 |
# Copy the rest of the application code
|
| 26 |
COPY --chown=user . .
|
| 27 |
|
| 28 |
-
# Create
|
| 29 |
RUN mkdir -p uploads outputs && chmod 777 uploads outputs
|
| 30 |
|
| 31 |
-
# Expose port
|
| 32 |
EXPOSE 7860
|
| 33 |
|
| 34 |
-
#
|
| 35 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Use an official Python runtime
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
# Set environment variables
|
|
|
|
| 6 |
ENV PYTHONUNBUFFERED=1
|
| 7 |
ENV HOME=/home/user
|
| 8 |
|
| 9 |
+
# Install system dependencies
|
| 10 |
+
# We use libgl1 instead of libgl1-mesa-glx for newer Debian compatibility
|
| 11 |
RUN apt-get update && apt-get install -y \
|
| 12 |
+
libgl1 \
|
| 13 |
libglib2.0-0 \
|
| 14 |
ffmpeg \
|
| 15 |
+
procps \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
+
# Create a non-root user (Required by Hugging Face)
|
| 19 |
RUN useradd -m -u 1000 user
|
| 20 |
USER user
|
| 21 |
+
ENV PATH="/home/user/.local/bin:${PATH}"
|
| 22 |
WORKDIR $HOME/app
|
| 23 |
|
| 24 |
# Copy requirements and install
|
| 25 |
COPY --chown=user requirements.txt .
|
| 26 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 27 |
+
pip install --no-cache-dir -r requirements.txt
|
| 28 |
|
| 29 |
# Copy the rest of the application code
|
| 30 |
COPY --chown=user . .
|
| 31 |
|
| 32 |
+
# Create storage directories and ensure they are writable
|
| 33 |
RUN mkdir -p uploads outputs && chmod 777 uploads outputs
|
| 34 |
|
| 35 |
+
# Expose the port HF expects
|
| 36 |
EXPOSE 7860
|
| 37 |
|
| 38 |
+
# Start the FastAPI app
|
| 39 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
CHANGED
|
@@ -12,6 +12,16 @@ from ultralytics import YOLO
|
|
| 12 |
|
| 13 |
app = FastAPI()
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# --- CONFIG & GLOBALS ---
|
| 16 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 17 |
MODEL_PATH = "best_slowfast_theft.pth"
|
|
|
|
| 12 |
|
| 13 |
app = FastAPI()
|
| 14 |
|
| 15 |
+
|
| 16 |
+
# Create absolute paths based on the app directory
|
| 17 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 18 |
+
UPLOAD_DIR = os.path.join(BASE_DIR, "uploads")
|
| 19 |
+
OUTPUT_DIR = os.path.join(BASE_DIR, "outputs")
|
| 20 |
+
|
| 21 |
+
# Ensure they exist (as a backup)
|
| 22 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 23 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 24 |
+
|
| 25 |
# --- CONFIG & GLOBALS ---
|
| 26 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 27 |
MODEL_PATH = "best_slowfast_theft.pth"
|