John Doe commited on
Commit
f30e3e5
·
1 Parent(s): 6c83666
Files changed (3) hide show
  1. Dockerfile +9 -4
  2. download_models.py +0 -6
  3. image_moderator.py +2 -2
Dockerfile CHANGED
@@ -1,13 +1,18 @@
1
- FROM python:3.9
 
2
 
 
3
  WORKDIR /app
4
 
 
5
  COPY requirements.txt .
6
- RUN pip install -r requirements.txt
7
 
 
8
  COPY . .
9
 
10
- # Download models at build time
11
- RUN python download_models.py
12
 
 
13
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use a slim Python image
2
+ FROM python:3.9-slim
3
 
4
+ # Set working directory
5
  WORKDIR /app
6
 
7
+ # Install dependencies
8
  COPY requirements.txt .
9
+ RUN pip install --no-cache-dir -r requirements.txt
10
 
11
+ # Copy app code and models
12
  COPY . .
13
 
14
+ # Expose the default port (Hugging Face uses 7860, but can be any port)
15
+ EXPOSE 7860
16
 
17
+ # Start uvicorn
18
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
download_models.py DELETED
@@ -1,6 +0,0 @@
1
- from transformers import pipeline
2
-
3
- # This will download and cache the model
4
- print("Downloading toxic-bert model...")
5
- _ = pipeline("text-classification", model="unitary/toxic-bert")
6
- print("Done.")
 
 
 
 
 
 
 
image_moderator.py CHANGED
@@ -66,9 +66,9 @@ class ImageContentModerator:
66
  return output_path
67
  from transformers import pipeline
68
  from better_profanity import profanity
69
- os.makedirs("./cache_dir", exist_ok=True)
70
  # Load profanity model
71
- toxic_classifier = pipeline("text-classification", model="unitary/toxic-bert", cache_dir="./cache_dir")
72
  profanity.load_censor_words()
73
  custom_words = [
74
  "idiot", "moron", "dumb", "stupid", "loser", "bastard", "retard", "scumbag",
 
66
  return output_path
67
  from transformers import pipeline
68
  from better_profanity import profanity
69
+
70
  # Load profanity model
71
+ pipeline("text-classification", model="unitary/toxic-bert").save_pretrained("./models/unitary-toxic-bert")
72
  profanity.load_censor_words()
73
  custom_words = [
74
  "idiot", "moron", "dumb", "stupid", "loser", "bastard", "retard", "scumbag",