|
|
|
|
|
""" |
|
|
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...') |
|
|
|
|
|
|
|
|
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: |
|
|
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...') |
|
|
|
|
|
|
|
|
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() |
|
|
|