vikas_project / app.py
adityaardak's picture
Upload 3 files
923450e verified
import streamlit as st
import pickle
import numpy as np
# Load the saved model
with open('model.pkl', 'rb') as f:
model = pickle.load(f)
st.title("Iris Flower Prediction App")
st.write("""
Enter the **Iris flower measurements** below to predict the species.
""")
# Create input widgets for each feature
sepal_length = st.number_input("Sepal length (cm)", min_value=0.0, max_value=10.0, value=5.0)
sepal_width = st.number_input("Sepal width (cm)", min_value=0.0, max_value=10.0, value=3.0)
petal_length = st.number_input("Petal length (cm)", min_value=0.0, max_value=10.0, value=4.0)
petal_width = st.number_input("Petal width (cm)", min_value=0.0, max_value=10.0, value=1.0)
if st.button("Predict"):
# 1. Convert input to a numpy array
input_data = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
# 2. Make prediction
prediction = model.predict(input_data)
# 3. Map numeric prediction to Iris class name
# (Iris dataset classes -> 0: setosa, 1: versicolor, 2: virginica)
class_names = ["Iris-setosa", "Iris-versicolor", "Iris-virginica"]
predicted_class = class_names[prediction[0]]
# 4. Display the result
st.write(f"**Predicted Iris Species:** {predicted_class}")