From 896831aa46040fc710b8ee2351e5d43476dad9f6 Mon Sep 17 00:00:00 2001 From: Alireza Date: Sat, 2 Aug 2025 17:59:14 +0330 Subject: [PATCH] Refactor Vosk service startup script to use start_with_deps.sh for both async and Gunicorn modes --- vosk/test_files/fix_flask_error.sh | 34 ++++++++++ vosk/test_files/run_optimized_192cores.sh | 4 +- vosk/vosk_service/install_deps.sh | 51 +++++++++++++++ vosk/vosk_service/requirements_optimized.txt | 15 +++++ vosk/vosk_service/start_with_deps.sh | 69 ++++++++++++++++++++ 5 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 vosk/test_files/fix_flask_error.sh create mode 100644 vosk/vosk_service/install_deps.sh create mode 100644 vosk/vosk_service/requirements_optimized.txt create mode 100644 vosk/vosk_service/start_with_deps.sh diff --git a/vosk/test_files/fix_flask_error.sh b/vosk/test_files/fix_flask_error.sh new file mode 100644 index 0000000..1abf981 --- /dev/null +++ b/vosk/test_files/fix_flask_error.sh @@ -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 \ No newline at end of file diff --git a/vosk/test_files/run_optimized_192cores.sh b/vosk/test_files/run_optimized_192cores.sh index 3fc8cfe..31a1e4a 100755 --- a/vosk/test_files/run_optimized_192cores.sh +++ b/vosk/test_files/run_optimized_192cores.sh @@ -48,13 +48,13 @@ if ! curl -s http://localhost:5000/ > /dev/null; then # Choose between async and production mode if [ "$USE_ASYNC" = "true" ]; then export USE_ASYNC=true - python start_service.py & + ./start_with_deps.sh & VOSK_PID=$! echo "โœ… Vosk async service started with PID: $VOSK_PID" else # Use Gunicorn for production multiprocessing export USE_GUNICORN=true - gunicorn -c gunicorn_config.py app_optimized:app & + ./start_with_deps.sh & VOSK_PID=$! echo "โœ… Vosk Gunicorn service started with PID: $VOSK_PID" fi diff --git a/vosk/vosk_service/install_deps.sh b/vosk/vosk_service/install_deps.sh new file mode 100644 index 0000000..37c845a --- /dev/null +++ b/vosk/vosk_service/install_deps.sh @@ -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!" \ No newline at end of file diff --git a/vosk/vosk_service/requirements_optimized.txt b/vosk/vosk_service/requirements_optimized.txt new file mode 100644 index 0000000..fc1a452 --- /dev/null +++ b/vosk/vosk_service/requirements_optimized.txt @@ -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 \ No newline at end of file diff --git a/vosk/vosk_service/start_with_deps.sh b/vosk/vosk_service/start_with_deps.sh new file mode 100644 index 0000000..3043432 --- /dev/null +++ b/vosk/vosk_service/start_with_deps.sh @@ -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 \ No newline at end of file