File size: 3,400 Bytes
ecb8e64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597b4ab
 
 
ecb8e64
 
 
 
597b4ab
ecb8e64
597b4ab
 
 
ecb8e64
 
 
 
 
 
597b4ab
 
 
ecb8e64
 
 
 
 
597b4ab
 
 
 
 
 
 
 
 
ecb8e64
597b4ab
 
ecb8e64
 
 
 
597b4ab
 
ecb8e64
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/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)