Download verify_dependencies.py from rakib7/localize: direct link, hf CLI and curl.
- Browser
- Download file 5.49 kB
-
https://huggingface.co/spaces/rakib7/localize/resolve/main/verify_dependencies.py
- Command line
-
hf download hf://spaces/rakib7/localize/verify_dependencies.py
-
curl -L -o verify_dependencies.py https://huggingface.co/spaces/rakib7/localize/resolve/main/verify_dependencies.py
5.49 kB
| #!/usr/bin/env python3 | |
| """ | |
| Dependency Verification Script | |
| Checks if all dependencies are installed with correct versions | |
| """ | |
| import sys | |
| from importlib.metadata import version, PackageNotFoundError | |
| # Expected versions | |
| EXPECTED_VERSIONS = { | |
| "gradio": "4.44.1", | |
| "transformers": "4.57.6", | |
| "torch": "2.10.0", | |
| "sentencepiece": "0.2.1", | |
| "protobuf": "6.33.4", | |
| "accelerate": "1.12.0", | |
| } | |
| def check_python_version(): | |
| """Check if Python version is 3.10 or higher""" | |
| print("Checking Python version...") | |
| major, minor = sys.version_info[:2] | |
| print(f" Current: Python {major}.{minor}") | |
| if major < 3 or (major == 3 and minor < 10): | |
| print(" β FAILED: Python 3.10+ required") | |
| return False | |
| else: | |
| print(" β PASSED: Python version is compatible") | |
| return True | |
| def check_package_versions(): | |
| """Check if all packages are installed with correct versions""" | |
| print("\nChecking package versions...") | |
| all_correct = True | |
| for package, expected_version in EXPECTED_VERSIONS.items(): | |
| try: | |
| installed_version = version(package) | |
| status = "β " if installed_version == expected_version else "β οΈ" | |
| if installed_version != expected_version: | |
| all_correct = False | |
| print(f" {status} {package}: {installed_version} (expected {expected_version})") | |
| else: | |
| print(f" {status} {package}: {installed_version}") | |
| except PackageNotFoundError: | |
| print(f" β {package}: NOT INSTALLED (expected {expected_version})") | |
| all_correct = False | |
| return all_correct | |
| def test_imports(): | |
| """Test if all packages can be imported""" | |
| print("\nTesting package imports...") | |
| imports_ok = True | |
| try: | |
| print(" Importing gradio...") | |
| import gradio as gr | |
| print(f" β gradio imported successfully (version {gr.__version__})") | |
| except Exception as e: | |
| print(f" β Failed to import gradio: {e}") | |
| imports_ok = False | |
| try: | |
| print(" Importing transformers...") | |
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
| print(" β transformers imported successfully") | |
| except Exception as e: | |
| print(f" β Failed to import transformers: {e}") | |
| imports_ok = False | |
| try: | |
| print(" Importing torch...") | |
| import torch | |
| print(f" β torch imported successfully (version {torch.__version__})") | |
| except Exception as e: | |
| print(f" β Failed to import torch: {e}") | |
| imports_ok = False | |
| try: | |
| print(" Importing sentencepiece...") | |
| import sentencepiece | |
| print(" β sentencepiece imported successfully") | |
| except Exception as e: | |
| print(f" β Failed to import sentencepiece: {e}") | |
| imports_ok = False | |
| try: | |
| print(" Importing protobuf...") | |
| import google.protobuf | |
| print(" β protobuf imported successfully") | |
| except Exception as e: | |
| print(f" β Failed to import protobuf: {e}") | |
| imports_ok = False | |
| try: | |
| print(" Importing accelerate...") | |
| import accelerate | |
| print(" β accelerate imported successfully") | |
| except Exception as e: | |
| print(f" β Failed to import accelerate: {e}") | |
| imports_ok = False | |
| return imports_ok | |
| def test_gradio_api(): | |
| """Test if Gradio 4.x API works correctly""" | |
| print("\nTesting Gradio 4.x API...") | |
| try: | |
| import gradio as gr | |
| # Test that theme can be passed to Blocks (Gradio 4.x style) | |
| with gr.Blocks(title="Test", theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# Test") | |
| print(" β Gradio Blocks created successfully with theme") | |
| print(" β Gradio 4.x API is compatible") | |
| return True | |
| except Exception as e: | |
| print(f" β Gradio API test failed: {e}") | |
| return False | |
| def main(): | |
| """Run all verification checks""" | |
| print("=" * 60) | |
| print("NLLB Translator - Dependency Verification") | |
| print("=" * 60) | |
| results = [] | |
| # Check Python version | |
| results.append(("Python Version", check_python_version())) | |
| # Check package versions | |
| results.append(("Package Versions", check_package_versions())) | |
| # Test imports | |
| results.append(("Package Imports", test_imports())) | |
| # Test Gradio API | |
| results.append(("Gradio 4.x API", test_gradio_api())) | |
| # Summary | |
| print("\n" + "=" * 60) | |
| print("VERIFICATION SUMMARY") | |
| print("=" * 60) | |
| for test_name, passed in results: | |
| status = "β PASSED" if passed else "β FAILED" | |
| print(f"{test_name}: {status}") | |
| all_passed = all(result[1] for result in results) | |
| print("\n" + "=" * 60) | |
| if all_passed: | |
| print("β ALL CHECKS PASSED - Dependencies are correctly installed!") | |
| print("\nYou can now run the application with:") | |
| print(" python app.py") | |
| else: | |
| print("β SOME CHECKS FAILED - Please review the errors above") | |
| print("\nTo fix issues:") | |
| print(" 1. Ensure Python 3.10+ is installed") | |
| print(" 2. Run: pip install -r requirements.txt") | |
| print(" 3. Run this script again to verify") | |
| print("=" * 60) | |
| return 0 if all_passed else 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |