yuni0725 commited on
Commit
f80395f
Β·
1 Parent(s): 16b19c9
Files changed (2) hide show
  1. Dockerfile +7 -6
  2. main.py +9 -2
Dockerfile CHANGED
@@ -3,16 +3,17 @@ FROM python:3.11-slim
3
  WORKDIR /app
4
 
5
  ENV TRANSFORMERS_CACHE=/app/cache
 
6
 
7
- COPY requirements.txt .
 
 
8
 
9
- RUN pip install --no-cache-dir -r requirements.txt
10
 
11
- COPY main.py .
 
12
 
13
- # μΊμ‹œ 디렉토리 생성
14
- RUN mkdir -p /app/cache
15
 
16
  EXPOSE 7860
17
-
18
  CMD ["python", "main.py"]
 
3
  WORKDIR /app
4
 
5
  ENV TRANSFORMERS_CACHE=/app/cache
6
+ ENV HF_HOME=/app/hf_home
7
 
8
+ # μΊμ‹œ 폴더 생성 + κΆŒν•œ λΆ€μ—¬
9
+ RUN mkdir -p /app/cache && chmod -R 777 /app/cache
10
+ RUN mkdir -p /app/hf_home && chmod -R 777 /app/hf_home
11
 
 
12
 
13
+ COPY requirements.txt .
14
+ RUN pip install -r requirements.txt
15
 
16
+ COPY main.py .
 
17
 
18
  EXPOSE 7860
 
19
  CMD ["python", "main.py"]
main.py CHANGED
@@ -4,6 +4,9 @@ import os
4
 
5
  local_path = "./models/roberta-large"
6
 
 
 
 
7
  model_id = "klue/roberta-large"
8
 
9
  if os.path.exists(local_path):
@@ -12,14 +15,18 @@ if os.path.exists(local_path):
12
  tokenizer = AutoTokenizer.from_pretrained(local_path)
13
  else:
14
  print("⬇️ λͺ¨λΈ ν—ˆκΉ…νŽ˜μ΄μŠ€μ—μ„œ λ‹€μš΄λ‘œλ“œ 쀑...")
15
- model = AutoModelForSequenceClassification.from_pretrained(model_id)
16
- tokenizer = AutoTokenizer.from_pretrained(model_id)
 
 
17
  os.makedirs(local_path, exist_ok=True)
18
  model.save_pretrained(local_path)
19
  tokenizer.save_pretrained(local_path)
20
 
21
  app = Flask(__name__)
22
 
 
 
23
 
24
  @app.route("/generate", methods=["POST"])
25
  def generate():
 
4
 
5
  local_path = "./models/roberta-large"
6
 
7
+ os.environ["HF_HOME"] = "/app/hf_home"
8
+ os.environ["TRANSFORMERS_CACHE"] = "/app/cache" # 병행 μ‚¬μš© κ°€λŠ₯
9
+
10
  model_id = "klue/roberta-large"
11
 
12
  if os.path.exists(local_path):
 
15
  tokenizer = AutoTokenizer.from_pretrained(local_path)
16
  else:
17
  print("⬇️ λͺ¨λΈ ν—ˆκΉ…νŽ˜μ΄μŠ€μ—μ„œ λ‹€μš΄λ‘œλ“œ 쀑...")
18
+ model = AutoModelForSequenceClassification.from_pretrained(
19
+ model_id, cache_dir=os.environ["HF_HOME"]
20
+ )
21
+ tokenizer = AutoTokenizer.from_pretrained(model_id, cache_dir=os.environ["HF_HOME"])
22
  os.makedirs(local_path, exist_ok=True)
23
  model.save_pretrained(local_path)
24
  tokenizer.save_pretrained(local_path)
25
 
26
  app = Flask(__name__)
27
 
28
+ print("πŸ”„ λͺ¨λΈ λ‘œλ“œ μ™„λ£Œ")
29
+
30
 
31
  @app.route("/generate", methods=["POST"])
32
  def generate():