Spaces:
Sleeping
A newer version of the Gradio SDK is available:
6.4.0
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:
- torch_recipe_embeddings_231630.pt (679MB)
- tag_based_bert_model.pth (418MB)
- RAW_recipes.csv (281MB)
- recipe_statistics_231630.pkl (4.3MB)
- recipe_scores_231630.pkl (3.0MB)
Step 2: Get Google Drive File IDs
For each file in Google Drive:
- Right-click β "Get link"
- Make sure it's set to "Anyone with the link can view"
- 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:
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
- Go to huggingface.co
- Sign up for a free account
Step 2: Create New Space
- Go to huggingface.co/spaces
- Click "Create new Space"
- Choose:
- Space name:
group5-recipe-recommendation - License: Apache 2.0
- SDK: Gradio
- Hardware: CPU Basic (free)
- Space name:
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
- Rename
gradio_app_deploy.pyβapp.py - Rename
requirements_deploy.txtβrequirements.txt - Upload both files to your Space
Step 5: Configure Space
Your Space will automatically:
- Install dependencies from
requirements.txt - Download files from Google Drive on first run
- Start the Gradio app on port 7860
π§ Alternative Deployment Options
Option 1: Railway
- Connect your GitHub repo to Railway
- Add environment variables for file URLs
- Deploy with automatic builds
Option 2: Render
- Connect your GitHub repo to Render
- Configure build and start commands
- Set up environment variables
Option 3: Streamlit Cloud
- Convert the app to Streamlit format
- Deploy via 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:
Files not downloading
- Check Google Drive file permissions
- Verify file IDs are correct
- Ensure files are public
Out of memory
- Use smaller dataset subset
- Upgrade to paid Hugging Face hardware
Slow startup
- Normal for first run (downloading files)
- Subsequent runs will be faster
π Useful Links
π GitHub Integration & Auto-Sync
Option 1: Direct GitHub Connection (Recommended)
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
Configure auto-sync:
- Enable "Auto-sync with GitHub"
- Choose branch (usually
main) - Set sync frequency (immediate, hourly, daily)
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:
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:
# 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:
#!/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
Set up direct GitHub connection (easiest)
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 filesConfigure auto-sync in HF Space settings
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:
- Check the Space logs in Hugging Face
- Verify all file IDs are correct
- 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