langvoice / entrypoint.sh
muhammadnoman76's picture
update
6ca99da
#!/bin/sh
set -e
echo "=========================================="
echo "LangVoice Backend - Hugging Face Deployment"
echo "=========================================="
echo "Starting at: $(date)"
APP_DIR="/home/user/app"
BACKEND_DIR="$APP_DIR/langvoice_backend"
# Check if the backend is already set up
if [ ! -d "$BACKEND_DIR/app" ]; then
echo "First run detected. Setting up application..."
# Check for GitHub token
if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: GITHUB_TOKEN is not set"
echo "Please set GITHUB_TOKEN as a Hugging Face Space secret"
exit 1
fi
echo "GitHub token found, proceeding with clone..."
echo "Cloning langvoice repository..."
git clone --depth 1 "https://${GITHUB_TOKEN}@github.com/muhammadnoman76/langvoice.git" /tmp/langvoice || {
echo "Failed to clone repository. Check GITHUB_TOKEN permissions."
exit 1
}
# Copy backend files
echo "Copying backend files..."
mkdir -p "$BACKEND_DIR"
cp -r /tmp/langvoice/langvoice_backend/* "$BACKEND_DIR/"
# Clean up cloned repo
rm -rf /tmp/langvoice
# Install Python dependencies
echo "Installing Python dependencies..."
cd "$BACKEND_DIR"
pip install --user --no-cache-dir -e . || {
echo "Failed to install dependencies"
exit 1
}
echo "=========================================="
echo "Setup complete!"
echo "=========================================="
else
echo "Backend already set up. Skipping clone..."
fi
# Navigate to backend directory
cd "$BACKEND_DIR"
# Create any required directories
mkdir -p uploads
# Set environment variables
export HOST="0.0.0.0"
export PORT="${PORT:-7860}"
echo "=========================================="
echo "Starting LangVoice Backend"
echo "Host: $HOST"
echo "Port: $PORT"
echo "=========================================="
# Run the FastAPI application
exec python -m uvicorn app.main:app --host "$HOST" --port "$PORT"