File size: 3,754 Bytes
e006598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
"""
Setup script for EmoVoice Hugging Face Space
This script prepares the environment and downloads necessary models
"""

import os
import sys
import subprocess
import logging
from pathlib import Path

# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

def run_command(command, description):
    """Run a command and log the result"""
    logger.info(f"Running: {description}")
    try:
        result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
        logger.info(f"βœ… {description} completed successfully")
        return True
    except subprocess.CalledProcessError as e:
        logger.error(f"❌ {description} failed: {e}")
        logger.error(f"Error output: {e.stderr}")
        return False

def check_python_version():
    """Check if Python version is compatible"""
    if sys.version_info < (3, 8):
        logger.error("❌ Python 3.8 or higher is required")
        return False
    logger.info(f"βœ… Python version: {sys.version}")
    return True

def install_requirements():
    """Install required packages"""
    requirements_file = Path(__file__).parent / "requirements.txt"
    if not requirements_file.exists():
        logger.error("❌ requirements.txt not found")
        return False
    
    return run_command(
        f"pip install -r {requirements_file}",
        "Installing requirements"
    )

def create_directories():
    """Create necessary directories"""
    directories = [
        "models",
        "cache",
        "temp"
    ]
    
    for directory in directories:
        Path(directory).mkdir(exist_ok=True)
        logger.info(f"βœ… Created directory: {directory}")
    
    return True

def setup_environment():
    """Set up environment variables"""
    env_vars = {
        "TOKENIZERS_PARALLELISM": "false",
        "OMP_NUM_THREADS": "1",
        "PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT": "2",
        "CUDA_LAUNCH_BLOCKING": "1"
    }
    
    for key, value in env_vars.items():
        os.environ[key] = value
        logger.info(f"βœ… Set environment variable: {key}={value}")
    
    return True

def verify_installation():
    """Verify that all required packages are installed"""
    required_packages = [
        "gradio",
        "torch",
        "torchaudio", 
        "soundfile",
        "numpy",
        "librosa",
        "huggingface_hub",
        "transformers"
    ]
    
    missing_packages = []
    for package in required_packages:
        try:
            __import__(package)
            logger.info(f"βœ… {package} is installed")
        except ImportError:
            missing_packages.append(package)
            logger.error(f"❌ {package} is missing")
    
    if missing_packages:
        logger.error(f"Missing packages: {missing_packages}")
        return False
    
    return True

def main():
    """Main setup function"""
    logger.info("πŸš€ Starting EmoVoice Hugging Face Space setup...")
    
    # Check Python version
    if not check_python_version():
        sys.exit(1)
    
    # Create directories
    if not create_directories():
        sys.exit(1)
    
    # Set up environment
    if not setup_environment():
        sys.exit(1)
    
    # Install requirements
    if not install_requirements():
        logger.warning("⚠️ Some packages failed to install, but continuing...")
    
    # Verify installation
    if not verify_installation():
        logger.warning("⚠️ Some packages are missing, but continuing...")
    
    logger.info("βœ… Setup completed successfully!")
    logger.info("🎭 You can now run the EmoVoice demo with: python app.py")

if __name__ == "__main__":
    main()