Spaces:
Running
Running
update docker files for deploying to spaces
Browse files- .github/workflows/sync-to-hugging-face-hub.yml +0 -1
- Dockerfile +8 -8
- docker-compose.yml +3 -3
- helper.py +4 -2
.github/workflows/sync-to-hugging-face-hub.yml
CHANGED
@@ -23,5 +23,4 @@ jobs:
|
|
23 |
- name: Push to hub
|
24 |
env:
|
25 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
26 |
-
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
|
27 |
run: git push https://Prgrmmer:$HF_TOKEN@huggingface.co/spaces/Prgrmmer/ai-dungeon main
|
|
|
23 |
- name: Push to hub
|
24 |
env:
|
25 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
|
|
26 |
run: git push https://Prgrmmer:$HF_TOKEN@huggingface.co/spaces/Prgrmmer/ai-dungeon main
|
Dockerfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
FROM python:3.10-slim
|
2 |
|
3 |
# Add build argument
|
4 |
-
ARG HUGGINGFACE_API_KEY
|
5 |
ENV HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY}
|
6 |
|
7 |
# System dependencies
|
@@ -22,17 +22,17 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
22 |
COPY . .
|
23 |
|
24 |
# # Environment variables
|
25 |
-
|
26 |
# ENV HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY}
|
27 |
|
28 |
# HuggingFace login at container startup
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
RUN mkdir -p ~/.huggingface && \
|
34 |
-
|
35 |
-
|
36 |
|
37 |
# Expose port
|
38 |
EXPOSE 7860
|
|
|
1 |
FROM python:3.10-slim
|
2 |
|
3 |
# Add build argument
|
4 |
+
# ARG HUGGINGFACE_API_KEY
|
5 |
ENV HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY}
|
6 |
|
7 |
# System dependencies
|
|
|
22 |
COPY . .
|
23 |
|
24 |
# # Environment variables
|
25 |
+
ENV PYTHONUNBUFFERED=1
|
26 |
# ENV HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY}
|
27 |
|
28 |
# HuggingFace login at container startup
|
29 |
+
RUN --mount=type=secret,id=HUGGINGFACE_API_KEY \
|
30 |
+
HUGGINGFACE_API_KEY=$(cat /run/secrets/HUGGINGFACE_API_KEY) && \
|
31 |
+
huggingface-cli login --token $HUGGINGFACE_API_KEY
|
32 |
|
33 |
+
# RUN mkdir -p ~/.huggingface && \
|
34 |
+
# echo "${HUGGINGFACE_API_KEY}" > ~/.huggingface/token && \
|
35 |
+
# huggingface-cli login --token ${HUGGINGFACE_API_KEY}
|
36 |
|
37 |
# Expose port
|
38 |
EXPOSE 7860
|
docker-compose.yml
CHANGED
@@ -3,12 +3,12 @@ services:
|
|
3 |
ai-dungeon:
|
4 |
build:
|
5 |
context: .
|
6 |
-
args:
|
7 |
-
|
8 |
ports:
|
9 |
- "7860:7860"
|
10 |
environment:
|
11 |
-
|
12 |
- HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY}
|
13 |
secrets:
|
14 |
- hf_token
|
|
|
3 |
ai-dungeon:
|
4 |
build:
|
5 |
context: .
|
6 |
+
# args:
|
7 |
+
# - HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY}
|
8 |
ports:
|
9 |
- "7860:7860"
|
10 |
environment:
|
11 |
+
- PYTHONUNBUFFERED=1
|
12 |
- HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY}
|
13 |
secrets:
|
14 |
- hf_token
|
helper.py
CHANGED
@@ -67,6 +67,8 @@ def initialize_model_pipeline(model_name, force_cpu=False):
|
|
67 |
else:
|
68 |
device = MODEL_CONFIG["main_model"]["device"]
|
69 |
|
|
|
|
|
70 |
# Use 8-bit quantization for memory efficiency
|
71 |
model = AutoModelForCausalLM.from_pretrained(
|
72 |
model_name,
|
@@ -75,6 +77,8 @@ def initialize_model_pipeline(model_name, force_cpu=False):
|
|
75 |
use_cache=True,
|
76 |
device_map="auto",
|
77 |
low_cpu_mem_usage=True,
|
|
|
|
|
78 |
)
|
79 |
|
80 |
model.config.use_cache = True
|
@@ -114,8 +118,6 @@ try:
|
|
114 |
|
115 |
model_name = MODEL_CONFIG["main_model"]["name"]
|
116 |
|
117 |
-
api_key = get_huggingface_api_key()
|
118 |
-
|
119 |
# Initialize the pipeline with memory management
|
120 |
generator, tokenizer = initialize_model_pipeline(model_name)
|
121 |
|
|
|
67 |
else:
|
68 |
device = MODEL_CONFIG["main_model"]["device"]
|
69 |
|
70 |
+
api_key = get_huggingface_api_key()
|
71 |
+
|
72 |
# Use 8-bit quantization for memory efficiency
|
73 |
model = AutoModelForCausalLM.from_pretrained(
|
74 |
model_name,
|
|
|
77 |
use_cache=True,
|
78 |
device_map="auto",
|
79 |
low_cpu_mem_usage=True,
|
80 |
+
trust_remote_code=True,
|
81 |
+
token=api_key, # Add token here
|
82 |
)
|
83 |
|
84 |
model.config.use_cache = True
|
|
|
118 |
|
119 |
model_name = MODEL_CONFIG["main_model"]["name"]
|
120 |
|
|
|
|
|
121 |
# Initialize the pipeline with memory management
|
122 |
generator, tokenizer = initialize_model_pipeline(model_name)
|
123 |
|