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

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env python3
"""
Simple startup script for Vosk service that handles Flask configuration properly.
"""
import os
import sys
from app_optimized import app, load_model
def main():
"""Start the Vosk service with proper configuration"""
# Load the model first
print("Loading Vosk model...")
load_model()
# Determine the mode to run in
use_async = os.getenv('USE_ASYNC', 'false').lower() == 'true'
use_gunicorn = os.getenv('USE_GUNICORN', 'false').lower() == 'true'
if use_async:
print("Starting async aiohttp service...")
from aiohttp import web
from app_optimized import create_async_app
app_async = create_async_app()
web.run_app(app_async, host='0.0.0.0', port=5000)
elif use_gunicorn:
print("Starting with Gunicorn (production mode)...")
# Gunicorn will handle the app
app.run(host='0.0.0.0', port=5000)
else:
print("Starting Flask service with threading...")
# Use threading only (no multiprocessing in Flask)
app.run(host='0.0.0.0', port=5000, threaded=True)
if __name__ == '__main__':
main()