Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (38 loc) · 1.46 KB
/
Copy pathapp.py
File metadata and controls
50 lines (38 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import streamlit as st
import pandas as pd
import numpy as np
import joblib
def predict(data):
clf = joblib.load("rf_model.sav")
return clf.predict(data)
# Function to map classes to images
def class_to_image(class_index):
class_names = {0: "setosa", 1: "versicolor", 2: "virginica"}
class_name = class_names.get(class_index, "setosa")
return f"images/{class_name}.jpg"
st.title('Classifying Iris Flowers')
st.markdown('Model to classify iris flowers into \
(setosa, versicolor, virginica) based on their sepal/petal \
and length/width.')
st.header("Plant Features")
col1, col2 = st.columns(2)
with col1:
st.text("Sepal characteristics")
sepal_l = st.slider('Sepal length (cm)', 1.0, 8.0, 0.5)
sepal_w = st.slider('Sepal width (cm)', 2.0, 4.4, 0.5)
with col2:
st.text("Petal characteristics")
petal_l = st.slider('Petal length (cm)', 1.0, 7.0, 0.5)
petal_w = st.slider('Petal width (cm)', 0.1, 2.5, 0.5)
st.text('')
if st.button("Predict type of Iris"):
result = predict(
np.array([[sepal_l, sepal_w, petal_l, petal_w]]))
# Map numeric prediction to class name
class_names = {0: "setosa", 1: "versicolor", 2: "virginica"}
predicted_class = class_names.get(result[0], "unknown")
st.text(f"Predicted: {predicted_class}")
# Display the image/icon corresponding to the predicted class
image_path = class_to_image(result[0])
st.image(image_path, use_container_width=True)
st.text('')