Spaces:
Sleeping
Sleeping
Commit
·
8f660ce
1
Parent(s):
f38a4b7
Update app.py with numexpr patch (backup fix)
Browse files
app.py
CHANGED
|
@@ -1,7 +1,30 @@
|
|
| 1 |
-
# Fix HuggingFace Spaces
|
| 2 |
import os
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# import libraries
|
| 7 |
import pandas as pd
|
|
|
|
| 1 |
+
# Fix HuggingFace Spaces OMP_NUM_THREADS issue by patching numexpr
|
| 2 |
import os
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
# Patch numexpr before it gets imported
|
| 6 |
+
try:
|
| 7 |
+
import site
|
| 8 |
+
for site_dir in site.getsitepackages():
|
| 9 |
+
numexpr_utils = os.path.join(site_dir, 'numexpr', 'utils.py')
|
| 10 |
+
if os.path.exists(numexpr_utils):
|
| 11 |
+
with open(numexpr_utils, 'r') as f:
|
| 12 |
+
content = f.read()
|
| 13 |
+
|
| 14 |
+
old_code = "requested_threads = int(os.environ['OMP_NUM_THREADS'])"
|
| 15 |
+
new_code = """try:
|
| 16 |
+
requested_threads = int(os.environ['OMP_NUM_THREADS'])
|
| 17 |
+
except (ValueError, TypeError):
|
| 18 |
+
requested_threads = 4"""
|
| 19 |
+
|
| 20 |
+
if old_code in content and new_code not in content:
|
| 21 |
+
content = content.replace(old_code, new_code)
|
| 22 |
+
with open(numexpr_utils, 'w') as f:
|
| 23 |
+
f.write(content)
|
| 24 |
+
print("✅ Patched numexpr for HuggingFace Spaces")
|
| 25 |
+
break
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"Note: Could not patch numexpr: {e}")
|
| 28 |
|
| 29 |
# import libraries
|
| 30 |
import pandas as pd
|