BTP_2026 / DEPLOYMENT_GUIDE.md
suvradeepp's picture
Upload 34 files
49e8d95 verified

A newer version of the Streamlit SDK is available: 1.56.0

Upgrade

πŸš€ Deployment Guide for Hugging Face Spaces

This guide will help you deploy the Crystallization Component Predictor to Hugging Face Spaces.

πŸ“‹ Prerequisites

  1. A Hugging Face account (sign up at https://huggingface.co/)
  2. Git installed on your computer
  3. Git LFS installed (git lfs install)

πŸ”§ Step-by-Step Deployment

Option 1: Web UI Upload (Easiest)

  1. Create a new Space:

    • Go to https://huggingface.co/spaces
    • Click "Create new Space"
    • Choose a name (e.g., "crystallization-predictor")
    • Select Streamlit as the SDK
    • Choose visibility (Public or Private)
    • Click "Create Space"
  2. Upload files:

    • Click "Files" tab in your Space
    • Click "Add file" β†’ "Upload files"
    • Drag and drop ALL files from this huggingface_app folder:
      • app.py
      • requirements.txt
      • README.md
      • .gitattributes
      • .gitignore
      • models/ folder (with all subfolders)
      • visualizations/ folder (with all images)
    • Click "Commit changes to main"
  3. Wait for build:

    • Hugging Face will automatically build your Space
    • Check the "Logs" tab to monitor progress
    • Usually takes 2-5 minutes
  4. Test your app:

    • Once built, click on the "App" tab
    • Your Streamlit app should be running!

Option 2: Git Command Line (Advanced)

  1. Initialize Git LFS:
cd huggingface_app
git lfs install
  1. Clone your Space repository:
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME
  1. Copy files:
# Copy all files from huggingface_app to your cloned repo
# On Windows:
xcopy ..\huggingface_app\* . /E /H /Y

# On Linux/Mac:
cp -r ../huggingface_app/* .
  1. Commit and push:
git add .
git commit -m "Initial deployment of crystallization predictor"
git push
  1. Check deployment:
    • Visit your Space URL: https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
    • Monitor build logs in the "Logs" tab

πŸ“ Files Included

huggingface_app/
β”œβ”€β”€ app.py                          # Main Streamlit application
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ README.md                       # Documentation (shown on Space page)
β”œβ”€β”€ .gitattributes                  # Git LFS configuration
β”œβ”€β”€ .gitignore                      # Files to ignore
β”œβ”€β”€ DEPLOYMENT_GUIDE.md            # This file
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ simple_baseline/
β”‚   β”‚   β”œβ”€β”€ model_component_name.pkl
β”‚   β”‚   β”œβ”€β”€ model_component_ph.pkl
β”‚   β”‚   β”œβ”€β”€ label_encoder_name.pkl
β”‚   β”‚   β”œβ”€β”€ scaler.pkl
β”‚   β”‚   β”œβ”€β”€ tfidf.pkl
β”‚   β”‚   └── training_results.json
β”‚   └── advanced_baseline/
β”‚       β”œβ”€β”€ model_component_name.pkl
β”‚       β”œβ”€β”€ model_component_conc.pkl
β”‚       β”œβ”€β”€ model_component_ph.pkl
β”‚       β”œβ”€β”€ label_encoder_name.pkl
β”‚       β”œβ”€β”€ scaler.pkl
β”‚       β”œβ”€β”€ tfidf.pkl
β”‚       └── training_results.json
└── visualizations/
    β”œβ”€β”€ 01_component_name_comparison.png
    β”œβ”€β”€ 02_component_conc_comparison.png
    β”œβ”€β”€ 03_component_ph_comparison.png
    β”œβ”€β”€ 04_all_approaches_heatmap.png
    └── 05_complete_comparison.png

πŸ” Troubleshooting

Build Fails

Problem: "Could not install packages due to an OSError"

  • Solution: Check that all dependencies in requirements.txt are compatible
  • Try pinning versions or using newer versions

Problem: "ModuleNotFoundError"

  • Solution: Ensure the missing module is in requirements.txt

Model Loading Errors

Problem: "FileNotFoundError: [Errno 2] No such file or directory: 'models/...'"

  • Solution: Verify all model files were uploaded correctly
  • Check that folder structure is preserved

Problem: Large file upload fails

  • Solution: Ensure Git LFS is properly configured
  • Files over 10MB should use LFS (already configured in .gitattributes)

App Crashes

Problem: "Memory limit exceeded"

  • Solution: Hugging Face Spaces have memory limits
  • Consider using smaller models or optimizing loading

Problem: Slow loading

  • Solution: Models are loaded on first prediction (not at startup)
  • This is intentional for faster app startup

🎨 Customization

Change App Title/Icon

Edit the README.md header: ```yaml

title: Your Custom Title emoji: 🧬 # Change emoji colorFrom: blue # Change colors colorTo: purple


### Modify the App
Edit `app.py` and commit changes. The Space will rebuild automatically.

### Add More Models
1. Add model files to `models/` folder
2. Update `app.py` to load and use new models
3. Update `README.md` to document changes

## πŸ“Š Monitoring

- **Logs**: Check the "Logs" tab in your Space
- **Analytics**: View usage statistics in Space settings
- **Updates**: Any push to the main branch triggers a rebuild

## πŸ”’ Security & Privacy

- **Public Spaces**: Anyone can use your app and see the code
- **Private Spaces**: Only you and collaborators can access
- **No User Data**: The app doesn't collect or store user inputs
- **Model Files**: Ensure you have rights to distribute the models

## πŸ’° Costs

- **Free Tier**: 
  - CPU: 2 vCPU, 16GB RAM
  - Perfect for this app
  - No credit card required
  
- **Paid Tiers**: 
  - Available for GPU or more resources
  - Not needed for this application

## πŸ”— Useful Links

- Hugging Face Spaces Docs: https://huggingface.co/docs/hub/spaces
- Streamlit Docs: https://docs.streamlit.io/
- Git LFS: https://git-lfs.github.com/

## πŸ“ž Support

If you encounter issues:
1. Check the "Logs" tab in your Space
2. Review Hugging Face Spaces documentation
3. Search Hugging Face forums
4. Open an issue on the repository

## βœ… Pre-Deployment Checklist

- [ ] All model files copied to `models/` folders
- [ ] Visualizations copied to `visualizations/` folder
- [ ] `requirements.txt` has all dependencies
- [ ] `README.md` header configured with title/emoji
- [ ] Tested app locally (`streamlit run app.py`)
- [ ] Git LFS installed and configured
- [ ] Hugging Face account created
- [ ] Space created on Hugging Face

## πŸŽ‰ Post-Deployment

After successful deployment:
1. Test all features in the live app
2. Share your Space URL with others
3. Monitor logs for any errors
4. Consider adding:
   - Example inputs/outputs
   - Tutorial video
   - Publication link
   - Citation information

---

**Good luck with your deployment! πŸš€**

Your app will be accessible at:
`https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`