iris / app.py
sankar12345's picture
Update app.py
39a8a70 verified
raw
history blame
1.49 kB
import streamlit as st
import pandas as pd
import pickle
import sklearn # Ensure scikit-learn is imported
# Load the pre-trained model
try:
with open('logreg_model.pkl', 'rb') as model_file:
model = pickle.load(model_file)
except Exception as e:
st.error("Failed to load model. Ensure that the scikit-learn version matches the one used to create the model file.")
st.error(f"Error Details: {e}")
st.stop()
st.title('Iris Variety Prediction')
# User Input Form
with st.form(key='form_parameters'):
sepal_length = st.slider('Sepal Length (cm)', 4.0, 8.0, 5.0)
sepal_width = st.slider('Sepal Width (cm)', 2.0, 4.5, 3.0)
petal_length = st.slider('Petal Length (cm)', 1.0, 7.0, 1.5)
petal_width = st.slider('Petal Width (cm)', 0.1, 2.5, 0.2)
st.markdown('---')
submitted = st.form_submit_button('Predict')
# Data Inference
if submitted:
# Create DataFrame for prediction
data_inf = {
'Id': 0,
'SepalLengthCm': sepal_length,
'SepalWidthCm': sepal_width,
'PetalLengthCm': petal_length,
'PetalWidthCm': petal_width
}
data_inf = pd.DataFrame([data_inf])
# Predict using the model
try:
y_pred_inf = model.predict(data_inf)
st.write('## Iris Variety: **' + str(y_pred_inf[0]) + '**')
except Exception as e:
st.error("Prediction failed. Please ensure the input format is correct and compatible with the model.")
st.error(f"Error Details: {e}")