Natwar commited on
Commit
eb8c64d
·
verified ·
1 Parent(s): b44bc34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -10,7 +10,7 @@ def install_package(package, version=None):
10
  print(f"Installing {package_spec}...")
11
  try:
12
  if package == "torch":
13
- # CPU-only build is ~200MB vs ~900MB for CUDA avoids disk quota errors
14
  subprocess.check_call([
15
  sys.executable, "-m", "pip", "install", "--no-cache-dir",
16
  "torch", "--index-url", "https://download.pytorch.org/whl/cpu"
@@ -24,14 +24,19 @@ def install_package(package, version=None):
24
  raise
25
 
26
 
27
- # Required packages
 
 
 
 
 
28
  required_packages = {
29
  "gradio": None,
30
  "torch": None,
31
- "transformers": None,
 
32
  }
33
 
34
- # Install missing packages using importlib (pkg_resources is deprecated)
35
  for package, version in required_packages.items():
36
  try:
37
  __import__(package)
@@ -92,7 +97,7 @@ def summarize_text(text, model_name, summary_length, num_beams):
92
 
93
  try:
94
  global summarizer
95
- # Reload pipeline only if the model has changed, always on CPU
96
  summarizer = pipeline("summarization", model=model_name, device=-1)
97
 
98
  length_mapping = {
 
10
  print(f"Installing {package_spec}...")
11
  try:
12
  if package == "torch":
13
+ # CPU-only build (~190MB) instead of CUDA (~900MB) to avoid disk quota errors
14
  subprocess.check_call([
15
  sys.executable, "-m", "pip", "install", "--no-cache-dir",
16
  "torch", "--index-url", "https://download.pytorch.org/whl/cpu"
 
24
  raise
25
 
26
 
27
+ # Required packages — ORDER MATTERS:
28
+ # tokenizers must be pinned before transformers so pip does not upgrade it.
29
+ # transformers 5.x dropped the "summarization" pipeline task entirely,
30
+ # so we pin to 4.46.3 (last v4 release) which still has it.
31
+ # tokenizers 0.21.3 is required by transformers 4.46.3 and has
32
+ # pre-built abi3 wheels that work on Python 3.13 without Rust compilation.
33
  required_packages = {
34
  "gradio": None,
35
  "torch": None,
36
+ "tokenizers": "0.21.3", # must come before transformers; abi3 wheel works on Py3.13
37
+ "transformers": "4.46.3", # last v4 release; still supports the summarization pipeline
38
  }
39
 
 
40
  for package, version in required_packages.items():
41
  try:
42
  __import__(package)
 
97
 
98
  try:
99
  global summarizer
100
+ # Reload pipeline on CPU whenever the model changes
101
  summarizer = pipeline("summarization", model=model_name, device=-1)
102
 
103
  length_mapping = {