Nebulixlabs commited on
Commit
7530207
·
verified ·
1 Parent(s): 91df2c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -16,16 +16,27 @@ import bm25s
16
  import aiohttp
17
  from bs4 import BeautifulSoup
18
 
19
- # 🔥 CRITICAL HOTFIX FOR HUGGING FACE SPACES
20
- # Bypasses the Optimum crash with the latest Transformers version natively on Python 3.13
 
 
21
  import transformers.utils
22
  import transformers.utils.import_utils
23
- for mod in [transformers.utils, transformers.utils.import_utils]:
24
- if not hasattr(mod, 'is_tf_available'):
25
- mod.is_tf_available = lambda: False
26
- if not hasattr(mod, 'is_torch_available'):
27
- mod.is_torch_available = lambda: True
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  from transformers import AutoTokenizer, pipeline
30
  from optimum.onnxruntime import ORTModelForCausalLM
31
  import onnxruntime as ort
 
16
  import aiohttp
17
  from bs4 import BeautifulSoup
18
 
19
+ # 🔥 COMPREHENSIVE HOTFIX FOR HUGGING FACE SPACES / OPTIMUM
20
+ # The new Transformers library removed TensorFlow checks, but Optimum still looks for them.
21
+ # We inject these functions into the root namespace BEFORE Optimum imports them.
22
+ import transformers
23
  import transformers.utils
24
  import transformers.utils.import_utils
 
 
 
 
 
25
 
26
+ def _is_false(): return False
27
+ def _is_true(): return True
28
+
29
+ # Patch the Root Namespace
30
+ transformers.is_tf_available = _is_false
31
+ transformers.is_torch_available = _is_true
32
+ # Patch the Utils Namespace
33
+ transformers.utils.is_tf_available = _is_false
34
+ transformers.utils.is_torch_available = _is_true
35
+ # Patch the Import Utils Namespace
36
+ transformers.utils.import_utils.is_tf_available = _is_false
37
+ transformers.utils.import_utils.is_torch_available = _is_true
38
+
39
+ # NOW it is safe to import optimum
40
  from transformers import AutoTokenizer, pipeline
41
  from optimum.onnxruntime import ORTModelForCausalLM
42
  import onnxruntime as ort