athmontech commited on
Commit
ef69efc
Β·
1 Parent(s): a70f0a0

Fix Docker runtime errors: cache permissions and numba JIT issues

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -5
  2. main.py +17 -4
  3. start.sh +45 -0
Dockerfile CHANGED
@@ -26,13 +26,17 @@ RUN pip install --no-cache-dir -r requirements.txt
26
  # Copy application code
27
  COPY . .
28
 
29
- # Create cache directory for models
30
- RUN mkdir -p /app/cache
 
 
 
31
 
32
  # Set environment variables
33
- ENV TRANSFORMERS_CACHE=/app/cache
34
  ENV HF_HOME=/app/cache
35
  ENV PYTHONPATH=/app
 
 
36
 
37
  # Expose port
38
  EXPOSE 7860
@@ -40,5 +44,5 @@ EXPOSE 7860
40
  # Set environment variable for port
41
  ENV PORT=7860
42
 
43
- # Run the application
44
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
26
  # Copy application code
27
  COPY . .
28
 
29
+ # Make startup script executable
30
+ RUN chmod +x start.sh
31
+
32
+ # Create cache directory for models with proper permissions
33
+ RUN mkdir -p /app/cache && chmod 777 /app/cache
34
 
35
  # Set environment variables
 
36
  ENV HF_HOME=/app/cache
37
  ENV PYTHONPATH=/app
38
+ ENV NUMBA_CACHE_DIR=/tmp/numba_cache
39
+ ENV NUMBA_DISABLE_JIT=1
40
 
41
  # Expose port
42
  EXPOSE 7860
 
44
  # Set environment variable for port
45
  ENV PORT=7860
46
 
47
+ # Run the application with startup script
48
+ CMD ["./start.sh"]
main.py CHANGED
@@ -12,7 +12,17 @@ try:
12
  except ImportError:
13
  ASREngine = None
14
 
15
- from tts_engine import TTSEngine
 
 
 
 
 
 
 
 
 
 
16
 
17
  try:
18
  from translation_engine import TranslationEngine
@@ -63,9 +73,12 @@ def load_models():
63
  else:
64
  logger.warning("⚠️ ASR Engine not available")
65
 
66
- logger.info("Loading TTS Engine...")
67
- tts_engine = TTSEngine()
68
- logger.info("βœ… TTS Engine loaded")
 
 
 
69
 
70
  logger.info("--- All available models loaded. API is ready. ---")
71
  except Exception as e:
 
12
  except ImportError:
13
  ASREngine = None
14
 
15
+ try:
16
+ # Set environment variables to prevent numba caching issues
17
+ import os
18
+ os.environ['NUMBA_DISABLE_JIT'] = '1'
19
+ os.environ['NUMBA_CACHE_DIR'] = '/tmp/numba_cache'
20
+ from tts_engine import TTSEngine
21
+ TTS_AVAILABLE = True
22
+ except ImportError as e:
23
+ print(f"⚠️ TTS engine not available: {e}")
24
+ TTSEngine = None
25
+ TTS_AVAILABLE = False
26
 
27
  try:
28
  from translation_engine import TranslationEngine
 
73
  else:
74
  logger.warning("⚠️ ASR Engine not available")
75
 
76
+ if TTS_AVAILABLE and TTSEngine:
77
+ logger.info("Loading TTS Engine...")
78
+ tts_engine = TTSEngine()
79
+ logger.info("βœ… TTS Engine loaded")
80
+ else:
81
+ logger.warning("⚠️ TTS Engine not available")
82
 
83
  logger.info("--- All available models loaded. API is ready. ---")
84
  except Exception as e:
start.sh ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "πŸš€ Starting Carsa AI Backend..."
5
+ echo "πŸ“ Working directory: $(pwd)"
6
+ echo "🐍 Python version: $(python --version)"
7
+
8
+ # Check if main.py exists
9
+ if [ ! -f "main.py" ]; then
10
+ echo "❌ main.py not found!"
11
+ exit 1
12
+ fi
13
+
14
+ # Test import before starting server
15
+ echo "πŸ” Testing imports..."
16
+ python -c "
17
+ import sys
18
+ print('βœ… Python import test...')
19
+ try:
20
+ import fastapi
21
+ print('βœ… FastAPI imported')
22
+ import uvicorn
23
+ print('βœ… Uvicorn imported')
24
+ import torch
25
+ print('βœ… PyTorch imported')
26
+ print('🎯 All core imports successful!')
27
+ except ImportError as e:
28
+ print(f'❌ Import error: {e}')
29
+ sys.exit(1)
30
+ "
31
+
32
+ # Create cache directories with proper permissions
33
+ mkdir -p /app/cache /tmp/numba_cache
34
+ chmod 777 /app/cache /tmp/numba_cache
35
+ echo "πŸ“ Cache directories created with proper permissions"
36
+
37
+ # Set environment variables
38
+ export HF_HOME=/app/cache
39
+ export PYTHONPATH=/app
40
+ export NUMBA_CACHE_DIR=/tmp/numba_cache
41
+ export NUMBA_DISABLE_JIT=1
42
+ echo "πŸ”§ Environment variables set"
43
+
44
+ echo "🌍 Starting server on 0.0.0.0:7860..."
45
+ python -m uvicorn main:app --host 0.0.0.0 --port 7860 --workers 1