Spaces:
Sleeping
Sleeping
File size: 8,377 Bytes
3730b80 90c01cf |
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
---
title: PatternRec Project Group5
emoji: π¦
colorFrom: gray
colorTo: yellow
sdk: gradio
sdk_version: 5.37.0
app_file: app.py
pinned: false
license: apache-2.0
---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
# π Group 5 Pattern Recognition Project - Deployment Guide
## π Overview
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.
## π Live Demo
Deploy this app on **Hugging Face Spaces** for free hosting!
## π File Setup for Deployment
### Step 1: Upload Large Files to Google Drive
You need to upload these files to Google Drive and make them publicly accessible:
1. **torch_recipe_embeddings_231630.pt** (679MB)
2. **tag_based_bert_model.pth** (418MB)
3. **RAW_recipes.csv** (281MB)
4. **recipe_statistics_231630.pkl** (4.3MB)
5. **recipe_scores_231630.pkl** (3.0MB)
### Step 2: Get Google Drive File IDs
For each file in Google Drive:
1. Right-click β "Get link"
2. Make sure it's set to "Anyone with the link can view"
3. Copy the file ID from the URL: `https://drive.google.com/file/d/FILE_ID_HERE/view`
### Step 3: Update File IDs in Code
Edit `gradio_app_deploy.py` and replace the placeholder IDs:
```python
GOOGLE_DRIVE_FILES = {
'torch_recipe_embeddings_231630.pt': 'YOUR_ACTUAL_EMBEDDINGS_FILE_ID',
'tag_based_bert_model.pth': 'YOUR_ACTUAL_MODEL_FILE_ID',
'RAW_recipes.csv': 'YOUR_ACTUAL_RECIPES_FILE_ID',
'recipe_statistics_231630.pkl': 'YOUR_ACTUAL_STATS_FILE_ID',
'recipe_scores_231630.pkl': 'YOUR_ACTUAL_SCORES_FILE_ID'
}
```
## π€ Deploy to Hugging Face Spaces
### Step 1: Create Hugging Face Account
1. Go to [huggingface.co](https://huggingface.co)
2. Sign up for a free account
### Step 2: Create New Space
1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
2. Click "Create new Space"
3. Choose:
- **Space name**: `group5-recipe-recommendation`
- **License**: Apache 2.0
- **SDK**: Gradio
- **Hardware**: CPU Basic (free)
### Step 3: Upload Files
Upload these files to your Space:
```
π Your Space Repository
βββ app.py (rename gradio_app_deploy.py to app.py)
βββ requirements.txt (use requirements_deploy.txt)
βββ README.md (this file)
```
### Step 4: Files to Upload
1. **Rename** `gradio_app_deploy.py` β `app.py`
2. **Rename** `requirements_deploy.txt` β `requirements.txt`
3. **Upload** both files to your Space
### Step 5: Configure Space
Your Space will automatically:
1. Install dependencies from `requirements.txt`
2. Download files from Google Drive on first run
3. Start the Gradio app on port 7860
## π§ Alternative Deployment Options
### Option 1: Railway
1. Connect your GitHub repo to [Railway](https://railway.app)
2. Add environment variables for file URLs
3. Deploy with automatic builds
### Option 2: Render
1. Connect your GitHub repo to [Render](https://render.com)
2. Configure build and start commands
3. Set up environment variables
### Option 3: Streamlit Cloud
1. Convert the app to Streamlit format
2. Deploy via [streamlit.io](https://streamlit.io)
## π Expected Performance
- **Startup Time**: 2-5 minutes (downloading files)
- **Search Speed**: <2 seconds per query
- **Memory Usage**: ~2GB (for full dataset)
- **Storage**: ~1.5GB total
## π Troubleshooting
### Common Issues:
1. **Files not downloading**
- Check Google Drive file permissions
- Verify file IDs are correct
- Ensure files are public
2. **Out of memory**
- Use smaller dataset subset
- Upgrade to paid Hugging Face hardware
3. **Slow startup**
- Normal for first run (downloading files)
- Subsequent runs will be faster
## π Useful Links
- [Hugging Face Spaces Documentation](https://huggingface.co/docs/hub/spaces)
- [Gradio Documentation](https://gradio.app/docs)
- [PyTorch Documentation](https://pytorch.org/docs)
## π GitHub Integration & Auto-Sync
### Option 1: Direct GitHub Connection (Recommended)
1. **In your Hugging Face Space settings**:
- Go to your Space β Settings β Repository
- Click "Connect to GitHub"
- Authorize Hugging Face to access your GitHub repo
- Select your repository: `PatternRec_Project_Group7`
2. **Configure auto-sync**:
- Enable "Auto-sync with GitHub"
- Choose branch (usually `main`)
- Set sync frequency (immediate, hourly, daily)
3. **Result**: Every time you push to GitHub, your Hugging Face Space will automatically update!
### Option 2: GitHub Actions (Advanced)
Create `.github/workflows/deploy-to-hf.yml` in your repo:
```yaml
name: Deploy to Hugging Face Spaces
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Push to Hugging Face Spaces
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
# Clone your HF Space repo
git clone https://huggingface.co/spaces/YOUR_USERNAME/group5-recipe-recommendation hf-space
cd hf-space
# Copy files from GitHub repo
cp ../gradio_app_deploy.py ./app.py
cp ../requirements_deploy.txt ./requirements.txt
cp ../DEPLOYMENT_README.md ./README.md
# Push to HF Space
git add .
git commit -m "Auto-sync from GitHub: ${{ github.event.head_commit.message }}"
git push https://USER:${{ secrets.HF_TOKEN }}@huggingface.co/spaces/YOUR_USERNAME/group5-recipe-recommendation
```
### Option 3: Dual Git Remotes
Set up your local repo to push to both GitHub and Hugging Face:
```bash
# Add HF Space as second remote
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/group5-recipe-recommendation
# Push to both with one command
git push origin main # GitHub
git push hf main # Hugging Face Space
# Or create an alias for both
git config alias.pushall '!git push origin main && git push hf main'
# Then use: git pushall
```
### Option 4: Automated Script
Create a deployment script `deploy.sh`:
```bash
#!/bin/bash
echo "π Deploying to Hugging Face Space..."
# Copy deployment files
cp gradio_app_deploy.py app.py
cp requirements_deploy.txt requirements.txt
# Commit changes
git add app.py requirements.txt README.md
git commit -m "Deploy: $(date)"
# Push to GitHub
git push origin main
# Push to Hugging Face Space
git push hf main
echo "β
Deployment complete!"
```
### Recommended Workflow
1. **Set up direct GitHub connection** (easiest)
2. **Structure your repo** with deployment-ready files:
```
π Your GitHub Repo
βββ gradio_app_deploy.py # Main app (will become app.py)
βββ requirements_deploy.txt # Dependencies (will become requirements.txt)
βββ DEPLOYMENT_README.md # This file (will become README.md)
βββ gradio_app_fixed.py # Development version
βββ ... other project files
```
3. **Configure auto-sync** in HF Space settings
4. **Push to GitHub** - HF Space updates automatically!
### File Mapping for Auto-Sync
When files sync from GitHub β Hugging Face Space:
| GitHub File | β | HF Space File | Purpose |
|-------------|---|---------------|---------|
| `gradio_app_deploy.py` | β | `app.py` | Main application |
| `requirements_deploy.txt` | β | `requirements.txt` | Dependencies |
| `DEPLOYMENT_README.md` | β | `README.md` | Documentation |
### Benefits of GitHub Integration
β
**Version Control**: Keep your code in GitHub
β
**Automatic Updates**: Push once, deploy everywhere
β
**Collaboration**: Team members can contribute via GitHub
β
**Backup**: Multiple copies of your code
β
**CI/CD**: Run tests before deployment
## π Support
If you encounter issues:
1. Check the Space logs in Hugging Face
2. Verify all file IDs are correct
3. Ensure requirements.txt has all dependencies
## π― Success Criteria
β
App loads without errors
β
Search functionality works
β
Results show relevant recipes
β
Interface is responsive
Your app should be accessible at: `https://huggingface.co/spaces/YOUR_USERNAME/group5-recipe-recommendation` |