File size: 1,838 Bytes
3b1fac6 |
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 |
#!/usr/bin/env python3
"""
Startup script for Hugging Face Spaces deployment.
"""
import os
import subprocess
import time
import sys
def main():
"""Main startup function."""
print('π Starting Multilingual Audio Intelligence System...')
# Create necessary directories
dirs = [
'uploads', 'outputs', 'model_cache', 'temp_files',
'demo_results', '/tmp/matplotlib', '/tmp/fontconfig'
]
for d in dirs:
try:
os.makedirs(d, mode=0o777, exist_ok=True)
print(f'β
Created directory: {d}')
except Exception as e:
print(f'β οΈ Failed to create directory {d}: {e}')
# Try to preload models
try:
print('π Preloading models...')
result = subprocess.run(['python', 'model_preloader.py'],
check=True, capture_output=True, text=True)
print('β
Models loaded successfully')
if result.stdout:
print(f'Model preloader output: {result.stdout}')
except subprocess.CalledProcessError as e:
print(f'β οΈ Model preloading failed: {e}')
if e.stdout:
print(f'Model preloader stdout: {e.stdout}')
if e.stderr:
print(f'Model preloader stderr: {e.stderr}')
print('π Continuing without preloaded models...')
except Exception as e:
print(f'β οΈ Model preloading failed: {e}')
print('π Continuing without preloaded models...')
# Start the web application
print('π Starting web application...')
try:
import uvicorn
uvicorn.run('web_app:app', host='0.0.0.0', port=7860, workers=1, log_level='info')
except Exception as e:
print(f'β Failed to start web application: {e}')
sys.exit(1)
if __name__ == '__main__':
main()
|