Spaces:
Sleeping
Sleeping
AKA Math commited on
Commit Β·
873ddfe
1
Parent(s): 9eaeb6f
Update app with dataset integration and improved UI
Browse files- .gitignore +5 -0
- DEPLOYMENT.md +19 -9
- QUICKSTART.md +7 -6
- deploy.sh +62 -12
.gitignore
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
/.streamlit/secrets.toml
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
# Byte-compiled / optimized / DLL files
|
| 4 |
__pycache__/
|
| 5 |
*.py[cod]
|
|
@@ -129,3 +133,4 @@ dmypy.json
|
|
| 129 |
|
| 130 |
# Pyre type checker
|
| 131 |
.pyre/
|
|
|
|
|
|
| 1 |
/.streamlit/secrets.toml
|
| 2 |
|
| 3 |
+
# Documentation (except README)
|
| 4 |
+
*.md
|
| 5 |
+
!README.md
|
| 6 |
+
|
| 7 |
# Byte-compiled / optimized / DLL files
|
| 8 |
__pycache__/
|
| 9 |
*.py[cod]
|
|
|
|
| 133 |
|
| 134 |
# Pyre type checker
|
| 135 |
.pyre/
|
| 136 |
+
DEPLOYMENT.md
|
DEPLOYMENT.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
| 2 |
|
| 3 |
This guide will walk you through deploying your Streamlit Image Registration app to Hugging Face Spaces using Docker.
|
| 4 |
|
|
|
|
|
|
|
| 5 |
## Prerequisites
|
| 6 |
|
| 7 |
1. A Hugging Face account (sign up at https://huggingface.co/join)
|
|
@@ -27,7 +29,7 @@ pip install huggingface_hub
|
|
| 27 |
### Login to Hugging Face
|
| 28 |
|
| 29 |
```bash
|
| 30 |
-
|
| 31 |
```
|
| 32 |
|
| 33 |
When prompted, paste your token. This will store your credentials in `~/.huggingface/token`.
|
|
@@ -71,11 +73,19 @@ Make sure your repository contains the following files:
|
|
| 71 |
|
| 72 |
### Required Files:
|
| 73 |
- β
`dockerfile` - Your Docker configuration (already created)
|
| 74 |
-
- β
`requirements.txt` - Python dependencies (already created)
|
| 75 |
-
- β
`image-registration-demo.py` - Your Streamlit app
|
| 76 |
-
- β
`rawimage.png` - The sample image used in the app
|
| 77 |
- β
`README.md` - Documentation for your Space
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
### Optional but Recommended:
|
| 80 |
- `.gitignore` - To exclude unnecessary files
|
| 81 |
- `LICENSE` - Your license file
|
|
@@ -162,8 +172,8 @@ Thumbs.db
|
|
| 162 |
|
| 163 |
```bash
|
| 164 |
# Make sure all your files are committed
|
| 165 |
-
git add dockerfile requirements.txt image-registration-demo.py
|
| 166 |
-
git commit -m "Initial deployment to Hugging Face Spaces"
|
| 167 |
|
| 168 |
# Push to Hugging Face (assuming you added the remote in Step 3)
|
| 169 |
git push hf main
|
|
@@ -285,13 +295,13 @@ jobs:
|
|
| 285 |
|
| 286 |
```bash
|
| 287 |
# Check Space status
|
| 288 |
-
|
| 289 |
|
| 290 |
# View Space logs (if available via CLI)
|
| 291 |
-
|
| 292 |
|
| 293 |
# Delete and recreate Space (careful!)
|
| 294 |
-
|
| 295 |
```
|
| 296 |
|
| 297 |
## Resources
|
|
|
|
| 2 |
|
| 3 |
This guide will walk you through deploying your Streamlit Image Registration app to Hugging Face Spaces using Docker.
|
| 4 |
|
| 5 |
+
**Note**: This app loads images from a Hugging Face dataset (`amithjkamath/exampleimages`) instead of bundling them with the Space, which allows you to avoid the binary file restrictions on Hugging Face Spaces.
|
| 6 |
+
|
| 7 |
## Prerequisites
|
| 8 |
|
| 9 |
1. A Hugging Face account (sign up at https://huggingface.co/join)
|
|
|
|
| 29 |
### Login to Hugging Face
|
| 30 |
|
| 31 |
```bash
|
| 32 |
+
hf auth login
|
| 33 |
```
|
| 34 |
|
| 35 |
When prompted, paste your token. This will store your credentials in `~/.huggingface/token`.
|
|
|
|
| 73 |
|
| 74 |
### Required Files:
|
| 75 |
- β
`dockerfile` - Your Docker configuration (already created)
|
| 76 |
+
- β
`requirements.txt` - Python dependencies (already created, includes `datasets` library)
|
| 77 |
+
- β
`image-registration-demo.py` - Your Streamlit app (updated to load from HF dataset)
|
|
|
|
| 78 |
- β
`README.md` - Documentation for your Space
|
| 79 |
|
| 80 |
+
### β οΈ Important: Image Dataset
|
| 81 |
+
This app loads images from a separate Hugging Face dataset: `amithjkamath/exampleimages`
|
| 82 |
+
|
| 83 |
+
**Why?** Hugging Face Spaces with the blank Docker template don't support binary files like images in the repository. By loading images from a dataset, we circumvent this limitation.
|
| 84 |
+
|
| 85 |
+
**Your dataset**: https://huggingface.co/datasets/amithjkamath/exampleimages
|
| 86 |
+
|
| 87 |
+
The app will automatically download images from this dataset when it starts. Make sure the dataset is public or set up proper authentication if it's private.
|
| 88 |
+
|
| 89 |
### Optional but Recommended:
|
| 90 |
- `.gitignore` - To exclude unnecessary files
|
| 91 |
- `LICENSE` - Your license file
|
|
|
|
| 172 |
|
| 173 |
```bash
|
| 174 |
# Make sure all your files are committed
|
| 175 |
+
git add dockerfile requirements.txt image-registration-demo.py README.md
|
| 176 |
+
git commit -m "Initial deployment to Hugging Face Spaces with dataset integration"
|
| 177 |
|
| 178 |
# Push to Hugging Face (assuming you added the remote in Step 3)
|
| 179 |
git push hf main
|
|
|
|
| 295 |
|
| 296 |
```bash
|
| 297 |
# Check Space status
|
| 298 |
+
hf repo info amithkamath/image-registration --repo-type space
|
| 299 |
|
| 300 |
# View Space logs (if available via CLI)
|
| 301 |
+
hf repo logs amithkamath/image-registration --repo-type space
|
| 302 |
|
| 303 |
# Delete and recreate Space (careful!)
|
| 304 |
+
hf repo delete amithkamath/image-registration --repo-type space
|
| 305 |
```
|
| 306 |
|
| 307 |
## Resources
|
QUICKSTART.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
| 7 |
pip install huggingface_hub
|
| 8 |
|
| 9 |
# 2. Login with your token
|
| 10 |
-
|
| 11 |
|
| 12 |
# 3. Run the deployment script
|
| 13 |
./deploy.sh
|
|
@@ -19,7 +19,7 @@ huggingface-cli login
|
|
| 19 |
|
| 20 |
```bash
|
| 21 |
# 1. Login to Hugging Face
|
| 22 |
-
|
| 23 |
|
| 24 |
# 2. Add Hugging Face remote
|
| 25 |
git remote add hf https://huggingface.co/spaces/amithkamath/image-registration
|
|
@@ -79,7 +79,7 @@ Then set as environment variable in Space settings.
|
|
| 79 |
## π Common Issues
|
| 80 |
|
| 81 |
### "Authentication failed"
|
| 82 |
-
β Run `
|
| 83 |
|
| 84 |
### "Build failed"
|
| 85 |
β Check logs at the Space URL, verify dockerfile and requirements.txt
|
|
@@ -94,11 +94,12 @@ Then set as environment variable in Space settings.
|
|
| 94 |
|
| 95 |
Ensure these files are in your repo:
|
| 96 |
- β
`dockerfile` - Docker configuration
|
| 97 |
-
- β
`requirements.txt` - Python dependencies
|
| 98 |
-
- β
`image-registration-demo.py` - Your Streamlit app
|
| 99 |
-
- β
`rawimage.png` - Sample image
|
| 100 |
- β
`README.md` - With Hugging Face metadata
|
| 101 |
|
|
|
|
|
|
|
| 102 |
## π Update Workflow
|
| 103 |
|
| 104 |
```bash
|
|
|
|
| 7 |
pip install huggingface_hub
|
| 8 |
|
| 9 |
# 2. Login with your token
|
| 10 |
+
hf auth login
|
| 11 |
|
| 12 |
# 3. Run the deployment script
|
| 13 |
./deploy.sh
|
|
|
|
| 19 |
|
| 20 |
```bash
|
| 21 |
# 1. Login to Hugging Face
|
| 22 |
+
hf auth login
|
| 23 |
|
| 24 |
# 2. Add Hugging Face remote
|
| 25 |
git remote add hf https://huggingface.co/spaces/amithkamath/image-registration
|
|
|
|
| 79 |
## π Common Issues
|
| 80 |
|
| 81 |
### "Authentication failed"
|
| 82 |
+
β Run `hf auth login` again with a valid token
|
| 83 |
|
| 84 |
### "Build failed"
|
| 85 |
β Check logs at the Space URL, verify dockerfile and requirements.txt
|
|
|
|
| 94 |
|
| 95 |
Ensure these files are in your repo:
|
| 96 |
- β
`dockerfile` - Docker configuration
|
| 97 |
+
- β
`requirements.txt` - Python dependencies (includes `datasets` library)
|
| 98 |
+
- β
`image-registration-demo.py` - Your Streamlit app (loads from HF dataset)
|
|
|
|
| 99 |
- β
`README.md` - With Hugging Face metadata
|
| 100 |
|
| 101 |
+
**Note**: Images are loaded from the HF dataset `amithjkamath/exampleimages`, not from local files. This avoids binary file restrictions on Hugging Face Spaces.
|
| 102 |
+
|
| 103 |
## π Update Workflow
|
| 104 |
|
| 105 |
```bash
|
deploy.sh
CHANGED
|
@@ -15,17 +15,17 @@ YELLOW='\033[1;33m'
|
|
| 15 |
RED='\033[0;31m'
|
| 16 |
NC='\033[0m' # No Color
|
| 17 |
|
| 18 |
-
# Check if
|
| 19 |
-
if ! command -v
|
| 20 |
echo -e "${YELLOW}β οΈ Hugging Face CLI not found. Installing...${NC}"
|
| 21 |
pip install huggingface_hub
|
| 22 |
fi
|
| 23 |
|
| 24 |
# Check if logged in
|
| 25 |
-
if !
|
| 26 |
echo -e "${YELLOW}β οΈ Not logged in to Hugging Face${NC}"
|
| 27 |
echo "Please login with your Hugging Face token:"
|
| 28 |
-
|
| 29 |
fi
|
| 30 |
|
| 31 |
echo -e "${GREEN}β
Hugging Face CLI ready${NC}"
|
|
@@ -49,7 +49,10 @@ fi
|
|
| 49 |
|
| 50 |
echo ""
|
| 51 |
echo "Files to be deployed:"
|
| 52 |
-
git ls-files | grep -E "(dockerfile|requirements\.txt|.*\.py|
|
|
|
|
|
|
|
|
|
|
| 53 |
echo ""
|
| 54 |
|
| 55 |
# Confirm deployment
|
|
@@ -59,16 +62,24 @@ echo ""
|
|
| 59 |
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
| 60 |
echo -e "${YELLOW}π¦ Preparing deployment...${NC}"
|
| 61 |
|
| 62 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
if ! git diff-index --quiet HEAD --; then
|
| 64 |
-
echo -e "${YELLOW}β οΈ
|
| 65 |
-
git
|
| 66 |
-
|
|
|
|
| 67 |
fi
|
| 68 |
|
| 69 |
echo -e "${YELLOW}π Pushing to Hugging Face Spaces...${NC}"
|
| 70 |
|
| 71 |
-
#
|
| 72 |
if git push hf main; then
|
| 73 |
echo ""
|
| 74 |
echo -e "${GREEN}β
Deployment successful!${NC}"
|
|
@@ -83,8 +94,47 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
| 83 |
echo "$SPACE_URL"
|
| 84 |
else
|
| 85 |
echo ""
|
| 86 |
-
echo -e "${RED}β
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
fi
|
| 89 |
else
|
| 90 |
echo -e "${YELLOW}Deployment cancelled.${NC}"
|
|
|
|
| 15 |
RED='\033[0;31m'
|
| 16 |
NC='\033[0m' # No Color
|
| 17 |
|
| 18 |
+
# Check if hf CLI is installed
|
| 19 |
+
if ! command -v hf &> /dev/null; then
|
| 20 |
echo -e "${YELLOW}β οΈ Hugging Face CLI not found. Installing...${NC}"
|
| 21 |
pip install huggingface_hub
|
| 22 |
fi
|
| 23 |
|
| 24 |
# Check if logged in
|
| 25 |
+
if ! hf whoami &> /dev/null; then
|
| 26 |
echo -e "${YELLOW}β οΈ Not logged in to Hugging Face${NC}"
|
| 27 |
echo "Please login with your Hugging Face token:"
|
| 28 |
+
hf auth login
|
| 29 |
fi
|
| 30 |
|
| 31 |
echo -e "${GREEN}β
Hugging Face CLI ready${NC}"
|
|
|
|
| 49 |
|
| 50 |
echo ""
|
| 51 |
echo "Files to be deployed:"
|
| 52 |
+
git ls-files | grep -E "(dockerfile|requirements\.txt|.*\.py|README\.md|LICENSE)"
|
| 53 |
+
echo ""
|
| 54 |
+
echo "π Note: Images are loaded from HF dataset (amithjkamath/exampleimages)"
|
| 55 |
+
echo " No need to include rawimage.png or other binary files"
|
| 56 |
echo ""
|
| 57 |
|
| 58 |
# Confirm deployment
|
|
|
|
| 62 |
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
| 63 |
echo -e "${YELLOW}π¦ Preparing deployment...${NC}"
|
| 64 |
|
| 65 |
+
# Add all essential files for the Space
|
| 66 |
+
echo "Adding files to git..."
|
| 67 |
+
git add dockerfile requirements.txt image-registration-demo.py README.md LICENSE .gitignore 2>/dev/null || true
|
| 68 |
+
|
| 69 |
+
# Remove deleted files (like rawimage.png)
|
| 70 |
+
git add -u 2>/dev/null || true
|
| 71 |
+
|
| 72 |
+
# Check if there are changes to commit
|
| 73 |
if ! git diff-index --quiet HEAD --; then
|
| 74 |
+
echo -e "${YELLOW}β οΈ Committing changes...${NC}"
|
| 75 |
+
git commit -m "Deploy to Hugging Face Spaces - updated app with dataset integration"
|
| 76 |
+
else
|
| 77 |
+
echo -e "${GREEN}β
No new changes to commit${NC}"
|
| 78 |
fi
|
| 79 |
|
| 80 |
echo -e "${YELLOW}π Pushing to Hugging Face Spaces...${NC}"
|
| 81 |
|
| 82 |
+
# Try to push to Hugging Face
|
| 83 |
if git push hf main; then
|
| 84 |
echo ""
|
| 85 |
echo -e "${GREEN}β
Deployment successful!${NC}"
|
|
|
|
| 94 |
echo "$SPACE_URL"
|
| 95 |
else
|
| 96 |
echo ""
|
| 97 |
+
echo -e "${RED}β Push failed. The remote branch has changes that aren't in your local branch.${NC}"
|
| 98 |
+
echo ""
|
| 99 |
+
echo "This typically happens when:"
|
| 100 |
+
echo " - The Space was modified directly on Hugging Face"
|
| 101 |
+
echo " - You're deploying from a different machine"
|
| 102 |
+
echo ""
|
| 103 |
+
echo -e "${YELLOW}Options:${NC}"
|
| 104 |
+
echo " 1. Pull and merge: git pull hf main (safer, preserves remote changes)"
|
| 105 |
+
echo " 2. Force push: Overwrite remote with your local version (will lose remote changes)"
|
| 106 |
+
echo ""
|
| 107 |
+
read -p "Do you want to FORCE PUSH and overwrite the remote? (y/n) " -n 1 -r
|
| 108 |
+
echo ""
|
| 109 |
+
|
| 110 |
+
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
| 111 |
+
echo -e "${YELLOW}β οΈ Force pushing to Hugging Face Spaces...${NC}"
|
| 112 |
+
if git push hf main --force; then
|
| 113 |
+
echo ""
|
| 114 |
+
echo -e "${GREEN}β
Force deployment successful!${NC}"
|
| 115 |
+
echo ""
|
| 116 |
+
echo "Your app is being built at:"
|
| 117 |
+
echo "$SPACE_URL"
|
| 118 |
+
echo ""
|
| 119 |
+
echo "Check the build logs at:"
|
| 120 |
+
echo "$SPACE_URL?logs=build"
|
| 121 |
+
echo ""
|
| 122 |
+
echo "Once built, your app will be available at:"
|
| 123 |
+
echo "$SPACE_URL"
|
| 124 |
+
else
|
| 125 |
+
echo ""
|
| 126 |
+
echo -e "${RED}β Force push also failed. Check your permissions and network connection.${NC}"
|
| 127 |
+
exit 1
|
| 128 |
+
fi
|
| 129 |
+
else
|
| 130 |
+
echo ""
|
| 131 |
+
echo -e "${YELLOW}Force push cancelled.${NC}"
|
| 132 |
+
echo ""
|
| 133 |
+
echo "To manually resolve, run:"
|
| 134 |
+
echo " git pull hf main"
|
| 135 |
+
echo " git push hf main"
|
| 136 |
+
exit 1
|
| 137 |
+
fi
|
| 138 |
fi
|
| 139 |
else
|
| 140 |
echo -e "${YELLOW}Deployment cancelled.${NC}"
|