SeaWolf-AI commited on
Commit
5c1be4f
·
verified ·
1 Parent(s): 4a5da45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -11,11 +11,23 @@ from collections.abc import Iterator
11
  from pathlib import Path
12
  from threading import Thread
13
 
14
- # Install pre-built transformers wheel (HF Spaces can't pip-install local wheel paths)
15
- if os.getenv("SPACE_ID"):
16
- _whl = Path(__file__).parent / "transformers-5.5.0.dev0-py3-none-any.whl"
17
- if _whl.exists():
 
 
 
 
18
  subprocess.check_call([sys.executable, "-m", "pip", "install", str(_whl)])
 
 
 
 
 
 
 
 
19
 
20
  import urllib3
21
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
 
11
  from pathlib import Path
12
  from threading import Thread
13
 
14
+ # Install pre-built transformers wheel BEFORE importing transformers
15
+ _app_dir = Path(__file__).parent
16
+ _whls = sorted(_app_dir.glob("transformers*.whl"))
17
+ _installed = False
18
+ if _whls:
19
+ _whl = _whls[0]
20
+ print(f"[BOOT] Installing wheel: {_whl.name}", flush=True)
21
+ try:
22
  subprocess.check_call([sys.executable, "-m", "pip", "install", str(_whl)])
23
+ _installed = True
24
+ print("[BOOT] ✓ Wheel installed", flush=True)
25
+ except subprocess.CalledProcessError as e:
26
+ print(f"[BOOT] ⚠ Wheel install failed ({e}), falling back to PyPI", flush=True)
27
+
28
+ if not _installed:
29
+ print("[BOOT] Installing transformers from PyPI...", flush=True)
30
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "transformers>=4.49"])
31
 
32
  import urllib3
33
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)