Spaces:
Paused
Paused
| #!/usr/bin/env python3 | |
| """ | |
| π§ Aggressive ONNX Runtime Installer for HF Spaces | |
| Try multiple installation methods untuk bypass executable stack issues | |
| """ | |
| import subprocess | |
| import sys | |
| import os | |
| import shutil | |
| def run_command(cmd, ignore_errors=False): | |
| """Run command dengan error handling""" | |
| try: | |
| result = subprocess.run(cmd, shell=True, capture_output=True, text=True) | |
| if result.returncode == 0 or ignore_errors: | |
| print(f"β {cmd}") | |
| return True | |
| else: | |
| print(f"β {cmd}: {result.stderr}") | |
| return False | |
| except Exception as e: | |
| print(f"π₯ {cmd}: {e}") | |
| return False | |
| def test_onnx_import(): | |
| """Test jika ONNX Runtime bisa diimport""" | |
| try: | |
| import onnxruntime as ort | |
| print(f"β ONNX Runtime {ort.__version__} imported successfully") | |
| return True | |
| except Exception as e: | |
| print(f"β ONNX Runtime import failed: {e}") | |
| return False | |
| def main(): | |
| """Try multiple ONNX Runtime installation approaches""" | |
| print("π Starting aggressive ONNX Runtime installation...") | |
| # Method 1: Try latest available onnxruntime | |
| print("\nπ Method 1: Latest available onnxruntime") | |
| if run_command("pip install onnxruntime==1.22.1"): | |
| if test_onnx_import(): | |
| print("π Method 1 SUCCESS!") | |
| return True | |
| else: | |
| run_command("pip uninstall -y onnxruntime", ignore_errors=True) | |
| # Method 2: Try stable version | |
| print("\nπ Method 2: Stable onnxruntime") | |
| if run_command("pip install onnxruntime==1.20.1"): | |
| if test_onnx_import(): | |
| print("π Method 2 SUCCESS!") | |
| return True | |
| else: | |
| run_command("pip uninstall -y onnxruntime", ignore_errors=True) | |
| # Method 3: Try minimum available version | |
| print("\nπ Method 3: Minimum available onnxruntime") | |
| if run_command("pip install onnxruntime==1.15.1"): | |
| if test_onnx_import(): | |
| print("π Method 3 SUCCESS!") | |
| return True | |
| else: | |
| run_command("pip uninstall -y onnxruntime", ignore_errors=True) | |
| # Method 4: Try alternative OpenVino build | |
| print("\nπ Method 4: OpenVino alternative build") | |
| if run_command("pip install onnxruntime-openvino==1.22.0"): | |
| if test_onnx_import(): | |
| print("π Method 4 SUCCESS!") | |
| return True | |
| else: | |
| run_command("pip uninstall -y onnxruntime-openvino", ignore_errors=True) | |
| # Method 5: Try CPU-only PyTorch instead | |
| print("\nπ Method 5: PyTorch CPU-only alternative") | |
| if run_command("pip install torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/cpu"): | |
| print("β PyTorch installed as ONNX Runtime alternative") | |
| return True | |
| # Method 6: Try TensorFlow Lite | |
| print("\nπ Method 6: TensorFlow Lite alternative") | |
| if run_command("pip install tensorflow==2.13.0"): | |
| print("β TensorFlow installed as ONNX Runtime alternative") | |
| return True | |
| print("β All ONNX Runtime installation methods failed!") | |
| print("β οΈ App will run dalam degraded mode") | |
| return False | |
| if __name__ == "__main__": | |
| success = main() | |
| sys.exit(0 if success else 1) | |