Spaces:
Paused
Paused
File size: 3,704 Bytes
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | #!/usr/bin/env python3
"""
π Package Version Checker for HF Spaces Deployment
Script untuk check available versions dari required packages
"""
import subprocess
import sys
import json
from typing import List, Dict
def check_package_versions(package: str, show_all: bool = False) -> List[str]:
"""Check available versions untuk package tertentu"""
try:
result = subprocess.run(
[sys.executable, "-m", "pip", "index", "versions", package],
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0:
lines = result.stdout.strip().split('\n')
versions = []
for line in lines:
if 'Available versions:' in line:
# Extract versions dari output
version_part = line.split('Available versions:')[1].strip()
versions = [v.strip() for v in version_part.split(',')]
break
if show_all:
return versions
else:
return versions[:10] # Show first 10 most recent
else:
print(f"β Error checking {package}: {result.stderr}")
return []
except subprocess.TimeoutExpired:
print(f"β° Timeout checking {package}")
return []
except Exception as e:
print(f"β Exception checking {package}: {e}")
return []
def main():
"""Main function untuk check semua packages"""
print("π Checking package versions untuk HF Spaces deployment...")
print("=" * 60)
# Packages yang perlu di-check
packages = [
"fastapi",
"uvicorn",
"onnxruntime",
"opencv-python-headless",
"numpy",
"pillow",
"pyyaml",
"python-multipart",
"python-jose"
]
results = {}
for package in packages:
print(f"π Checking {package}...")
versions = check_package_versions(package, show_all=False)
if versions:
print(f"β
{package}: {', '.join(versions[:5])}...")
results[package] = versions
else:
print(f"β {package}: Could not retrieve versions")
results[package] = []
print("\n" + "=" * 60)
print("π RECOMMENDED requirements.txt:")
print("=" * 60)
# Generate recommended versions
recommendations = {
"fastapi": "0.104.1",
"uvicorn[standard]": "0.24.0",
"onnxruntime": "1.15.1",
"opencv-python-headless": "4.8.0.76", # From error log
"numpy": "1.24.3",
"pillow": "10.0.1",
"pyyaml": "6.0.1",
"python-multipart": "0.0.6",
"python-jose[cryptography]": "3.3.0"
}
for package, version in recommendations.items():
print(f"{package}=={version}")
print("\n" + "=" * 60)
print("π‘ FLEXIBLE requirements.txt (ranges):")
print("=" * 60)
flexible = {
"fastapi": ">=0.100.0,<0.110.0",
"uvicorn[standard]": ">=0.20.0,<0.30.0",
"onnxruntime": ">=1.15.0,<1.16.0",
"opencv-python-headless": ">=4.7.0,<4.9.0",
"numpy": ">=1.21.0,<1.26.0",
"pillow": ">=9.0.0,<11.0.0",
"pyyaml": ">=6.0",
"python-multipart": ">=0.0.5"
}
for package, version in flexible.items():
print(f"{package}{version}")
print("\nπ― Use exact versions for production, ranges for development!")
if __name__ == "__main__":
main()
|