AAZ1215's picture
Update README.md
90c01cf verified

A newer version of the Gradio SDK is available: 6.4.0

Upgrade
metadata
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:

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
  2. Sign up for a free account

Step 2: Create New Space

  1. Go to 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
  2. Add environment variables for file URLs
  3. Deploy with automatic builds

Option 2: Render

  1. Connect your GitHub repo to Render
  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

πŸ“Š 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

πŸ”„ 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:

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

  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