akhaliq HF Staff commited on
Commit
4b46da9
Β·
1 Parent(s): 07a166f

Install exact torch/transformers pins at runtime in app.py to bypass build-time conflict

Browse files
Files changed (2) hide show
  1. app.py +22 -3
  2. requirements.txt +4 -8
app.py CHANGED
@@ -1,5 +1,24 @@
1
- import os
2
- import tempfile
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import torch
4
  from transformers import AutoModel, AutoTokenizer
5
  from gradio import Server
@@ -23,7 +42,7 @@ model = AutoModel.from_pretrained(
23
  torch_dtype=torch.bfloat16,
24
  )
25
  model = model.eval()
26
- print("Model loaded (on CPU β€” ZeroGPU will allocate GPU per request).")
27
 
28
  # ──────────────────────────────────────────────
29
  # App setup
 
1
+ import subprocess, sys, os, tempfile
2
+
3
+ # ──────────────────────────────────────────────────────────────────────────────
4
+ # Runtime install of exact model-required versions.
5
+ # Done here (not requirements.txt) to avoid a huggingface-hub version conflict
6
+ # between transformers==4.57.1 (<1.0) and gradio 6.x (>=1.2.0) at build time.
7
+ # ──────────────────────────────────────────────────────────────────────────────
8
+ _RUNTIME_PKGS = [
9
+ "torch==2.10.0",
10
+ "torchvision==0.25.0",
11
+ "transformers==4.57.1",
12
+ ]
13
+
14
+ print("Installing pinned runtime dependencies...")
15
+ subprocess.run(
16
+ [sys.executable, "-m", "pip", "install", "--quiet", "--no-cache-dir"] + _RUNTIME_PKGS,
17
+ check=True,
18
+ )
19
+ print("Runtime deps installed.")
20
+
21
+ # ── Now safe to import ────────────────────────────────────────────────────────
22
  import torch
23
  from transformers import AutoModel, AutoTokenizer
24
  from gradio import Server
 
42
  torch_dtype=torch.bfloat16,
43
  )
44
  model = model.eval()
45
+ print("Model loaded (on CPU β€” ZeroGPU allocates GPU per request).")
46
 
47
  # ──────────────────────────────────────────────
48
  # App setup
requirements.txt CHANGED
@@ -1,13 +1,9 @@
1
- # torch/torchvision β€” let the Space runtime supply a CUDA-compatible build
2
- torch
3
- torchvision
4
- # transformers β€” must be >=4.50 for Unlimited-OCR; leave upper bound open so
5
- # pip can pick a version whose huggingface-hub pin doesn't conflict with gradio
6
- transformers>=4.50.0
7
- Pillow>=10.0.0
8
  einops>=0.8.0
9
  addict>=2.4.0
10
  easydict>=1.13
11
  pymupdf>=1.27.0
12
  psutil>=5.9.0
13
- matplotlib>=3.7.0
 
1
+ # Build-time deps only β€” gradio-compatible, no transformers version conflict.
2
+ # The exact model-required versions are pip-installed at runtime in app.py.
3
+ matplotlib>=3.7.0
 
 
 
 
4
  einops>=0.8.0
5
  addict>=2.4.0
6
  easydict>=1.13
7
  pymupdf>=1.27.0
8
  psutil>=5.9.0
9
+ Pillow>=10.0.0