My First ML Web App: Diabetes Prediction with Streamlit (Mistakes, Fixes & Lessons Learned)


Introduction
When I started my college summer internship, my goal was simple — build something real with machine learning.
I decided to create a Diabetes Prediction Web App using Python and Streamlit.
Spoiler: I had no idea that I’d spend hours fighting with GitHub errors like "fetch first" and confusing bugs like ModuleNotFoundError: joblib
.
But that’s the beauty of projects — they teach you way more than just coding.
In this blog, I’ll Walk you through how I built this app from scratch, the mistakes I made, and what I learned.
Step 1: Choosing the Problem
I picked the PIMA Indians Diabetes Dataset because:
It’s simple yet meaningful.
It predicts whether a person is diabetic based on features like glucose, BMI, and age.
I downloaded diabetes.csv
and explored it using Pandas:
pythonCopy codeimport pandas as pd
data = pd.read_csv("diabetes.csv")
print(data.head())
Step 2: Building the ML Model
For this project, I chose KNN (K-Nearest Neighbors). Why?
Because KNN is easy to understand — it predicts based on the closest neighbors in data.
The training code was as simple as:
pythonCopy codefrom sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
import joblib
X = data.drop('Outcome', axis=1)
y = data['Outcome']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = KNeighborsClassifier(n_neighbors=5)
model.fit(X_train, y_train)
# Save model
joblib.dump(model, "Diabetes_KNN.pkl")
Step 3: Adding a UI with Streamlit
I didn’t want this to remain a boring .py
script.
So, I used Streamlit to make a simple web interface.
Here’s how my app.py
looked:
pythonCopy codeimport streamlit as st
import joblib
import numpy as np
model = joblib.load("Diabetes_KNN.pkl")
st.title("Diabetes Prediction App")
glucose = st.number_input("Glucose Level")
bmi = st.number_input("BMI")
age = st.number_input("Age")
if st.button("Predict"):
prediction = model.predict([[glucose, bmi, age, ...]])
st.success("Diabetic" if prediction[0] == 1 else "Not Diabetic")
Step 4: My Mistakes (and Fixes)
Here’s where the real learning started:
Mistake 1: Wrong requirements file
I created
requirement.txt
instead ofrequirements.txt
.Fix: Renamed the file and added
joblib
:nginxCopy codestreamlit scikit-learn pandas joblib
Mistake 2: GitHub Push Errors
I kept seeing:
vbnetCopy codeerror: failed to push some refs to 'github.com:AstutiJ/Diabetes-detect.git'
Fix: Learned to
git pull --rebase
before pushing:bashCopy codegit pull origin main --rebase git push origin main
Mistake 3: ModuleNotFoundError
On Streamlit Cloud, I got:
makefileCopy codeModuleNotFoundError: joblib
Fix: Adding
joblib
to requirements solved it.
Step 5: Deployment
I connected my GitHub repo to Streamlit Cloud, and within minutes, my app was live.
This was the best feeling ever — sharing my app with others!
Lessons Learned
Building projects isn’t just about code — it’s about debugging, experimenting, and learning.
I now understand Git basics, ML model saving, and web app deployment.
Conclusion
This project was part of my college summer internship program, and it helped me connect machine learning with real-world applications.
Next, I’m planning to work on a Breast Cancer Detection App (stay tuned — I’ll share that journey too!).
GitHub Repository: Diabetes Detection App
Subscribe to my newsletter
Read articles from ByteMotive directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
