KarthikAI commited on
Commit
cdee956
·
verified ·
1 Parent(s): c418674

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +76 -21
Dockerfile CHANGED
@@ -1,7 +1,7 @@
1
  FROM python:3.10-slim
2
 
3
  # System dependencies
4
- RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
5
 
6
  WORKDIR /workspace
7
 
@@ -9,34 +9,89 @@ WORKDIR /workspace
9
  COPY requirements.txt .
10
  RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
11
 
12
- # Download models and adapters at build time
13
- # You can replace MODEL_ID or adapter repos as needed
 
14
 
15
- ENV CACHE_DIR="/data"
16
- ENV HF_HOME="/data"
17
- # ENV TRANSFORMERS_CACHE="/data"
18
- # ENV DEEPFACE_HOME="/data"
19
- # ENV INSIGHTFACE_HOME="/data/.insightface"
20
- RUN mkdir -p /data && \
21
- chmod -R 777 /data
22
 
23
- # -- Download Stable Diffusion v1-5 weights --
24
- # RUN python -c "from diffusers import StableDiffusionImg2ImgPipeline; StableDiffusionImg2ImgPipeline.from_pretrained('runwayml/stable-diffusion-v1-5', cache_dir='./models', torch_dtype='float32')"
25
- RUN python -c "import torch; from diffusers import StableDiffusionImg2ImgPipeline; StableDiffusionImg2ImgPipeline.from_pretrained('runwayml/stable-diffusion-v1-5', cache_dir='./models', torch_dtype=torch.float32)"
26
-
27
-
28
- RUN apt-get update && apt-get install -y wget
29
-
30
- # -- Download IP-Adapter weights (official Hugging Face repo) --
31
- RUN mkdir -p ./models/ip_adapter && \
32
- wget -O ./models/ip_adapter/ip-adapter_sd15.bin https://huggingface.co/h94/IP-Adapter/resolve/main/models/ip-adapter_sd15.bin
33
 
34
  # Copy app code
35
  COPY . .
36
 
37
- # Set environment (disable gradio analytics, useful for Spaces)
38
  ENV GRADIO_ANALYTICS_ENABLED="False"
39
 
40
  EXPOSE 7860
41
 
42
  CMD ["python", "app.py"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM python:3.10-slim
2
 
3
  # System dependencies
4
+ RUN apt-get update && apt-get install -y git wget && rm -rf /var/lib/apt/lists/*
5
 
6
  WORKDIR /workspace
7
 
 
9
  COPY requirements.txt .
10
  RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
11
 
12
+ # Set Hugging Face cache for all model downloads (best practice for Spaces)
13
+ ENV TRANSFORMERS_CACHE="/workspace/.cache/huggingface"
14
+ RUN mkdir -p /workspace/.cache/huggingface
15
 
16
+ # Pre-download Stable Diffusion v1-5 weights into cache
17
+ RUN python -c "import torch; from diffusers import StableDiffusionImg2ImgPipeline; StableDiffusionImg2ImgPipeline.from_pretrained('runwayml/stable-diffusion-v1-5', cache_dir='/workspace/.cache/huggingface', torch_dtype=torch.float32)"
 
 
 
 
 
18
 
19
+ # Pre-download IP-Adapter weights (if using)
20
+ RUN mkdir -p /workspace/.cache/huggingface/ip_adapter && \
21
+ wget -O /workspace/.cache/huggingface/ip_adapter/ip-adapter_sd15.bin https://huggingface.co/h94/IP-Adapter/resolve/main/models/ip-adapter_sd15.bin
 
 
 
 
 
 
 
22
 
23
  # Copy app code
24
  COPY . .
25
 
26
+ # Disable Gradio analytics (optional, but good for Spaces)
27
  ENV GRADIO_ANALYTICS_ENABLED="False"
28
 
29
  EXPOSE 7860
30
 
31
  CMD ["python", "app.py"]
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+ # FROM python:3.10-slim
41
+
42
+ # # System dependencies
43
+ # RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
44
+
45
+ # WORKDIR /workspace
46
+
47
+ # # Install Python dependencies
48
+ # COPY requirements.txt .
49
+ # RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
50
+
51
+ # # Download models and adapters at build time
52
+ # # You can replace MODEL_ID or adapter repos as needed
53
+
54
+ # ENV CACHE_DIR="/data"
55
+ # ENV HF_HOME="/data"
56
+ # # ENV TRANSFORMERS_CACHE="/data"
57
+ # # ENV DEEPFACE_HOME="/data"
58
+ # # ENV INSIGHTFACE_HOME="/data/.insightface"
59
+ # RUN mkdir -p /data && \
60
+ # chmod -R 777 /data
61
+
62
+ # # -- Download Stable Diffusion v1-5 weights --
63
+ # # RUN python -c "from diffusers import StableDiffusionImg2ImgPipeline; StableDiffusionImg2ImgPipeline.from_pretrained('runwayml/stable-diffusion-v1-5', cache_dir='./models', torch_dtype='float32')"
64
+ # RUN python -c "import torch; from diffusers import StableDiffusionImg2ImgPipeline; StableDiffusionImg2ImgPipeline.from_pretrained('runwayml/stable-diffusion-v1-5', cache_dir='./models', torch_dtype=torch.float32)"
65
+
66
+
67
+ # RUN apt-get update && apt-get install -y wget
68
+
69
+ # # -- Download IP-Adapter weights (official Hugging Face repo) --
70
+ # RUN mkdir -p ./models/ip_adapter && \
71
+ # wget -O ./models/ip_adapter/ip-adapter_sd15.bin https://huggingface.co/h94/IP-Adapter/resolve/main/models/ip-adapter_sd15.bin
72
+
73
+
74
+ # # Set Hugging Face cache for all model downloads (best practice for Spaces)
75
+ # ENV TRANSFORMERS_CACHE="/workspace/.cache/huggingface"
76
+ # RUN mkdir -p /workspace/.cache/huggingface && \
77
+ # chmod -R 777 /workspace
78
+
79
+ # # Pre-download Stable Diffusion v1-5 weights into cache
80
+ # RUN python -c "import torch; from diffusers import StableDiffusionImg2ImgPipeline; StableDiffusionImg2ImgPipeline.from_pretrained('runwayml/stable-diffusion-v1-5', cache_dir='/workspace/.cache/huggingface', torch_dtype=torch.float32)"
81
+
82
+ # # Pre-download IP-Adapter weights (if using)
83
+ # RUN mkdir -p /workspace/.cache/huggingface/ip_adapter && \
84
+ # wget -O /workspace/.cache/huggingface/ip_adapter/ip-adapter_sd15.bin https://huggingface.co/h94/IP-Adapter/resolve/main/models/ip-adapter_sd15.bin
85
+
86
+
87
+
88
+
89
+ # # Copy app code
90
+ # COPY . .
91
+
92
+ # # Set environment (disable gradio analytics, useful for Spaces)
93
+ # ENV GRADIO_ANALYTICS_ENABLED="False"
94
+
95
+ # EXPOSE 7860
96
+
97
+ # CMD ["python", "app.py"]