File size: 4,660 Bytes
f66259a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
873ddfe
 
f66259a
 
 
 
 
873ddfe
f66259a
 
873ddfe
f66259a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
873ddfe
 
 
 
f66259a
 
 
 
 
 
 
 
 
873ddfe
 
 
 
 
 
 
 
f66259a
873ddfe
 
 
 
f66259a
 
 
 
873ddfe
f66259a
 
 
 
 
 
 
 
 
 
 
 
 
 
873ddfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f66259a
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash

# Quick deployment script for Hugging Face Spaces
# This script helps you deploy your Streamlit app to Hugging Face Spaces

set -e

echo "πŸš€ Hugging Face Spaces Deployment Script"
echo "=========================================="
echo ""

# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Check if hf CLI is installed
if ! command -v hf &> /dev/null; then
    echo -e "${YELLOW}⚠️  Hugging Face CLI not found. Installing...${NC}"
    pip install huggingface_hub
fi

# Check if logged in
if ! hf whoami &> /dev/null; then
    echo -e "${YELLOW}⚠️  Not logged in to Hugging Face${NC}"
    echo "Please login with your Hugging Face token:"
    hf auth login
fi

echo -e "${GREEN}βœ… Hugging Face CLI ready${NC}"
echo ""

# Space details
SPACE_ID="amithkamath/image-registration"
SPACE_URL="https://huggingface.co/spaces/$SPACE_ID"

echo "Target Space: $SPACE_ID"
echo "Space URL: $SPACE_URL"
echo ""

# Check if remote exists
if git remote | grep -q "^hf$"; then
    echo -e "${GREEN}βœ… Hugging Face remote already configured${NC}"
else
    echo -e "${YELLOW}⚠️  Adding Hugging Face remote...${NC}"
    git remote add hf "https://huggingface.co/spaces/$SPACE_ID"
fi

echo ""
echo "Files to be deployed:"
git ls-files | grep -E "(dockerfile|requirements\.txt|.*\.py|README\.md|LICENSE)"
echo ""
echo "πŸ“Š Note: Images are loaded from HF dataset (amithjkamath/exampleimages)"
echo "   No need to include rawimage.png or other binary files"
echo ""

# Confirm deployment
read -p "Do you want to deploy these files to $SPACE_ID? (y/n) " -n 1 -r
echo ""

if [[ $REPLY =~ ^[Yy]$ ]]; then
    echo -e "${YELLOW}πŸ“¦ Preparing deployment...${NC}"
    
    # Add all essential files for the Space
    echo "Adding files to git..."
    git add dockerfile requirements.txt image-registration-demo.py README.md LICENSE .gitignore 2>/dev/null || true
    
    # Remove deleted files (like rawimage.png)
    git add -u 2>/dev/null || true
    
    # Check if there are changes to commit
    if ! git diff-index --quiet HEAD --; then
        echo -e "${YELLOW}⚠️  Committing changes...${NC}"
        git commit -m "Deploy to Hugging Face Spaces - updated app with dataset integration"
    else
        echo -e "${GREEN}βœ… No new changes to commit${NC}"
    fi
    
    echo -e "${YELLOW}πŸš€ Pushing to Hugging Face Spaces...${NC}"
    
    # Try to push to Hugging Face
    if git push hf main; then
        echo ""
        echo -e "${GREEN}βœ… Deployment successful!${NC}"
        echo ""
        echo "Your app is being built at:"
        echo "$SPACE_URL"
        echo ""
        echo "Check the build logs at:"
        echo "$SPACE_URL?logs=build"
        echo ""
        echo "Once built, your app will be available at:"
        echo "$SPACE_URL"
    else
        echo ""
        echo -e "${RED}❌ Push failed. The remote branch has changes that aren't in your local branch.${NC}"
        echo ""
        echo "This typically happens when:"
        echo "  - The Space was modified directly on Hugging Face"
        echo "  - You're deploying from a different machine"
        echo ""
        echo -e "${YELLOW}Options:${NC}"
        echo "  1. Pull and merge: git pull hf main (safer, preserves remote changes)"
        echo "  2. Force push: Overwrite remote with your local version (will lose remote changes)"
        echo ""
        read -p "Do you want to FORCE PUSH and overwrite the remote? (y/n) " -n 1 -r
        echo ""
        
        if [[ $REPLY =~ ^[Yy]$ ]]; then
            echo -e "${YELLOW}⚠️  Force pushing to Hugging Face Spaces...${NC}"
            if git push hf main --force; then
                echo ""
                echo -e "${GREEN}βœ… Force deployment successful!${NC}"
                echo ""
                echo "Your app is being built at:"
                echo "$SPACE_URL"
                echo ""
                echo "Check the build logs at:"
                echo "$SPACE_URL?logs=build"
                echo ""
                echo "Once built, your app will be available at:"
                echo "$SPACE_URL"
            else
                echo ""
                echo -e "${RED}❌ Force push also failed. Check your permissions and network connection.${NC}"
                exit 1
            fi
        else
            echo ""
            echo -e "${YELLOW}Force push cancelled.${NC}"
            echo ""
            echo "To manually resolve, run:"
            echo "  git pull hf main"
            echo "  git push hf main"
            exit 1
        fi
    fi
else
    echo -e "${YELLOW}Deployment cancelled.${NC}"
    exit 0
fi