This guide will help you deploy your TransPolymer Streamlit app to Heroku with an optimized setup that stays under the 500MB slug size limit.
- CPU-only PyTorch: Replaced CUDA-enabled PyTorch (~3GB) with CPU-only version (~100MB)
- Minimal Dependencies: Removed unnecessary packages (seaborn, scipy) that aren't used in the web app
- File Exclusion: Created
.slugignoreto exclude training scripts and data files - Heroku Configuration: Added proper
Procfileandruntime.txt
Make sure you have these new files in your repository:
requirements-heroku.txt(optimized dependencies)Procfile(tells Heroku how to run your app)runtime.txt(specifies Python version).slugignore(excludes unnecessary files)
# Install Heroku CLI if you haven't already
# https://devcenter.heroku.com/articles/heroku-cli
# Login to Heroku
heroku login
# Create a new Heroku app
heroku create your-transpolymer-app
# Rename requirements file for deployment
cp requirements-heroku.txt requirements.txt
# Deploy
git add .
git commit -m "Optimize for Heroku deployment"
git push heroku main
# Open your app
heroku open- Go to Heroku Dashboard
- Click "New" → "Create new app"
- Connect your GitHub repository
- Important: Before deploying, rename
requirements-heroku.txttorequirements.txt - Deploy from the main branch
Your app should now be running with a slug size under 500MB! The optimizations include:
- Estimated slug size: ~200-300MB (down from 3.1GB)
- CPU-only inference: Works perfectly for web predictions
- Faster build times: Fewer dependencies to install
-
Check your requirements.txt: Make sure you're using the CPU-only PyTorch:
torch>=1.12.0,<3.0.0 --index-url https://download.pytorch.org/whl/cpu -
Verify .slugignore is working: Make sure unnecessary files are excluded
-
Further optimize: If still too large, consider removing matplotlib:
# Remove from requirements-heroku.txt if not essential # matplotlib>=3.5.0,<4.0.0
-
Check Heroku logs:
heroku logs --tail -a your-app-name
-
Verify Procfile: Make sure it's exactly:
web: streamlit run app.py --server.port=$PORT --server.address=0.0.0.0
- Model Loading: The app uses random weights by default since pretrained model files are excluded
- Predictions: Still functional for demonstration purposes
- Memory Usage: CPU inference is memory-efficient for Heroku's standard dynos
pip install -r requirements.txtpip install -r requirements-heroku.txt- Dyno Types: Standard dynos should be sufficient for this app
- Scaling: For high traffic, consider upgrading to performance dynos
- Caching: The app uses
@st.cache_resourcefor efficient model loading - Monitoring: Use Heroku metrics to monitor performance
- The deployed app will use random model weights (for demo purposes)
- If you need actual predictions, you'll need to host model weights separately (e.g., Hugging Face Hub)
- Consider using environment variables for any sensitive configurations
Happy deploying! 🚀