funcaptcha / install-onnx.py
doniramdani820's picture
Upload 12 files
597b4ab verified
#!/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)