|
|
|
"""
|
|
Manual dependency installation script for Hugging Face Spaces.
|
|
|
|
This script installs missing dependencies that might not be properly
|
|
installed through requirements.txt. Run this in the Space terminal.
|
|
|
|
Author: Louis Chua Bean Chong
|
|
License: GPL-3.0
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
|
|
def run_command(command, description):
|
|
"""
|
|
Run a shell command and handle errors.
|
|
|
|
Args:
|
|
command: Command to run
|
|
description: Description of what the command does
|
|
"""
|
|
print(f"\nπ§ {description}")
|
|
print(f"Running: {command}")
|
|
|
|
try:
|
|
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
|
if result.returncode == 0:
|
|
print(f"β
Success: {description}")
|
|
if result.stdout.strip():
|
|
print(f"Output: {result.stdout.strip()}")
|
|
else:
|
|
print(f"β Failed: {description}")
|
|
print(f"Error: {result.stderr.strip()}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"β Exception: {e}")
|
|
return False
|
|
|
|
return True
|
|
|
|
def main():
|
|
"""Install all required dependencies manually."""
|
|
print("π Manual Dependency Installation for OpenLLM Training")
|
|
print("=" * 60)
|
|
|
|
|
|
print(f"π Python version: {sys.version}")
|
|
print(f"π Working directory: {os.getcwd()}")
|
|
|
|
|
|
dependencies = [
|
|
("sentencepiece>=0.1.99", "SentencePiece tokenization library (CRITICAL for OpenLLM)"),
|
|
("transformers>=4.30.0", "Hugging Face Transformers library"),
|
|
("datasets>=2.12.0", "Hugging Face Datasets library"),
|
|
("tokenizers>=0.13.0", "Fast tokenization library"),
|
|
("huggingface_hub>=0.34.0", "Hugging Face Hub integration"),
|
|
("accelerate>=0.20.0", "Distributed training acceleration"),
|
|
("torch>=2.0.0", "PyTorch deep learning framework"),
|
|
("gradio==4.44.1", "Gradio UI framework (fixed version)"),
|
|
("numpy>=1.24.0", "Numerical computing library"),
|
|
("pandas>=2.0.0", "Data manipulation library"),
|
|
("tqdm>=4.65.0", "Progress bars"),
|
|
("requests>=2.31.0", "HTTP library"),
|
|
]
|
|
|
|
print(f"\nπ¦ Installing {len(dependencies)} dependencies...")
|
|
|
|
success_count = 0
|
|
for package, description in dependencies:
|
|
command = f"pip install {package}"
|
|
if run_command(command, description):
|
|
success_count += 1
|
|
|
|
print(f"\n" + "=" * 60)
|
|
print(f"π― Installation Summary:")
|
|
print(f"β
Successful: {success_count}/{len(dependencies)}")
|
|
print(f"β Failed: {len(dependencies) - success_count}/{len(dependencies)}")
|
|
|
|
if success_count == len(dependencies):
|
|
print("\nπ All dependencies installed successfully!")
|
|
print("π‘ You can now try the training again.")
|
|
else:
|
|
print("\nβ οΈ Some dependencies failed to install.")
|
|
print("π‘ Check the error messages above and try again.")
|
|
|
|
|
|
print(f"\nπ§ͺ Testing critical imports...")
|
|
test_imports = [
|
|
("sentencepiece", "SentencePiece (CRITICAL)"),
|
|
("transformers", "Transformers"),
|
|
("datasets", "Datasets"),
|
|
("torch", "PyTorch"),
|
|
("gradio", "Gradio"),
|
|
]
|
|
|
|
for module, name in test_imports:
|
|
try:
|
|
__import__(module)
|
|
print(f"β
{name} - Import successful")
|
|
except ImportError as e:
|
|
print(f"β {name} - Import failed: {e}")
|
|
|
|
print(f"\nπ§ Manual installation complete!")
|
|
print("π‘ If imports still fail, try restarting the Space.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|