File size: 1,937 Bytes
ab599b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/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"