#!/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)