Add Gunicorn support for production in Vosk service and update requirements

This commit is contained in:
Alireza
2025-08-02 17:52:11 +03:30
parent 0d151529f0
commit cfe2b2346a
7 changed files with 220 additions and 6 deletions

36
vosk/test_files/quick_fix.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Quick fix for Flask multiprocessing issue
echo "🔧 Applying quick fix for Flask multiprocessing issue..."
# Kill any existing Vosk service
echo "🛑 Stopping any existing Vosk service..."
pkill -f "python.*app_optimized" || true
pkill -f "gunicorn.*app_optimized" || true
# Wait a moment
sleep 2
# Start the service with proper configuration
echo "🚀 Starting Vosk service with proper configuration..."
cd ../vosk_service
# Use the startup script that handles configuration properly
python start_service.py &
VOSK_PID=$!
echo "✅ Vosk service started with PID: $VOSK_PID"
# Wait for service to be ready
echo "⏳ Waiting for service to be ready..."
for i in {1..30}; do
if curl -s http://localhost:5000/ > /dev/null; then
echo "✅ Service is ready!"
break
fi
sleep 1
done
echo "🎯 Service should now be running without the multiprocessing error!"
echo "💡 You can now run your optimized processing script."

View File

@@ -21,6 +21,7 @@ vosk>=0.3.45
# Flask for API (if using Flask version)
flask>=2.3.0
gunicorn>=21.0.0
# Additional optimizations
uvloop>=0.17.0 # Faster event loop for asyncio

View File

@@ -44,10 +44,20 @@ if ! curl -s http://localhost:5000/ > /dev/null; then
# Start optimized Vosk service
cd ../vosk_service
export USE_ASYNC=true
python app_optimized.py &
VOSK_PID=$!
echo "✅ Vosk service started with PID: $VOSK_PID"
# Choose between async and production mode
if [ "$USE_ASYNC" = "true" ]; then
export USE_ASYNC=true
python start_service.py &
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 &
VOSK_PID=$!
echo "✅ Vosk Gunicorn service started with PID: $VOSK_PID"
fi
# Wait for service to be ready
echo "⏳ Waiting for service to be ready..."

View File

@@ -0,0 +1,80 @@
#!/usr/bin/env python3
"""
Test script to verify Vosk service is working properly.
"""
import requests
import time
import json
def test_service_health():
"""Test if the service is responding"""
try:
response = requests.get("http://localhost:5000/", timeout=5)
if response.status_code == 200:
print("✅ Service is healthy!")
print(f"Response: {response.json()}")
return True
else:
print(f"❌ Service returned status {response.status_code}")
return False
except Exception as e:
print(f"❌ Service not responding: {e}")
return False
def test_batch_processing():
"""Test batch processing functionality"""
try:
# Create a simple test batch
test_data = {
'references': json.dumps(['test sentence 1', 'test sentence 2'])
}
# Create dummy audio files (you'll need real audio files for actual testing)
files = {
'audio0': ('test1.wav', b'dummy_audio_data', 'audio/wav'),
'audio1': ('test2.wav', b'dummy_audio_data', 'audio/wav')
}
response = requests.post(
"http://localhost:5000/batch_confirm",
data=test_data,
files=files,
timeout=30
)
if response.status_code == 200:
print("✅ Batch processing endpoint is working!")
print(f"Response: {response.json()}")
return True
else:
print(f"❌ Batch processing failed: {response.status_code}")
print(f"Response: {response.text}")
return False
except Exception as e:
print(f"❌ Batch processing error: {e}")
return False
def main():
"""Main test function"""
print("🔍 Testing Vosk service...")
# Wait for service to be ready
print("⏳ Waiting for service to be ready...")
for i in range(30):
if test_service_health():
break
time.sleep(1)
else:
print("❌ Service did not become ready within 30 seconds")
return
# Test batch processing
print("\n🧪 Testing batch processing...")
test_batch_processing()
print("\n✅ Service testing complete!")
if __name__ == "__main__":
main()