mwtuni commited on
Commit
042968a
·
1 Parent(s): f52eb8e

now works locally in docker

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -12
  2. app.py +6 -10
  3. build.sh +13 -8
Dockerfile CHANGED
@@ -3,26 +3,21 @@ FROM python:3.10-slim
3
  ENV PYTHONUNBUFFERED=1 \
4
  PIP_NO_CACHE_DIR=1
5
 
6
- # Install only the required system packages
7
  RUN apt-get update && apt-get install -y --no-install-recommends \
8
- ffmpeg \
9
- libsm6 \
10
- libxext6 \
11
- libgl1 \
12
- git \
13
- git-lfs \
14
  && rm -rf /var/lib/apt/lists/* \
15
  && git lfs install
16
 
17
  WORKDIR /app
18
 
19
- # Install Python deps first (better caching)
20
  COPY requirements.txt .
21
- RUN pip install --upgrade pip \
22
- && pip install -r requirements.txt \
23
- && pip install "gradio[oauth,mcp]==6.0.1" uvicorn spaces
24
 
25
- # Copy the rest of the app
26
  COPY . .
27
 
28
  EXPOSE 7860
 
3
  ENV PYTHONUNBUFFERED=1 \
4
  PIP_NO_CACHE_DIR=1
5
 
6
+ # System deps
7
  RUN apt-get update && apt-get install -y --no-install-recommends \
8
+ ffmpeg libsm6 libxext6 libgl1 git git-lfs \
 
 
 
 
 
9
  && rm -rf /var/lib/apt/lists/* \
10
  && git lfs install
11
 
12
  WORKDIR /app
13
 
14
+ # ---------- Cache heavy PIP layer ----------
15
  COPY requirements.txt .
16
+ RUN pip install --upgrade pip && \
17
+ pip install -r requirements.txt && \
18
+ pip install "gradio[oauth,mcp]==6.0.1" uvicorn spaces
19
 
20
+ # ---------- Only copy app code ----------
21
  COPY . .
22
 
23
  EXPOSE 7860
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import json
2
  from pathlib import Path
3
  from datetime import datetime
@@ -449,24 +450,20 @@ with gr.Blocks() as ui:
449
  outputs=file_status,
450
  )
451
 
452
-
453
  # ----------------------------------------------------
454
  # Export ASGI app for Hugging Face Spaces
455
  # ----------------------------------------------------
456
-
457
- app = gr.mount_gradio_app(fastapi_app, ui, path="/")
458
-
459
- # ----------------------------------------------------
460
- # Export ASGI app for Hugging Face Spaces
461
  # ----------------------------------------------------
462
 
463
- app = gr.mount_gradio_app(fastapi_app, ui, path="/")
 
464
 
465
  # ----------------------------------------------------
466
  # Local & Docker run mode
467
  # ----------------------------------------------------
468
- # HF Spaces sets SPACE_ID — we MUST NOT run uvicorn there,
469
- # but in local/docker we MUST run uvicorn so the process does not exit.
470
  # ----------------------------------------------------
471
 
472
  if __name__ == "__main__" and not os.getenv("SPACE_ID"):
@@ -474,4 +471,3 @@ if __name__ == "__main__" and not os.getenv("SPACE_ID"):
474
  port = int(os.getenv("PORT", "7860"))
475
  print(f"Starting local uvicorn server on port {port}...")
476
  uvicorn.run(app, host="0.0.0.0", port=port)
477
-
 
1
+ import os
2
  import json
3
  from pathlib import Path
4
  from datetime import datetime
 
450
  outputs=file_status,
451
  )
452
 
 
453
  # ----------------------------------------------------
454
  # Export ASGI app for Hugging Face Spaces
455
  # ----------------------------------------------------
456
+ # Mount Gradio UI at /ui so FastAPI "/" stays alive
 
 
 
 
457
  # ----------------------------------------------------
458
 
459
+ app = gr.mount_gradio_app(fastapi_app, ui, path="/ui")
460
+
461
 
462
  # ----------------------------------------------------
463
  # Local & Docker run mode
464
  # ----------------------------------------------------
465
+ # HF Spaces sets SPACE_ID — DO NOT run uvicorn in HF.
466
+ # For local / Docker usage, run uvicorn manually.
467
  # ----------------------------------------------------
468
 
469
  if __name__ == "__main__" and not os.getenv("SPACE_ID"):
 
471
  port = int(os.getenv("PORT", "7860"))
472
  print(f"Starting local uvicorn server on port {port}...")
473
  uvicorn.run(app, host="0.0.0.0", port=port)
 
build.sh CHANGED
@@ -3,18 +3,23 @@ set -e
3
 
4
  IMAGE_NAME="avatar-mcp"
5
 
6
- echo "🧹 Removing old containers..."
7
- docker ps -a --filter "ancestor=$IMAGE_NAME" --format "{{.ID}}" | xargs -r docker rm -f
 
 
 
 
 
 
8
 
9
- echo "🧹 Removing old image..."
10
- docker images --filter "reference=$IMAGE_NAME" --format "{{.ID}}" | xargs -r docker rmi -f
11
-
12
- echo "📦 Building new image..."
13
- docker build -t $IMAGE_NAME .
14
 
15
  echo "📏 Image size:"
16
  docker images | grep $IMAGE_NAME
17
 
18
  # Uncomment to run locally:
19
  # echo "🚀 Starting container on http://localhost:7860 ..."
20
- # docker run -p 7860:7860 avatar-mcp
 
3
 
4
  IMAGE_NAME="avatar-mcp"
5
 
6
+ if [[ "$1" == "clean" ]]; then
7
+ echo "🧹 CLEAN build requested removing image & containers..."
8
+ docker ps -a --filter "ancestor=$IMAGE_NAME" --format "{{.ID}}" | xargs -r docker rm -f
9
+ docker images --filter "reference=$IMAGE_NAME" --format "{{.ID}}" | xargs -r docker rmi -f
10
+ else
11
+ echo "🛑 Removing old containers only..."
12
+ docker ps -a --filter "ancestor=$IMAGE_NAME" --format "{{.ID}}" | xargs -r docker rm -f
13
+ fi
14
 
15
+ echo "📦 Building image with cache…"
16
+ docker build \
17
+ --cache-from=$IMAGE_NAME \
18
+ -t $IMAGE_NAME .
 
19
 
20
  echo "📏 Image size:"
21
  docker images | grep $IMAGE_NAME
22
 
23
  # Uncomment to run locally:
24
  # echo "🚀 Starting container on http://localhost:7860 ..."
25
+ # docker run -p 7860:7860 $IMAGE_NAME