Refactor Vosk service startup script to use start_with_deps.sh for both async and Gunicorn modes

This commit is contained in:
Alireza
2025-08-02 17:59:14 +03:30
parent cfe2b2346a
commit 896831aa46
5 changed files with 171 additions and 2 deletions

View File

@@ -0,0 +1,34 @@
#!/bin/bash
# Quick fix for Flask module error
echo "🔧 Fixing Flask module error..."
# Navigate to vosk_service directory
cd ../vosk_service
# Make the startup script executable
chmod +x start_with_deps.sh
# Install dependencies
echo "📦 Installing dependencies..."
pip install Flask>=2.3.0
pip install aiohttp>=3.8.0
pip install gunicorn>=21.0.0
pip install vosk>=0.3.45
pip install soundfile>=0.12.1
pip install numpy>=1.24.0
pip install requests>=2.31.0
# Test if Flask is now available
echo "🧪 Testing Flask import..."
python -c "import flask; print('✅ Flask imported successfully!')"
if [ $? -eq 0 ]; then
echo "🎯 Flask module error fixed!"
echo "💡 You can now run the service with:"
echo " cd vosk/vosk_service"
echo " ./start_with_deps.sh"
else
echo "❌ Flask import still failing. Please check your Python environment."
fi

View File

@@ -48,13 +48,13 @@ if ! curl -s http://localhost:5000/ > /dev/null; then
# Choose between async and production mode # Choose between async and production mode
if [ "$USE_ASYNC" = "true" ]; then if [ "$USE_ASYNC" = "true" ]; then
export USE_ASYNC=true export USE_ASYNC=true
python start_service.py & ./start_with_deps.sh &
VOSK_PID=$! VOSK_PID=$!
echo "✅ Vosk async service started with PID: $VOSK_PID" echo "✅ Vosk async service started with PID: $VOSK_PID"
else else
# Use Gunicorn for production multiprocessing # Use Gunicorn for production multiprocessing
export USE_GUNICORN=true export USE_GUNICORN=true
gunicorn -c gunicorn_config.py app_optimized:app & ./start_with_deps.sh &
VOSK_PID=$! VOSK_PID=$!
echo "✅ Vosk Gunicorn service started with PID: $VOSK_PID" echo "✅ Vosk Gunicorn service started with PID: $VOSK_PID"
fi fi

View File

@@ -0,0 +1,51 @@
#!/bin/bash
# Installation script for Vosk service dependencies
echo "🚀 Installing Vosk service dependencies..."
# Check if we're in the right directory
if [ ! -f "app_optimized.py" ]; then
echo "❌ Please run this script from the vosk_service directory"
exit 1
fi
# Install dependencies
echo "📦 Installing dependencies..."
# Core dependencies
pip install vosk>=0.3.45
pip install Flask>=2.3.0
pip install soundfile>=0.12.1
# Async dependencies
pip install aiohttp>=3.8.0
pip install asyncio-throttle>=1.0.0
# Production server
pip install gunicorn>=21.0.0
# Additional dependencies
pip install numpy>=1.24.0
pip install requests>=2.31.0
echo "✅ Dependencies installed successfully!"
# Test imports
echo "🧪 Testing imports..."
python -c "
try:
import flask
import aiohttp
import gunicorn
import vosk
import soundfile
import numpy
import requests
print('✅ All modules imported successfully!')
except ImportError as e:
print(f'❌ Import error: {e}')
exit(1)
"
echo "🎯 Vosk service is ready to run!"

View File

@@ -0,0 +1,15 @@
# Core dependencies for Vosk service
vosk>=0.3.45
Flask>=2.3.0
soundfile>=0.12.1
# Async and concurrent processing
aiohttp>=3.8.0
asyncio-throttle>=1.0.0
# Production server
gunicorn>=21.0.0
# Additional dependencies
numpy>=1.24.0
requests>=2.31.0

View File

@@ -0,0 +1,69 @@
#!/bin/bash
# Startup script that installs dependencies and starts the Vosk service
echo "🚀 Starting Vosk service with automatic dependency installation..."
# Check if we're in the right directory
if [ ! -f "app_optimized.py" ]; then
echo "❌ Please run this script from the vosk_service directory"
exit 1
fi
# Install dependencies if needed
echo "📦 Checking and installing dependencies..."
# Check if Flask is installed
if ! python -c "import flask" 2>/dev/null; then
echo "⚠️ Flask not found. Installing dependencies..."
# Install core dependencies
pip install vosk>=0.3.45
pip install Flask>=2.3.0
pip install soundfile>=0.12.1
pip install aiohttp>=3.8.0
pip install gunicorn>=21.0.0
pip install numpy>=1.24.0
pip install requests>=2.31.0
echo "✅ Dependencies installed!"
else
echo "✅ Dependencies already installed!"
fi
# Test imports
echo "🧪 Testing imports..."
python -c "
try:
import flask
import aiohttp
import gunicorn
import vosk
import soundfile
import numpy
import requests
print('✅ All modules imported successfully!')
except ImportError as e:
print(f'❌ Import error: {e}')
exit(1)
"
if [ $? -ne 0 ]; then
echo "❌ Import test failed. Please check your Python environment."
exit 1
fi
# Start the service
echo "🎯 Starting Vosk service..."
# Choose the startup method
if [ "$USE_GUNICORN" = "true" ]; then
echo "🚀 Starting with Gunicorn (production mode)..."
gunicorn -c gunicorn_config.py app_optimized:app
elif [ "$USE_ASYNC" = "true" ]; then
echo "⚡ Starting async service..."
python start_service.py
else
echo "🌐 Starting Flask service..."
python start_service.py
fi