Spaces:
Sleeping
Sleeping
AKA Math
commited on
Commit
Β·
f66259a
1
Parent(s):
787d68a
adding hf deployment
Browse files- DEPLOYMENT.md +309 -0
- QUICKSTART.md +143 -0
- README.md +10 -0
- deploy.sh +92 -0
- dockerfile +42 -0
- pyproject.toml +12 -0
- requirements.txt +4 -4
- uv.lock +0 -0
DEPLOYMENT.md
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deploying to Hugging Face Spaces - Complete Guide
|
| 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)
|
| 8 |
+
2. Git installed on your local machine
|
| 9 |
+
3. Your Space already created at: https://huggingface.co/spaces/amithkamath/image-registration
|
| 10 |
+
|
| 11 |
+
## Step 1: Set Up Hugging Face CLI and Authentication
|
| 12 |
+
|
| 13 |
+
### Install Hugging Face CLI
|
| 14 |
+
```bash
|
| 15 |
+
pip install huggingface_hub
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
### Create a Hugging Face Token
|
| 19 |
+
|
| 20 |
+
1. Go to https://huggingface.co/settings/tokens
|
| 21 |
+
2. Click on "New token"
|
| 22 |
+
3. Give it a descriptive name (e.g., "image-registration-deploy")
|
| 23 |
+
4. Select "Write" access (required for pushing to your Space)
|
| 24 |
+
5. Click "Generate token"
|
| 25 |
+
6. **Important**: Copy and save this token securely - you won't be able to see it again!
|
| 26 |
+
|
| 27 |
+
### Login to Hugging Face
|
| 28 |
+
|
| 29 |
+
```bash
|
| 30 |
+
huggingface-cli login
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
When prompted, paste your token. This will store your credentials in `~/.huggingface/token`.
|
| 34 |
+
|
| 35 |
+
Alternatively, you can set it as an environment variable:
|
| 36 |
+
```bash
|
| 37 |
+
export HF_TOKEN=your_token_here
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
## Step 2: Configure Git for Hugging Face
|
| 41 |
+
|
| 42 |
+
Hugging Face Spaces uses Git LFS (Large File Storage) for large files. Set up Git LFS:
|
| 43 |
+
|
| 44 |
+
```bash
|
| 45 |
+
# Install git-lfs if you haven't already
|
| 46 |
+
# On macOS:
|
| 47 |
+
brew install git-lfs
|
| 48 |
+
|
| 49 |
+
# Initialize git-lfs
|
| 50 |
+
git lfs install
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
## Step 3: Clone Your Hugging Face Space
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
# Clone your space repository
|
| 57 |
+
git clone https://huggingface.co/spaces/amithkamath/image-registration
|
| 58 |
+
cd image-registration
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
Alternatively, if you want to push from your existing local repository:
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
# In your current repo directory
|
| 65 |
+
git remote add hf https://huggingface.co/spaces/amithkamath/image-registration
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## Step 4: Prepare Your Files
|
| 69 |
+
|
| 70 |
+
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
|
| 82 |
+
|
| 83 |
+
### Create a README.md for Hugging Face Space
|
| 84 |
+
|
| 85 |
+
Create or update your `README.md` with proper metadata at the top:
|
| 86 |
+
|
| 87 |
+
```markdown
|
| 88 |
+
---
|
| 89 |
+
title: Image Registration Demo
|
| 90 |
+
emoji: π
|
| 91 |
+
colorFrom: blue
|
| 92 |
+
colorTo: green
|
| 93 |
+
sdk: docker
|
| 94 |
+
pinned: false
|
| 95 |
+
license: mit
|
| 96 |
+
---
|
| 97 |
+
|
| 98 |
+
# Image Registration Demo
|
| 99 |
+
|
| 100 |
+
This is a demonstration of how transformation matrices affect registration for the affine case.
|
| 101 |
+
|
| 102 |
+
[Rest of your existing README content...]
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## Step 5: Set Up Secrets (for Password Protection)
|
| 106 |
+
|
| 107 |
+
Your app uses `st.secrets` for password protection. You need to set this up in Hugging Face Spaces:
|
| 108 |
+
|
| 109 |
+
1. Go to your Space settings: https://huggingface.co/spaces/amithkamath/image-registration/settings
|
| 110 |
+
2. Scroll down to "Repository secrets"
|
| 111 |
+
3. Add secrets as needed
|
| 112 |
+
|
| 113 |
+
For Streamlit secrets, create a `.streamlit/secrets.toml` file locally (DO NOT commit this to git):
|
| 114 |
+
|
| 115 |
+
```toml
|
| 116 |
+
[passwords]
|
| 117 |
+
username1 = "password1"
|
| 118 |
+
username2 = "password2"
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
Then in Hugging Face Space settings, add each secret:
|
| 122 |
+
- Key: `STREAMLIT_SECRETS`
|
| 123 |
+
- Value: The entire contents of your `secrets.toml` file
|
| 124 |
+
|
| 125 |
+
Alternatively, you can mount secrets as environment variables and modify your app to read from environment variables instead.
|
| 126 |
+
|
| 127 |
+
## Step 6: Update .gitignore
|
| 128 |
+
|
| 129 |
+
Create or update `.gitignore` to exclude sensitive and unnecessary files:
|
| 130 |
+
|
| 131 |
+
```
|
| 132 |
+
# Python
|
| 133 |
+
__pycache__/
|
| 134 |
+
*.py[cod]
|
| 135 |
+
*$py.class
|
| 136 |
+
*.so
|
| 137 |
+
.Python
|
| 138 |
+
env/
|
| 139 |
+
venv/
|
| 140 |
+
.venv
|
| 141 |
+
|
| 142 |
+
# Streamlit
|
| 143 |
+
.streamlit/secrets.toml
|
| 144 |
+
|
| 145 |
+
# IDE
|
| 146 |
+
.vscode/
|
| 147 |
+
.idea/
|
| 148 |
+
*.swp
|
| 149 |
+
*.swo
|
| 150 |
+
|
| 151 |
+
# OS
|
| 152 |
+
.DS_Store
|
| 153 |
+
Thumbs.db
|
| 154 |
+
|
| 155 |
+
# Other
|
| 156 |
+
*.log
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
## Step 7: Deploy to Hugging Face Spaces
|
| 160 |
+
|
| 161 |
+
### Method A: Push from Your Existing Repository
|
| 162 |
+
|
| 163 |
+
```bash
|
| 164 |
+
# Make sure all your files are committed
|
| 165 |
+
git add dockerfile requirements.txt image-registration-demo.py rawimage.png README.md
|
| 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
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
### Method B: Clone and Deploy
|
| 173 |
+
|
| 174 |
+
If you cloned the HF space in Step 3:
|
| 175 |
+
|
| 176 |
+
```bash
|
| 177 |
+
# Copy your files to the cloned space directory
|
| 178 |
+
cp /path/to/your/repo/* /path/to/cloned/space/
|
| 179 |
+
|
| 180 |
+
# Add and commit
|
| 181 |
+
git add .
|
| 182 |
+
git commit -m "Deploy Streamlit app with Docker"
|
| 183 |
+
|
| 184 |
+
# Push to Hugging Face
|
| 185 |
+
git push origin main
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
### Method C: Using Hugging Face Hub Python API
|
| 189 |
+
|
| 190 |
+
```python
|
| 191 |
+
from huggingface_hub import HfApi
|
| 192 |
+
|
| 193 |
+
api = HfApi()
|
| 194 |
+
|
| 195 |
+
# Upload files
|
| 196 |
+
api.upload_folder(
|
| 197 |
+
folder_path=".",
|
| 198 |
+
repo_id="amithkamath/image-registration",
|
| 199 |
+
repo_type="space",
|
| 200 |
+
ignore_patterns=[".git/*", "__pycache__/*", ".streamlit/secrets.toml"]
|
| 201 |
+
)
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
## Step 8: Monitor Deployment
|
| 205 |
+
|
| 206 |
+
1. Go to your Space: https://huggingface.co/spaces/amithkamath/image-registration
|
| 207 |
+
2. Click on the "Logs" tab to see build progress
|
| 208 |
+
3. The build process will:
|
| 209 |
+
- Build your Docker image
|
| 210 |
+
- Install dependencies
|
| 211 |
+
- Start your Streamlit app
|
| 212 |
+
4. Once completed, your app will be available at the Space URL
|
| 213 |
+
|
| 214 |
+
## Step 9: Troubleshooting
|
| 215 |
+
|
| 216 |
+
### Build Fails
|
| 217 |
+
- Check the logs in the "Logs" tab
|
| 218 |
+
- Verify all dependencies are correctly specified in `requirements.txt`
|
| 219 |
+
- Ensure the Dockerfile syntax is correct
|
| 220 |
+
|
| 221 |
+
### App Doesn't Start
|
| 222 |
+
- Check if the correct port (7860) is being used
|
| 223 |
+
- Verify the CMD in Dockerfile is correct
|
| 224 |
+
- Check for Python errors in the logs
|
| 225 |
+
|
| 226 |
+
### Secrets Not Working
|
| 227 |
+
- Ensure secrets are properly set in Space settings
|
| 228 |
+
- Verify the app can access them correctly
|
| 229 |
+
|
| 230 |
+
### Image Not Found
|
| 231 |
+
- Make sure `rawimage.png` is committed and pushed to the repository
|
| 232 |
+
- Check file paths are correct (relative to the working directory)
|
| 233 |
+
|
| 234 |
+
## Step 10: Update Your Deployment
|
| 235 |
+
|
| 236 |
+
When you want to update your app:
|
| 237 |
+
|
| 238 |
+
```bash
|
| 239 |
+
# Make changes locally
|
| 240 |
+
git add .
|
| 241 |
+
git commit -m "Description of changes"
|
| 242 |
+
git push hf main
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
The Space will automatically rebuild and redeploy.
|
| 246 |
+
|
| 247 |
+
## Advanced: Continuous Deployment from GitHub
|
| 248 |
+
|
| 249 |
+
If you want to maintain your code on GitHub and automatically deploy to Hugging Face:
|
| 250 |
+
|
| 251 |
+
1. Keep your main repository on GitHub
|
| 252 |
+
2. Set up a GitHub Action to push to Hugging Face on every commit to main
|
| 253 |
+
3. Create `.github/workflows/deploy-to-hf.yml`:
|
| 254 |
+
|
| 255 |
+
```yaml
|
| 256 |
+
name: Deploy to Hugging Face Spaces
|
| 257 |
+
|
| 258 |
+
on:
|
| 259 |
+
push:
|
| 260 |
+
branches:
|
| 261 |
+
- main
|
| 262 |
+
|
| 263 |
+
jobs:
|
| 264 |
+
sync:
|
| 265 |
+
runs-on: ubuntu-latest
|
| 266 |
+
steps:
|
| 267 |
+
- uses: actions/checkout@v3
|
| 268 |
+
with:
|
| 269 |
+
fetch-depth: 0
|
| 270 |
+
lfs: true
|
| 271 |
+
|
| 272 |
+
- name: Push to Hugging Face Space
|
| 273 |
+
env:
|
| 274 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 275 |
+
run: |
|
| 276 |
+
git config --global user.email "github-actions@github.com"
|
| 277 |
+
git config --global user.name "GitHub Actions"
|
| 278 |
+
git remote add hf https://amithkamath:$HF_TOKEN@huggingface.co/spaces/amithkamath/image-registration
|
| 279 |
+
git push hf main --force
|
| 280 |
+
```
|
| 281 |
+
|
| 282 |
+
4. Add your HF_TOKEN as a secret in your GitHub repository settings
|
| 283 |
+
|
| 284 |
+
## Useful Commands
|
| 285 |
+
|
| 286 |
+
```bash
|
| 287 |
+
# Check Space status
|
| 288 |
+
huggingface-cli repo info amithkamath/image-registration --repo-type space
|
| 289 |
+
|
| 290 |
+
# View Space logs (if available via CLI)
|
| 291 |
+
huggingface-cli repo logs amithkamath/image-registration --repo-type space
|
| 292 |
+
|
| 293 |
+
# Delete and recreate Space (careful!)
|
| 294 |
+
huggingface-cli repo delete amithkamath/image-registration --repo-type space
|
| 295 |
+
```
|
| 296 |
+
|
| 297 |
+
## Resources
|
| 298 |
+
|
| 299 |
+
- [Hugging Face Spaces Docker Documentation](https://huggingface.co/docs/hub/spaces-sdks-docker)
|
| 300 |
+
- [Hugging Face Spaces Overview](https://huggingface.co/docs/hub/spaces-overview)
|
| 301 |
+
- [Streamlit Documentation](https://docs.streamlit.io/)
|
| 302 |
+
- [Git LFS Documentation](https://git-lfs.github.com/)
|
| 303 |
+
|
| 304 |
+
## Support
|
| 305 |
+
|
| 306 |
+
If you encounter issues:
|
| 307 |
+
1. Check the [Hugging Face Forums](https://discuss.huggingface.co/)
|
| 308 |
+
2. Review the [Spaces FAQ](https://huggingface.co/docs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| 5 |
+
```bash
|
| 6 |
+
# 1. Install Hugging Face CLI
|
| 7 |
+
pip install huggingface_hub
|
| 8 |
+
|
| 9 |
+
# 2. Login with your token
|
| 10 |
+
huggingface-cli login
|
| 11 |
+
|
| 12 |
+
# 3. Run the deployment script
|
| 13 |
+
./deploy.sh
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
## π Manual Deployment Steps
|
| 17 |
+
|
| 18 |
+
### First Time Setup
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
# 1. Login to Hugging Face
|
| 22 |
+
huggingface-cli login
|
| 23 |
+
|
| 24 |
+
# 2. Add Hugging Face remote
|
| 25 |
+
git remote add hf https://huggingface.co/spaces/amithkamath/image-registration
|
| 26 |
+
|
| 27 |
+
# 3. Push to deploy
|
| 28 |
+
git push hf main
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
### Subsequent Deployments
|
| 32 |
+
|
| 33 |
+
```bash
|
| 34 |
+
# 1. Commit your changes
|
| 35 |
+
git add .
|
| 36 |
+
git commit -m "Your update message"
|
| 37 |
+
|
| 38 |
+
# 2. Push to deploy
|
| 39 |
+
git push hf main
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
## π Getting Your Hugging Face Token
|
| 43 |
+
|
| 44 |
+
1. Go to: https://huggingface.co/settings/tokens
|
| 45 |
+
2. Click "New token"
|
| 46 |
+
3. Name: "image-registration-deploy"
|
| 47 |
+
4. Access: **Write**
|
| 48 |
+
5. Click "Generate token"
|
| 49 |
+
6. Copy and save the token
|
| 50 |
+
|
| 51 |
+
## π Setting Up Secrets (Password Protection)
|
| 52 |
+
|
| 53 |
+
Your app uses password protection. You need to configure secrets:
|
| 54 |
+
|
| 55 |
+
### Option 1: Via Hugging Face UI (Recommended)
|
| 56 |
+
|
| 57 |
+
1. Go to: https://huggingface.co/spaces/amithkamath/image-registration/settings
|
| 58 |
+
2. Scroll to "Repository secrets"
|
| 59 |
+
3. Add secrets for your usernames/passwords
|
| 60 |
+
|
| 61 |
+
### Option 2: Create secrets.toml file
|
| 62 |
+
|
| 63 |
+
Create `.streamlit/secrets.toml` (locally, DO NOT commit):
|
| 64 |
+
|
| 65 |
+
```toml
|
| 66 |
+
[passwords]
|
| 67 |
+
your_username = "your_password"
|
| 68 |
+
another_user = "another_password"
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
Then set as environment variable in Space settings.
|
| 72 |
+
|
| 73 |
+
## π Monitoring Your Deployment
|
| 74 |
+
|
| 75 |
+
- **Space URL**: https://huggingface.co/spaces/amithkamath/image-registration
|
| 76 |
+
- **Build Logs**: https://huggingface.co/spaces/amithkamath/image-registration?logs=build
|
| 77 |
+
- **Settings**: https://huggingface.co/spaces/amithkamath/image-registration/settings
|
| 78 |
+
|
| 79 |
+
## π Common Issues
|
| 80 |
+
|
| 81 |
+
### "Authentication failed"
|
| 82 |
+
β Run `huggingface-cli login` again with a valid token
|
| 83 |
+
|
| 84 |
+
### "Build failed"
|
| 85 |
+
β Check logs at the Space URL, verify dockerfile and requirements.txt
|
| 86 |
+
|
| 87 |
+
### "App doesn't start"
|
| 88 |
+
β Ensure port 7860 is used and Streamlit command is correct in dockerfile
|
| 89 |
+
|
| 90 |
+
### "Secrets not working"
|
| 91 |
+
β Verify secrets are set in Space settings, check key names match your code
|
| 92 |
+
|
| 93 |
+
## π Required Files
|
| 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
|
| 105 |
+
# 1. Make changes to your code
|
| 106 |
+
vim image-registration-demo.py
|
| 107 |
+
|
| 108 |
+
# 2. Test locally
|
| 109 |
+
streamlit run image-registration-demo.py
|
| 110 |
+
|
| 111 |
+
# 3. Commit and push
|
| 112 |
+
git add .
|
| 113 |
+
git commit -m "Update: description"
|
| 114 |
+
git push hf main
|
| 115 |
+
|
| 116 |
+
# 4. Monitor deployment
|
| 117 |
+
# Visit: https://huggingface.co/spaces/amithkamath/image-registration
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
## π οΈ Testing Locally with Docker
|
| 121 |
+
|
| 122 |
+
Before deploying, test your Docker setup locally:
|
| 123 |
+
|
| 124 |
+
```bash
|
| 125 |
+
# Build the image
|
| 126 |
+
docker build -t image-registration .
|
| 127 |
+
|
| 128 |
+
# Run the container
|
| 129 |
+
docker run -p 7860:7860 image-registration
|
| 130 |
+
|
| 131 |
+
# Open browser
|
| 132 |
+
open http://localhost:7860
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
## π Full Documentation
|
| 136 |
+
|
| 137 |
+
For detailed instructions, see: [DEPLOYMENT.md](./DEPLOYMENT.md)
|
| 138 |
+
|
| 139 |
+
## π Need Help?
|
| 140 |
+
|
| 141 |
+
- [Hugging Face Spaces Docs](https://huggingface.co/docs/hub/spaces-sdks-docker)
|
| 142 |
+
- [Hugging Face Forums](https://discuss.huggingface.co/)
|
| 143 |
+
- [Streamlit Docs](https://docs.streamlit.io/)
|
README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# image-registration
|
| 2 |
|
| 3 |
This is a demonstration of how transformation matrices affect registration for the affine case.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Image Registration Demo
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
# image-registration
|
| 12 |
|
| 13 |
This is a demonstration of how transformation matrices affect registration for the affine case.
|
deploy.sh
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Quick deployment script for Hugging Face Spaces
|
| 4 |
+
# This script helps you deploy your Streamlit app to Hugging Face Spaces
|
| 5 |
+
|
| 6 |
+
set -e
|
| 7 |
+
|
| 8 |
+
echo "π Hugging Face Spaces Deployment Script"
|
| 9 |
+
echo "=========================================="
|
| 10 |
+
echo ""
|
| 11 |
+
|
| 12 |
+
# Colors for output
|
| 13 |
+
GREEN='\033[0;32m'
|
| 14 |
+
YELLOW='\033[1;33m'
|
| 15 |
+
RED='\033[0;31m'
|
| 16 |
+
NC='\033[0m' # No Color
|
| 17 |
+
|
| 18 |
+
# Check if huggingface-cli is installed
|
| 19 |
+
if ! command -v huggingface-cli &> /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 ! huggingface-cli 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 |
+
huggingface-cli login
|
| 29 |
+
fi
|
| 30 |
+
|
| 31 |
+
echo -e "${GREEN}β
Hugging Face CLI ready${NC}"
|
| 32 |
+
echo ""
|
| 33 |
+
|
| 34 |
+
# Space details
|
| 35 |
+
SPACE_ID="amithkamath/image-registration"
|
| 36 |
+
SPACE_URL="https://huggingface.co/spaces/$SPACE_ID"
|
| 37 |
+
|
| 38 |
+
echo "Target Space: $SPACE_ID"
|
| 39 |
+
echo "Space URL: $SPACE_URL"
|
| 40 |
+
echo ""
|
| 41 |
+
|
| 42 |
+
# Check if remote exists
|
| 43 |
+
if git remote | grep -q "^hf$"; then
|
| 44 |
+
echo -e "${GREEN}β
Hugging Face remote already configured${NC}"
|
| 45 |
+
else
|
| 46 |
+
echo -e "${YELLOW}β οΈ Adding Hugging Face remote...${NC}"
|
| 47 |
+
git remote add hf "https://huggingface.co/spaces/$SPACE_ID"
|
| 48 |
+
fi
|
| 49 |
+
|
| 50 |
+
echo ""
|
| 51 |
+
echo "Files to be deployed:"
|
| 52 |
+
git ls-files | grep -E "(dockerfile|requirements\.txt|.*\.py|.*\.png|README\.md|LICENSE)"
|
| 53 |
+
echo ""
|
| 54 |
+
|
| 55 |
+
# Confirm deployment
|
| 56 |
+
read -p "Do you want to deploy these files to $SPACE_ID? (y/n) " -n 1 -r
|
| 57 |
+
echo ""
|
| 58 |
+
|
| 59 |
+
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
| 60 |
+
echo -e "${YELLOW}π¦ Preparing deployment...${NC}"
|
| 61 |
+
|
| 62 |
+
# Check if there are uncommitted changes
|
| 63 |
+
if ! git diff-index --quiet HEAD --; then
|
| 64 |
+
echo -e "${YELLOW}β οΈ You have uncommitted changes. Committing them...${NC}"
|
| 65 |
+
git add dockerfile requirements.txt image-registration-demo.py rawimage.png README.md LICENSE 2>/dev/null || true
|
| 66 |
+
git commit -m "Deploy to Hugging Face Spaces"
|
| 67 |
+
fi
|
| 68 |
+
|
| 69 |
+
echo -e "${YELLOW}π Pushing to Hugging Face Spaces...${NC}"
|
| 70 |
+
|
| 71 |
+
# Push to Hugging Face
|
| 72 |
+
if git push hf main; then
|
| 73 |
+
echo ""
|
| 74 |
+
echo -e "${GREEN}β
Deployment successful!${NC}"
|
| 75 |
+
echo ""
|
| 76 |
+
echo "Your app is being built at:"
|
| 77 |
+
echo "$SPACE_URL"
|
| 78 |
+
echo ""
|
| 79 |
+
echo "Check the build logs at:"
|
| 80 |
+
echo "$SPACE_URL?logs=build"
|
| 81 |
+
echo ""
|
| 82 |
+
echo "Once built, your app will be available at:"
|
| 83 |
+
echo "$SPACE_URL"
|
| 84 |
+
else
|
| 85 |
+
echo ""
|
| 86 |
+
echo -e "${RED}β Deployment failed. Check the error messages above.${NC}"
|
| 87 |
+
exit 1
|
| 88 |
+
fi
|
| 89 |
+
else
|
| 90 |
+
echo -e "${YELLOW}Deployment cancelled.${NC}"
|
| 91 |
+
exit 0
|
| 92 |
+
fi
|
dockerfile
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# Dockerfile for Streamlit Image Registration Demo
|
| 3 |
+
|
| 4 |
+
FROM python:3.11-slim
|
| 5 |
+
|
| 6 |
+
# Install system dependencies required for OpenCV
|
| 7 |
+
RUN apt-get update && apt-get install -y \
|
| 8 |
+
freeglut3-dev \
|
| 9 |
+
libgtk2.0-dev \
|
| 10 |
+
libgl1-mesa-glx \
|
| 11 |
+
libglib2.0-0 \
|
| 12 |
+
libsm6 \
|
| 13 |
+
libxext6 \
|
| 14 |
+
libxrender-dev \
|
| 15 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
+
|
| 17 |
+
# Create user
|
| 18 |
+
RUN useradd -m -u 1000 user
|
| 19 |
+
USER user
|
| 20 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 21 |
+
|
| 22 |
+
# Set working directory
|
| 23 |
+
WORKDIR /app
|
| 24 |
+
|
| 25 |
+
# Copy requirements and install Python dependencies
|
| 26 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 27 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 28 |
+
|
| 29 |
+
# Copy application files
|
| 30 |
+
COPY --chown=user . /app
|
| 31 |
+
|
| 32 |
+
# Expose Streamlit default port
|
| 33 |
+
EXPOSE 7860
|
| 34 |
+
|
| 35 |
+
# Set Streamlit configuration
|
| 36 |
+
ENV STREAMLIT_SERVER_PORT=7860
|
| 37 |
+
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
| 38 |
+
ENV STREAMLIT_SERVER_HEADLESS=true
|
| 39 |
+
ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
|
| 40 |
+
|
| 41 |
+
# Run Streamlit app
|
| 42 |
+
CMD ["streamlit", "run", "image-registration-demo.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
pyproject.toml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "image-registration"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "This is a demonstration of how transformation matrices affect registration for the affine case."
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.11.9"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"numpy>=2.2.6",
|
| 9 |
+
"opencv-python-headless>=4.12.0.88",
|
| 10 |
+
"pillow>=12.0.0",
|
| 11 |
+
"streamlit>=1.51.0",
|
| 12 |
+
]
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 1 |
+
numpy>=2.2.6
|
| 2 |
+
opencv-python-headless>=4.12.0.88
|
| 3 |
+
pillow>=12.0.0
|
| 4 |
+
streamlit>=1.51.0
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|