VietCat commited on
Commit
0673a12
·
1 Parent(s): 9f79fe4

fix build error

Browse files
Files changed (3) hide show
  1. Dockerfile +2 -2
  2. app.py +7 -0
  3. requirements.txt +4 -14
Dockerfile CHANGED
@@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
9
 
10
  # Install dependencies
11
  COPY requirements.txt .
12
- RUN pip install --no-cache-dir -r requirements.txt
13
 
14
  # Copy source code
15
  COPY app.py .
@@ -20,7 +20,7 @@ RUN mkdir -p /app/cache && chmod -R 777 /app/cache
20
  # Set env vars
21
  ENV HF_HOME=/app/cache \
22
  PYTHONUNBUFFERED=1 \
23
- PYTHONWARNINGS=ignore::FutureWarning
24
 
25
  EXPOSE 7860
26
 
 
9
 
10
  # Install dependencies
11
  COPY requirements.txt .
12
+ RUN pip cache purge && pip install --no-cache-dir -r requirements.txt
13
 
14
  # Copy source code
15
  COPY app.py .
 
20
  # Set env vars
21
  ENV HF_HOME=/app/cache \
22
  PYTHONUNBUFFERED=1 \
23
+ PYTHONWARNINGS=ignore::FutureWarning,ignore::UserWarning:torch._utils
24
 
25
  EXPOSE 7860
26
 
app.py CHANGED
@@ -1,4 +1,7 @@
1
  import os
 
 
 
2
  from transformers import GPT2LMHeadModel, GPT2Tokenizer
3
  import torch
4
  import gradio as gr
@@ -17,6 +20,10 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
  model.to(device)
18
  model.eval()
19
 
 
 
 
 
20
  def generate_text(prompt, max_length=100, temperature=1.0):
21
  try:
22
  inputs = tokenizer.encode(prompt, return_tensors="pt").to(device)
 
1
  import os
2
+ import warnings
3
+ warnings.filterwarnings("ignore", category=UserWarning, module="torch._utils")
4
+
5
  from transformers import GPT2LMHeadModel, GPT2Tokenizer
6
  import torch
7
  import gradio as gr
 
20
  model.to(device)
21
  model.eval()
22
 
23
+ # Print device and memory info for debugging
24
+ print(f"Device: {device}")
25
+ print(f"Memory allocated: {torch.cuda.memory_allocated(device)/1e9:.2f} GB" if torch.cuda.is_available() else "CPU only")
26
+
27
  def generate_text(prompt, max_length=100, temperature=1.0):
28
  try:
29
  inputs = tokenizer.encode(prompt, return_tensors="pt").to(device)
requirements.txt CHANGED
@@ -1,16 +1,6 @@
1
- # CPU-friendly PyTorch
2
- torch==2.1.2+cpu
3
- -f https://download.pytorch.org/whl/torch_stable.html
4
-
5
- # Transformers / Sentence Transformers
6
  transformers==4.40.0
7
- sentence-transformers==2.7.0
8
-
9
- # Gradio app
10
  gradio==4.44.1
11
- fastapi
12
- uvicorn
13
-
14
- # Tools
15
- pandas
16
- numpy
 
 
 
 
 
 
1
  transformers==4.40.0
2
+ torch==2.1.2
 
 
3
  gradio==4.44.1
4
+ fastapi==0.111.0
5
+ pydantic==2.7.1
6
+ numpy<2.0.0