Chinnatip Taemkaeo commited on
Commit
70af803
·
1 Parent(s): 939ef3b

fix path of cache model

Browse files
Files changed (3) hide show
  1. Dockerfile +8 -1
  2. download_model.py +5 -0
  3. interface.py +5 -0
Dockerfile CHANGED
@@ -1,11 +1,18 @@
1
  # ใช้ Python base image
2
  FROM python:3.9-slim
3
 
 
 
 
 
4
  # ติดตั้ง dependencies
5
  WORKDIR /app
6
  COPY requirements.txt .
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
 
 
 
9
  # โหลดโมเดลล่วงหน้า
10
  COPY download_model.py .
11
  RUN python download_model.py
@@ -16,5 +23,5 @@ COPY . .
16
  # เปิดพอร์ต 7860 สำหรับ Gradio
17
  EXPOSE 7860
18
 
19
- # คำสั่งรัน FastAPI หรือ Gradio
20
  CMD ["python", "interface.py"]
 
1
  # ใช้ Python base image
2
  FROM python:3.9-slim
3
 
4
+ # ตั้งค่า cache location ให้ transformers
5
+ ENV HF_HOME=/app/cache
6
+ ENV TRANSFORMERS_CACHE=/app/cache
7
+
8
  # ติดตั้ง dependencies
9
  WORKDIR /app
10
  COPY requirements.txt .
11
  RUN pip install --no-cache-dir -r requirements.txt
12
 
13
+ # สร้างโฟลเดอร์ cache และให้สิทธิ์เขียน
14
+ RUN mkdir -p /app/cache && chmod -R 777 /app/cache
15
+
16
  # โหลดโมเดลล่วงหน้า
17
  COPY download_model.py .
18
  RUN python download_model.py
 
23
  # เปิดพอร์ต 7860 สำหรับ Gradio
24
  EXPOSE 7860
25
 
26
+ # คำสั่งรัน Gradio
27
  CMD ["python", "interface.py"]
download_model.py CHANGED
@@ -1,5 +1,10 @@
 
1
  from transformers import pipeline
2
 
 
 
 
 
3
  print("Downloading pre-trained model...")
4
  classifier = pipeline("audio-classification", model="AmeerHesham/distilhubert-finetuned-baby_cry")
5
  print("Model downloaded successfully!")
 
1
+ import os
2
  from transformers import pipeline
3
 
4
+ # กำหนดค่า cache ให้ transformers และ huggingface_hub
5
+ os.environ["HF_HOME"] = "/app/cache"
6
+ os.environ["TRANSFORMERS_CACHE"] = "/app/cache"
7
+
8
  print("Downloading pre-trained model...")
9
  classifier = pipeline("audio-classification", model="AmeerHesham/distilhubert-finetuned-baby_cry")
10
  print("Model downloaded successfully!")
interface.py CHANGED
@@ -1,7 +1,12 @@
 
1
  import gradio as gr
2
  from transformers import pipeline
3
  import tempfile
4
 
 
 
 
 
5
  # โหลดโมเดลล่วงหน้า
6
  classifier = pipeline("audio-classification",
7
  model="AmeerHesham/distilhubert-finetuned-baby_cry",
 
1
+ import os
2
  import gradio as gr
3
  from transformers import pipeline
4
  import tempfile
5
 
6
+ # กำหนดค่า cache location ให้ transformers
7
+ os.environ["HF_HOME"] = "/app/cache"
8
+ os.environ["TRANSFORMERS_CACHE"] = "/app/cache"
9
+
10
  # โหลดโมเดลล่วงหน้า
11
  classifier = pipeline("audio-classification",
12
  model="AmeerHesham/distilhubert-finetuned-baby_cry",