docker_mineru / deploy_to_hf.sh
marcosremar2's picture
Update with magic-pdf API implementation
ab599b4
#!/bin/bash
# Script to deploy the PDF processor to Hugging Face Spaces
# Check if huggingface_hub is installed
pip show huggingface_hub > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Installing huggingface_hub..."
pip install huggingface_hub
fi
# Set up variables
if [ -z "$1" ]; then
read -p "Enter your Hugging Face username: " HF_USERNAME
else
HF_USERNAME=$1
fi
if [ -z "$2" ]; then
read -p "Enter the name for your Space: " SPACE_NAME
else
SPACE_NAME=$2
fi
SPACE_REPO="$HF_USERNAME/$SPACE_NAME"
SPACE_URL="https://huggingface.co/spaces/$SPACE_REPO"
# Check if the repo exists
echo "Checking if the Space already exists..."
huggingface-cli repo info spaces/$SPACE_REPO > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Space $SPACE_REPO already exists."
read -p "Do you want to continue and update it? (y/n): " CONTINUE
if [ "$CONTINUE" != "y" ] && [ "$CONTINUE" != "Y" ]; then
echo "Deployment cancelled."
exit 1
fi
else
echo "Creating new Space: $SPACE_REPO"
huggingface-cli repo create spaces/$SPACE_NAME --type space --organization $HF_USERNAME
fi
# Create a temporary directory
TEMP_DIR=$(mktemp -d)
echo "Created temporary directory: $TEMP_DIR"
# Clone the repository
echo "Cloning repository..."
git clone https://huggingface.co/spaces/$SPACE_REPO $TEMP_DIR
# Copy files to the repository
echo "Copying files to the repository..."
cp -r api.py app.py convert_pdf.py download_models_hf.py requirements.txt Dockerfile README.md .gitattributes $TEMP_DIR/
mkdir -p $TEMP_DIR/output/images
# If magic-pdf.json exists, copy it
if [ -f "magic-pdf.json" ]; then
cp magic-pdf.json $TEMP_DIR/
fi
# Configure Git LFS
cd $TEMP_DIR
git lfs install
# Add, commit, and push changes
echo "Committing changes..."
git add .
git commit -m "Update PDF processor application"
git push
echo "Deployment completed successfully!"
echo "Your Space is available at: $SPACE_URL"