Prathamesh Sarjerao Vaidya
commited on
Commit
Β·
3b1fac6
1
Parent(s):
5de798e
fixed deployment error of hf_spaces
Browse files- Dockerfile +1 -16
- startup.py +57 -0
Dockerfile
CHANGED
@@ -78,19 +78,4 @@ HEALTHCHECK --interval=30s --timeout=30s --start-period=60s --retries=3 \
|
|
78 |
CMD curl -f http://localhost:7860/health || exit 1
|
79 |
|
80 |
# Preload models and start the application
|
81 |
-
CMD ["python", "
|
82 |
-
import os; \
|
83 |
-
import subprocess; \
|
84 |
-
import time; \
|
85 |
-
print('Starting Multilingual Audio Intelligence System...'); \
|
86 |
-
dirs = ['uploads', 'outputs', 'model_cache', 'temp_files', 'demo_results', '/tmp/matplotlib', '/tmp/fontconfig']; \
|
87 |
-
[os.makedirs(d, mode=0o777, exist_ok=True) for d in dirs]; \
|
88 |
-
try: \
|
89 |
-
subprocess.run(['python', 'model_preloader.py'], check=True); \
|
90 |
-
print('Models loaded successfully'); \
|
91 |
-
except Exception as e: \
|
92 |
-
print(f'Model preloading failed: {e}'); \
|
93 |
-
print('Continuing without preloaded models...'); \
|
94 |
-
import uvicorn; \
|
95 |
-
uvicorn.run('web_app:app', host='0.0.0.0', port=7860, workers=1, log_level='info')\
|
96 |
-
"]
|
|
|
78 |
CMD curl -f http://localhost:7860/health || exit 1
|
79 |
|
80 |
# Preload models and start the application
|
81 |
+
CMD ["python", "startup.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startup.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Startup script for Hugging Face Spaces deployment.
|
4 |
+
"""
|
5 |
+
|
6 |
+
import os
|
7 |
+
import subprocess
|
8 |
+
import time
|
9 |
+
import sys
|
10 |
+
|
11 |
+
def main():
|
12 |
+
"""Main startup function."""
|
13 |
+
print('π Starting Multilingual Audio Intelligence System...')
|
14 |
+
|
15 |
+
# Create necessary directories
|
16 |
+
dirs = [
|
17 |
+
'uploads', 'outputs', 'model_cache', 'temp_files',
|
18 |
+
'demo_results', '/tmp/matplotlib', '/tmp/fontconfig'
|
19 |
+
]
|
20 |
+
|
21 |
+
for d in dirs:
|
22 |
+
try:
|
23 |
+
os.makedirs(d, mode=0o777, exist_ok=True)
|
24 |
+
print(f'β
Created directory: {d}')
|
25 |
+
except Exception as e:
|
26 |
+
print(f'β οΈ Failed to create directory {d}: {e}')
|
27 |
+
|
28 |
+
# Try to preload models
|
29 |
+
try:
|
30 |
+
print('π Preloading models...')
|
31 |
+
result = subprocess.run(['python', 'model_preloader.py'],
|
32 |
+
check=True, capture_output=True, text=True)
|
33 |
+
print('β
Models loaded successfully')
|
34 |
+
if result.stdout:
|
35 |
+
print(f'Model preloader output: {result.stdout}')
|
36 |
+
except subprocess.CalledProcessError as e:
|
37 |
+
print(f'β οΈ Model preloading failed: {e}')
|
38 |
+
if e.stdout:
|
39 |
+
print(f'Model preloader stdout: {e.stdout}')
|
40 |
+
if e.stderr:
|
41 |
+
print(f'Model preloader stderr: {e.stderr}')
|
42 |
+
print('π Continuing without preloaded models...')
|
43 |
+
except Exception as e:
|
44 |
+
print(f'β οΈ Model preloading failed: {e}')
|
45 |
+
print('π Continuing without preloaded models...')
|
46 |
+
|
47 |
+
# Start the web application
|
48 |
+
print('π Starting web application...')
|
49 |
+
try:
|
50 |
+
import uvicorn
|
51 |
+
uvicorn.run('web_app:app', host='0.0.0.0', port=7860, workers=1, log_level='info')
|
52 |
+
except Exception as e:
|
53 |
+
print(f'β Failed to start web application: {e}')
|
54 |
+
sys.exit(1)
|
55 |
+
|
56 |
+
if __name__ == '__main__':
|
57 |
+
main()
|