Step-by-step guide on building an end-to-end ML web app. Learn model creation, UI design, and deployment for real-world projects.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
// Import data handling libraries
import pandas as pd
import numpy as np
// Load raw data from CSV file or API endpoint
data = pd.read_csv("raw_data.csv")
// Data cleaning: remove duplicates, handle missing values
data.drop\_duplicates(inplace=true)
data.fillna(method="ffill", inplace=true)
// Feature engineering: create new features, normalize values
data["normalized_feature"] = (data["raw_feature"] - data["raw_feature"].mean()) / data["raw_feature"].std()
import sklearn.model\_selection as ms
import sklearn.ensemble as ensemble
import sklearn.metrics as metrics
// Split data into training and test sets
X = data.drop("target", axis=1)
y = data["target"]
X_train, X_test, y_train, y_test = ms.train_test_split(X, y, test_size=0.2, random_state=42)
// Train a Random Forest classifier
model = ensemble.RandomForestClassifier(n\_estimators=100)
model.fit(X_train, y_train)
// Evaluate model performance on test data
predictions = model.predict(X\_test)
accuracy = metrics.accuracy_score(y_test, predictions)
print("Model Accuracy:", accuracy)
import pickle
// Save the trained model to disk
with open("trained\_model.pkl", "wb") as f:
pickle.dump(model, f)
// Later, load the model for inference
with open("trained\_model.pkl", "rb") as f:
loaded\_model = pickle.load(f)
from flask import Flask, request, jsonify
import pickle
import pandas as pd
// Create Flask app instance
app = Flask(**name**)
// Load model at startup so that it is available for all requests
with open("trained\_model.pkl", "rb") as f:
model = pickle.load(f)
@app.route("/predict", methods=["POST"])
def predict():
// Extract JSON data from request
input_data = request.get_json()
// Convert input data into a pandas DataFrame
input_df = pd.DataFrame(input_data)
// Make prediction using pre-loaded model
predictions = model.predict(input\_df)
// Return predictions in JSON format
return jsonify({"predictions": predictions.tolist()})
if **name** == "**main**":
app.run(port=5000, debug=True)
// Function to call the ML API and display predictions
async function getPrediction(inputData) {
try {
// Make a POST request to the ML API
const response = await fetch("http://localhost:5000/predict", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(inputData)
});
// Process the JSON response
const data = await response.json();
console.log("Predictions:", data.predictions);
// Update your UI elements with the predictions here
} catch (error) {
console.error("Error fetching prediction:", error);
}
}
// Trigger the function on user action, e.g., button click
document.getElementById("predictBtn").addEventListener("click", () => {
const inputData = {
// Gather form input values into an object or array
feature1: parseFloat(document.getElementById("feature1").value),
feature2: parseFloat(document.getElementById("feature2").value)
};
getPrediction(inputData);
});
// Use an official Python runtime as a parent image
FROM python:3.8-slim
// Set working directory in the container
WORKDIR /app
// Copy current directory contents into the container at /app
COPY . /app
// Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
// Expose the port the API runs on
EXPOSE 5000
// Run the API using gunicorn for better performance in production
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "app:app"] // app:app refers to the app module and app variable
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.Â