Step-by-step ML model deployment with Streamlit Cloud. Quick guide to scalable, efficient ML launches.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
joblib or pickle). This file (e.g., model.pkl) is the basis for your predictions.
// Import necessary libraries
import streamlit as st
import joblib // Used for loading the saved ML model
// Load the persisted model
model = joblib.load("model.pkl")
// Define a function that receives user input and returns predictions
def make_prediction(input_data):
// Process or transform the input data as necessary
prediction = model.predict([input\_data])
return prediction
// Streamlit app logic begins here
st.title("ML Model Deployment on Streamlit Cloud")
// Capture user input; adapt based on model requirements
user_input = st.text_input("Enter the input value:")
// Trigger prediction on button click
if st.button("Predict"):
try:
result = make_prediction(user_input)
st.write("Prediction Result:", result)
except Exception as e:
st.error("Error processing prediction: " + str(e))
// Example preprocessing function
def preprocess_data(raw_input):
// Convert the raw string input into a numerical format
try:
processed_input = float(raw_input)
except ValueError:
st.error("Invalid input: please enter a numerical value")
return None
return processed\_input
// Updated prediction function utilizing preprocessing
def make_prediction(raw_input):
processed_input = preprocess_data(raw\_input)
if processed\_input is None:
return None
prediction = model.predict([processed\_input])
return prediction
requirements.txt file. This ensures consistent behavior across deployments.streamlit==1.15.0 (adapt version as necessary), along with others required for data processing and model execution.
// Sample content of requirements.txt:
// streamlit==1.15.0
// joblib==1.1.0
// scikit-learn==1.1.1
api_key="YOUR_API_KEY". In your code, access them with st.secrets["api_key"].
// Accessing a secret variable within the app
api_key = st.secrets["api_key"]
app.py), confirming that all dependencies are correctly declared. Streamlit Cloud will install them automatically from requirements.txt.
streamlit run app.py. This ensures a smoother deployment process on Streamlit Cloud.
// Sample command (run in your terminal locally):
// streamlit run app.py
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.Â