diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..a8dd540 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b79d30e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/simple-asr-server.iml b/.idea/simple-asr-server.iml new file mode 100644 index 0000000..ec63674 --- /dev/null +++ b/.idea/simple-asr-server.iml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2f7749a..9b71450 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,43 @@ -FROM rocm/pytorch:rocm6.4.1_ubuntu22.04_py3.10_pytorch_release_2.6.0 +# Use official Python image as base +FROM python:3.10-slim +# Set working directory WORKDIR /app +# Install system dependencies RUN apt-get update && apt-get install -y \ ffmpeg \ + git \ + curl \ python3-pip \ - python3-venv \ + && rm -rf /var/lib/apt/lists/* +# Update pip +RUN pip install --upgrade pip + +# Copy requirements first for better caching COPY requirements.txt . -RUN pip install --no-cache-dir --default-timeout=100 -r requirements.txt -COPY . . +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt +# Copy application code +COPY app.py . + +# Create directory for models and keys +RUN mkdir -p /app/models /app/data + +# Set environment variables +ENV PYTHONUNBUFFERED=1 +ENV MODEL_DOWNLOAD_ROOT=/app/models +ENV KEYS_FILE=/app/data/keys.txt + +# Expose port EXPOSE 9854 -# Устанавливаем переменные окружения для ROCm -ENV HSA_OVERRIDE_GFX_VERSION=10.3.0 -ENV PYTORCH_ROCM_ARCH=gfx1030 +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD curl -f http://localhost:9854/health || exit 1 -# Команда для запуска приложения -CMD ["python3", "app.py"] +# Run the application +CMD ["python", "app.py"] diff --git a/requirements.txt b/requirements.txt index 6a0fedf..c3f060d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,7 @@ fastapi uvicorn[standard] python-multipart -gigaam -gigaam[longform] -ffmpeg-python -PyYAML -numpy<2.0.0 \ No newline at end of file +openai-whisper +python-dotenv + + diff --git a/simple-asr-server.service b/simple-asr-server.service new file mode 100644 index 0000000..9fa30a4 --- /dev/null +++ b/simple-asr-server.service @@ -0,0 +1,20 @@ +[Unit] +Description=Whisper ASR Server (ROCM) +After=network.target +Wants=network.target + +[Service] +Type=exec +User=asr +Group=asr +WorkingDirectory=/opt/asr +ExecStart=/opt/asr/start_server.sh +ExecReload=/bin/kill -HUP $MAINPID +Restart=always +RestartSec=10 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=asr + +[Install] +WantedBy=multi-user.target diff --git a/start_server.sh b/start_server.sh new file mode 100755 index 0000000..2ac7bf9 --- /dev/null +++ b/start_server.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Simple ASR Server startup script for systemd +# This script loads environment variables from .env file and starts the server + +set -e + +# Get the directory where this script is located +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +APP_DIR="${SCRIPT_DIR}" + +# Load environment variables from .env file if it exists +if [ -f "${APP_DIR}/.env" ]; then + echo "Loading environment variables from ${APP_DIR}/.env" + set -a # automatically export all variables + source "${APP_DIR}/.env" + set +a +else + echo "Warning: .env file not found at ${APP_DIR}/.env" + echo "Using default environment variables" +fi + +# Set default values if not provided in .env +export HOST=${HOST:-"0.0.0.0"} +export PORT=${PORT:-9854} +export DEFAULT_MODEL=${DEFAULT_MODEL:-"turbo"} +export MODEL_DOWNLOAD_ROOT=${MODEL_DOWNLOAD_ROOT:-"${APP_DIR}/models"} +export KEYS_FILE=${KEYS_FILE:-"${APP_DIR}/keys.txt"} +export LOG_LEVEL=${LOG_LEVEL:-"INFO"} + +# Create necessary directories +mkdir -p "${MODEL_DOWNLOAD_ROOT}" +mkdir -p "$(dirname "${KEYS_FILE}")" + +# Check if virtual environment exists, create if not +VENV_DIR="${APP_DIR}/venv" +if [ ! -d "${VENV_DIR}" ]; then + echo "Creating virtual environment..." + python3 -m venv "${VENV_DIR}" +fi + +# Activate virtual environment +echo "Activating virtual environment..." +source "${VENV_DIR}/bin/activate" + +# Install/upgrade dependencies +echo "Installing/upgrading dependencies..." +pip install --upgrade pip +pip install -r "${APP_DIR}/requirements.txt" + +# Change to app directory +cd "${APP_DIR}" + +echo "Starting Simple ASR Server..." +echo "Host: ${HOST}" +echo "Port: ${PORT}" +echo "Default Model: ${DEFAULT_MODEL}" +echo "Model Download Root: ${MODEL_DOWNLOAD_ROOT}" +echo "Keys File: ${KEYS_FILE}" +echo "Log Level: ${LOG_LEVEL}" + +# Start the application +exec python3 app.py +