Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +41 -0
- iris_model.pkl +3 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import joblib
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
# Load the pre-trained model
|
7 |
+
model = joblib.load("iris_model.pkl")
|
8 |
+
|
9 |
+
# Define the mapping for iris species
|
10 |
+
species = {0: "setosa", 1: "versicolor", 2: "virginica"}
|
11 |
+
|
12 |
+
# App Title
|
13 |
+
st.title("Iris Species Classifier")
|
14 |
+
st.write("Enter the measurements of an Iris flower to predict its species.")
|
15 |
+
|
16 |
+
# Input widgets for user to enter measurements
|
17 |
+
sepal_length = st.number_input("Sepal Length (cm)", min_value=0.0, value=5.1)
|
18 |
+
sepal_width = st.number_input("Sepal Width (cm)", min_value=0.0, value=3.5)
|
19 |
+
petal_length = st.number_input("Petal Length (cm)", min_value=0.0, value=1.4)
|
20 |
+
petal_width = st.number_input("Petal Width (cm)", min_value=0.0, value=0.2)
|
21 |
+
|
22 |
+
if st.button("Predict"):
|
23 |
+
# Prepare the input as a 2D array for prediction
|
24 |
+
input_features = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
|
25 |
+
prediction = model.predict(input_features)
|
26 |
+
st.success(f"The predicted Iris species is **{species[prediction[0]]}**.")
|
27 |
+
|
28 |
+
|
29 |
+
### TO-DO: ADD A BAR CHART WITH THE MEASUREMENTS ENTERED.
|
30 |
+
### Create a dataframe first with the input values. Then use streamlit's bar_chart function: https://docs.streamlit.io/develop/api-reference/charts/st.bar_chart
|
31 |
+
df = pd.DataFrame({
|
32 |
+
"Measurement": ["Sepal Length", "Sepal Width", "Petal Length", "Petal Width"],
|
33 |
+
"Value (cm)": [sepal_length, sepal_width, petal_length, petal_width]
|
34 |
+
})
|
35 |
+
|
36 |
+
# Use the measurement as index for better display
|
37 |
+
df.set_index("Measurement", inplace=True)
|
38 |
+
|
39 |
+
st.subheader("Entered Measurements")
|
40 |
+
st.bar_chart(df)
|
41 |
+
|
iris_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a5829ca86fd591898be1994c42c919f4f705748401e08ccf788ffeb8a50ae2f4
|
3 |
+
size 943
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
scikit-learn
|
3 |
+
joblib
|
4 |
+
numpy
|