diff --git a/api/Dockerfile b/api/Dockerfile index 1674a564..4efdd91e 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -20,9 +20,12 @@ RUN pip install --user --no-cache-dir -r requirements.txt && \ # Copy and install pipecat from local submodule COPY pipecat /tmp/pipecat +COPY scripts/download_model.sh /tmp/download_model.sh RUN pip install --user --no-cache-dir '/tmp/pipecat[cartesia,deepgram,openai,elevenlabs,groq,google,azure,soundfile,silero,webrtc]' && \ - # Clean up pip cache and temporary pipecat directory - rm -rf /root/.cache/pip /tmp/pipecat + # Copy Silero VAD model using dedicated script (before cleaning up pipecat source) + bash /tmp/download_model.sh && \ + # Clean up pip cache and temporary files + rm -rf /root/.cache/pip /tmp/pipecat /tmp/download_model.sh # Remove unnecessary Python cache files from installed packages diff --git a/scripts/download_model.sh b/scripts/download_model.sh new file mode 100755 index 00000000..480cde2e --- /dev/null +++ b/scripts/download_model.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# Script to copy Silero VAD model during Docker build. +# This ensures the model is available at runtime. + +set -e + +# Source model path from the pipecat installation +SOURCE_MODEL_PATH="/tmp/pipecat/src/pipecat/audio/vad/data/silero_vad.onnx" + +# Target model path in the installed package +USER_SITE=$(python -c "import site; print(site.getusersitepackages())") +VAD_DATA_DIR="$USER_SITE/pipecat/audio/vad/data" +TARGET_MODEL_PATH="$VAD_DATA_DIR/silero_vad.onnx" + +echo "Setting up Silero VAD model..." + +# Create the VAD data directory if it doesn't exist +mkdir -p "$VAD_DATA_DIR" + +# Check if model already exists +if [ -f "$TARGET_MODEL_PATH" ]; then + echo "✓ Silero VAD model already exists at: $TARGET_MODEL_PATH" + exit 0 +fi + +# Check if source model exists +if [ ! -f "$SOURCE_MODEL_PATH" ]; then + echo "✗ Source model not found at: $SOURCE_MODEL_PATH" + exit 1 +fi + +echo "Copying Silero VAD model from pipecat source..." + +# Copy the model file +cp "$SOURCE_MODEL_PATH" "$TARGET_MODEL_PATH" + +# Verify the model file exists and get its size +if [ -f "$TARGET_MODEL_PATH" ]; then + FILE_SIZE=$(stat -c%s "$TARGET_MODEL_PATH" 2>/dev/null || stat -f%z "$TARGET_MODEL_PATH" 2>/dev/null) + echo "✓ Silero VAD model successfully copied to: $TARGET_MODEL_PATH ($FILE_SIZE bytes)" +else + echo "✗ Failed to copy model file to: $TARGET_MODEL_PATH" + exit 1 +fi + +echo "Silero VAD model setup complete!" \ No newline at end of file