Deploy your ML model to Heroku with our step-by-step guide. Quick and stress-free instructions for smooth, reliable implementation.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
model.pkl) in your project directory.app.py) with code to load the ML model and set up routes. For instance, using Flask:
// Import required modules
from flask import Flask, request, jsonify
import pickle
app = Flask(name)
// Load the pre-trained ML model
with open('model.pkl', 'rb') as file:
model = pickle.load(file)
// Define a prediction route
@app.route('/predict', methods=['POST'])
def predict():
// Retrieve input data as JSON
data = request.get_json(force=True)
// Extract features for prediction (adjust as necessary)
features = data['features']
// Perform model prediction
prediction = model.predict([features])
return jsonify({'prediction': prediction.tolist()})
// Main entry point
if name == 'main':
app.run(debug=True)
/predict which accepts POST requests with JSON data. It loads the model and responds with predictions using Flask.requirements.txt listing all the dependencies. This file will be used by Heroku to install the packages automatically.
// Example of requirements.txt content
Flask==2.2.2
gunicorn==20.1.0 // Production server to run the Flask app
scikit-learn==1.1.1 // If your model is built with scikit-learn
numpy==1.21.0 // Often needed for numerical operations
Procfile (with no file extension) and include the following content:
// Use gunicorn to run the Flask application
web: gunicorn app:app
gunicorn app:app tells Heroku to run the gunicorn server using the app object inside app.py.runtime.txt and specify the version.
// Specify Python version
python-3.9.12
app.py, requirements.txt, Procfile, runtime.txt (if used), and your ML model file.
// Initialize Git repository
git init
// Add all files to the repository
git add .
// Commit the changes
git commit -m "Initial commit with ML model and Heroku deployment files"
// Create a new app on Heroku (replace 'your-app-name' with your desired app name)
heroku create your-app-name
// Push code to Heroku master/main branch
git push heroku master
main, use git push heroku main instead.
// Stream logs from Heroku
heroku logs --tail --app your-app-name
https://your-app-name.herokuapp.com/predict with appropriate JSON data to verify that your ML model returns predictions correctly.From startups to enterprises and everything in between, see for yourself our incredible impact.
Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.Â