Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -11,3 +11,272 @@ license: apache-2.0
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 14 |
+
# π Group 5 Pattern Recognition Project - Deployment Guide
|
| 15 |
+
|
| 16 |
+
## π Overview
|
| 17 |
+
This is a recipe recommendation system using semantic search with a trained BERT model. The system provides intelligent recipe recommendations based on semantic understanding of user queries.
|
| 18 |
+
|
| 19 |
+
## π Live Demo
|
| 20 |
+
Deploy this app on **Hugging Face Spaces** for free hosting!
|
| 21 |
+
|
| 22 |
+
## π File Setup for Deployment
|
| 23 |
+
|
| 24 |
+
### Step 1: Upload Large Files to Google Drive
|
| 25 |
+
|
| 26 |
+
You need to upload these files to Google Drive and make them publicly accessible:
|
| 27 |
+
|
| 28 |
+
1. **torch_recipe_embeddings_231630.pt** (679MB)
|
| 29 |
+
2. **tag_based_bert_model.pth** (418MB)
|
| 30 |
+
3. **RAW_recipes.csv** (281MB)
|
| 31 |
+
4. **recipe_statistics_231630.pkl** (4.3MB)
|
| 32 |
+
5. **recipe_scores_231630.pkl** (3.0MB)
|
| 33 |
+
|
| 34 |
+
### Step 2: Get Google Drive File IDs
|
| 35 |
+
|
| 36 |
+
For each file in Google Drive:
|
| 37 |
+
1. Right-click β "Get link"
|
| 38 |
+
2. Make sure it's set to "Anyone with the link can view"
|
| 39 |
+
3. Copy the file ID from the URL: `https://drive.google.com/file/d/FILE_ID_HERE/view`
|
| 40 |
+
|
| 41 |
+
### Step 3: Update File IDs in Code
|
| 42 |
+
|
| 43 |
+
Edit `gradio_app_deploy.py` and replace the placeholder IDs:
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
GOOGLE_DRIVE_FILES = {
|
| 47 |
+
'torch_recipe_embeddings_231630.pt': 'YOUR_ACTUAL_EMBEDDINGS_FILE_ID',
|
| 48 |
+
'tag_based_bert_model.pth': 'YOUR_ACTUAL_MODEL_FILE_ID',
|
| 49 |
+
'RAW_recipes.csv': 'YOUR_ACTUAL_RECIPES_FILE_ID',
|
| 50 |
+
'recipe_statistics_231630.pkl': 'YOUR_ACTUAL_STATS_FILE_ID',
|
| 51 |
+
'recipe_scores_231630.pkl': 'YOUR_ACTUAL_SCORES_FILE_ID'
|
| 52 |
+
}
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## π€ Deploy to Hugging Face Spaces
|
| 56 |
+
|
| 57 |
+
### Step 1: Create Hugging Face Account
|
| 58 |
+
1. Go to [huggingface.co](https://huggingface.co)
|
| 59 |
+
2. Sign up for a free account
|
| 60 |
+
|
| 61 |
+
### Step 2: Create New Space
|
| 62 |
+
1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
|
| 63 |
+
2. Click "Create new Space"
|
| 64 |
+
3. Choose:
|
| 65 |
+
- **Space name**: `group5-recipe-recommendation`
|
| 66 |
+
- **License**: Apache 2.0
|
| 67 |
+
- **SDK**: Gradio
|
| 68 |
+
- **Hardware**: CPU Basic (free)
|
| 69 |
+
|
| 70 |
+
### Step 3: Upload Files
|
| 71 |
+
Upload these files to your Space:
|
| 72 |
+
|
| 73 |
+
```
|
| 74 |
+
π Your Space Repository
|
| 75 |
+
βββ app.py (rename gradio_app_deploy.py to app.py)
|
| 76 |
+
βββ requirements.txt (use requirements_deploy.txt)
|
| 77 |
+
βββ README.md (this file)
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### Step 4: Files to Upload
|
| 81 |
+
|
| 82 |
+
1. **Rename** `gradio_app_deploy.py` β `app.py`
|
| 83 |
+
2. **Rename** `requirements_deploy.txt` β `requirements.txt`
|
| 84 |
+
3. **Upload** both files to your Space
|
| 85 |
+
|
| 86 |
+
### Step 5: Configure Space
|
| 87 |
+
Your Space will automatically:
|
| 88 |
+
1. Install dependencies from `requirements.txt`
|
| 89 |
+
2. Download files from Google Drive on first run
|
| 90 |
+
3. Start the Gradio app on port 7860
|
| 91 |
+
|
| 92 |
+
## π§ Alternative Deployment Options
|
| 93 |
+
|
| 94 |
+
### Option 1: Railway
|
| 95 |
+
1. Connect your GitHub repo to [Railway](https://railway.app)
|
| 96 |
+
2. Add environment variables for file URLs
|
| 97 |
+
3. Deploy with automatic builds
|
| 98 |
+
|
| 99 |
+
### Option 2: Render
|
| 100 |
+
1. Connect your GitHub repo to [Render](https://render.com)
|
| 101 |
+
2. Configure build and start commands
|
| 102 |
+
3. Set up environment variables
|
| 103 |
+
|
| 104 |
+
### Option 3: Streamlit Cloud
|
| 105 |
+
1. Convert the app to Streamlit format
|
| 106 |
+
2. Deploy via [streamlit.io](https://streamlit.io)
|
| 107 |
+
|
| 108 |
+
## π Expected Performance
|
| 109 |
+
- **Startup Time**: 2-5 minutes (downloading files)
|
| 110 |
+
- **Search Speed**: <2 seconds per query
|
| 111 |
+
- **Memory Usage**: ~2GB (for full dataset)
|
| 112 |
+
- **Storage**: ~1.5GB total
|
| 113 |
+
|
| 114 |
+
## π Troubleshooting
|
| 115 |
+
|
| 116 |
+
### Common Issues:
|
| 117 |
+
|
| 118 |
+
1. **Files not downloading**
|
| 119 |
+
- Check Google Drive file permissions
|
| 120 |
+
- Verify file IDs are correct
|
| 121 |
+
- Ensure files are public
|
| 122 |
+
|
| 123 |
+
2. **Out of memory**
|
| 124 |
+
- Use smaller dataset subset
|
| 125 |
+
- Upgrade to paid Hugging Face hardware
|
| 126 |
+
|
| 127 |
+
3. **Slow startup**
|
| 128 |
+
- Normal for first run (downloading files)
|
| 129 |
+
- Subsequent runs will be faster
|
| 130 |
+
|
| 131 |
+
## π Useful Links
|
| 132 |
+
- [Hugging Face Spaces Documentation](https://huggingface.co/docs/hub/spaces)
|
| 133 |
+
- [Gradio Documentation](https://gradio.app/docs)
|
| 134 |
+
- [PyTorch Documentation](https://pytorch.org/docs)
|
| 135 |
+
|
| 136 |
+
## π GitHub Integration & Auto-Sync
|
| 137 |
+
|
| 138 |
+
### Option 1: Direct GitHub Connection (Recommended)
|
| 139 |
+
|
| 140 |
+
1. **In your Hugging Face Space settings**:
|
| 141 |
+
- Go to your Space β Settings β Repository
|
| 142 |
+
- Click "Connect to GitHub"
|
| 143 |
+
- Authorize Hugging Face to access your GitHub repo
|
| 144 |
+
- Select your repository: `PatternRec_Project_Group7`
|
| 145 |
+
|
| 146 |
+
2. **Configure auto-sync**:
|
| 147 |
+
- Enable "Auto-sync with GitHub"
|
| 148 |
+
- Choose branch (usually `main`)
|
| 149 |
+
- Set sync frequency (immediate, hourly, daily)
|
| 150 |
+
|
| 151 |
+
3. **Result**: Every time you push to GitHub, your Hugging Face Space will automatically update!
|
| 152 |
+
|
| 153 |
+
### Option 2: GitHub Actions (Advanced)
|
| 154 |
+
|
| 155 |
+
Create `.github/workflows/deploy-to-hf.yml` in your repo:
|
| 156 |
+
|
| 157 |
+
```yaml
|
| 158 |
+
name: Deploy to Hugging Face Spaces
|
| 159 |
+
|
| 160 |
+
on:
|
| 161 |
+
push:
|
| 162 |
+
branches: [ main ]
|
| 163 |
+
pull_request:
|
| 164 |
+
branches: [ main ]
|
| 165 |
+
|
| 166 |
+
jobs:
|
| 167 |
+
deploy:
|
| 168 |
+
runs-on: ubuntu-latest
|
| 169 |
+
steps:
|
| 170 |
+
- uses: actions/checkout@v3
|
| 171 |
+
|
| 172 |
+
- name: Push to Hugging Face Spaces
|
| 173 |
+
env:
|
| 174 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 175 |
+
run: |
|
| 176 |
+
git config --global user.email "action@github.com"
|
| 177 |
+
git config --global user.name "GitHub Action"
|
| 178 |
+
|
| 179 |
+
# Clone your HF Space repo
|
| 180 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/group5-recipe-recommendation hf-space
|
| 181 |
+
cd hf-space
|
| 182 |
+
|
| 183 |
+
# Copy files from GitHub repo
|
| 184 |
+
cp ../gradio_app_deploy.py ./app.py
|
| 185 |
+
cp ../requirements_deploy.txt ./requirements.txt
|
| 186 |
+
cp ../DEPLOYMENT_README.md ./README.md
|
| 187 |
+
|
| 188 |
+
# Push to HF Space
|
| 189 |
+
git add .
|
| 190 |
+
git commit -m "Auto-sync from GitHub: ${{ github.event.head_commit.message }}"
|
| 191 |
+
git push https://USER:${{ secrets.HF_TOKEN }}@huggingface.co/spaces/YOUR_USERNAME/group5-recipe-recommendation
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
### Option 3: Dual Git Remotes
|
| 195 |
+
|
| 196 |
+
Set up your local repo to push to both GitHub and Hugging Face:
|
| 197 |
+
|
| 198 |
+
```bash
|
| 199 |
+
# Add HF Space as second remote
|
| 200 |
+
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/group5-recipe-recommendation
|
| 201 |
+
|
| 202 |
+
# Push to both with one command
|
| 203 |
+
git push origin main # GitHub
|
| 204 |
+
git push hf main # Hugging Face Space
|
| 205 |
+
|
| 206 |
+
# Or create an alias for both
|
| 207 |
+
git config alias.pushall '!git push origin main && git push hf main'
|
| 208 |
+
# Then use: git pushall
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
### Option 4: Automated Script
|
| 212 |
+
|
| 213 |
+
Create a deployment script `deploy.sh`:
|
| 214 |
+
|
| 215 |
+
```bash
|
| 216 |
+
#!/bin/bash
|
| 217 |
+
echo "π Deploying to Hugging Face Space..."
|
| 218 |
+
|
| 219 |
+
# Copy deployment files
|
| 220 |
+
cp gradio_app_deploy.py app.py
|
| 221 |
+
cp requirements_deploy.txt requirements.txt
|
| 222 |
+
|
| 223 |
+
# Commit changes
|
| 224 |
+
git add app.py requirements.txt README.md
|
| 225 |
+
git commit -m "Deploy: $(date)"
|
| 226 |
+
|
| 227 |
+
# Push to GitHub
|
| 228 |
+
git push origin main
|
| 229 |
+
|
| 230 |
+
# Push to Hugging Face Space
|
| 231 |
+
git push hf main
|
| 232 |
+
|
| 233 |
+
echo "β
Deployment complete!"
|
| 234 |
+
```
|
| 235 |
+
|
| 236 |
+
### Recommended Workflow
|
| 237 |
+
|
| 238 |
+
1. **Set up direct GitHub connection** (easiest)
|
| 239 |
+
2. **Structure your repo** with deployment-ready files:
|
| 240 |
+
```
|
| 241 |
+
π Your GitHub Repo
|
| 242 |
+
βββ gradio_app_deploy.py # Main app (will become app.py)
|
| 243 |
+
βββ requirements_deploy.txt # Dependencies (will become requirements.txt)
|
| 244 |
+
βββ DEPLOYMENT_README.md # This file (will become README.md)
|
| 245 |
+
βββ gradio_app_fixed.py # Development version
|
| 246 |
+
βββ ... other project files
|
| 247 |
+
```
|
| 248 |
+
|
| 249 |
+
3. **Configure auto-sync** in HF Space settings
|
| 250 |
+
4. **Push to GitHub** - HF Space updates automatically!
|
| 251 |
+
|
| 252 |
+
### File Mapping for Auto-Sync
|
| 253 |
+
|
| 254 |
+
When files sync from GitHub β Hugging Face Space:
|
| 255 |
+
|
| 256 |
+
| GitHub File | β | HF Space File | Purpose |
|
| 257 |
+
|-------------|---|---------------|---------|
|
| 258 |
+
| `gradio_app_deploy.py` | β | `app.py` | Main application |
|
| 259 |
+
| `requirements_deploy.txt` | β | `requirements.txt` | Dependencies |
|
| 260 |
+
| `DEPLOYMENT_README.md` | β | `README.md` | Documentation |
|
| 261 |
+
|
| 262 |
+
### Benefits of GitHub Integration
|
| 263 |
+
|
| 264 |
+
β
**Version Control**: Keep your code in GitHub
|
| 265 |
+
β
**Automatic Updates**: Push once, deploy everywhere
|
| 266 |
+
β
**Collaboration**: Team members can contribute via GitHub
|
| 267 |
+
β
**Backup**: Multiple copies of your code
|
| 268 |
+
β
**CI/CD**: Run tests before deployment
|
| 269 |
+
|
| 270 |
+
## π Support
|
| 271 |
+
If you encounter issues:
|
| 272 |
+
1. Check the Space logs in Hugging Face
|
| 273 |
+
2. Verify all file IDs are correct
|
| 274 |
+
3. Ensure requirements.txt has all dependencies
|
| 275 |
+
|
| 276 |
+
## π― Success Criteria
|
| 277 |
+
β
App loads without errors
|
| 278 |
+
β
Search functionality works
|
| 279 |
+
β
Results show relevant recipes
|
| 280 |
+
β
Interface is responsive
|
| 281 |
+
|
| 282 |
+
Your app should be accessible at: `https://huggingface.co/spaces/YOUR_USERNAME/group5-recipe-recommendation`
|