Commit
·
15365f0
1
Parent(s):
b7ca752
Upload 5 files
Browse files- app.py +62 -0
- model.sav +0 -0
- prediction_helper.py +31 -0
- requirements.txt +8 -0
- style.css +25 -0
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests as req
|
3 |
+
from streamlit_lottie import st_lottie
|
4 |
+
from prediction_helper import predict_class_way1, predict_class_way2
|
5 |
+
|
6 |
+
st.set_page_config(page_title="Welcome to Iris Classifier",page_icon=":blossom:")
|
7 |
+
|
8 |
+
with st.container():
|
9 |
+
st.title("Welcome to Iris Classifier :blossom:")
|
10 |
+
st.subheader("Author: Ahmad Baseer")
|
11 |
+
st.write("You can find the code [here](https://github.com/Ahmad-Baseer/AI-Projects)")
|
12 |
+
|
13 |
+
st.write("---")
|
14 |
+
|
15 |
+
def load_lottieurl(url):
|
16 |
+
r=req.get(url)
|
17 |
+
if r.status_code !=200:
|
18 |
+
None
|
19 |
+
return r.json()
|
20 |
+
|
21 |
+
lottie_flower=load_lottieurl("https://lottie.host/db599348-de9d-44a3-9e66-6490a4920520/jiH4zhQwAD.json")
|
22 |
+
|
23 |
+
left_col, right_col = st.columns(2)
|
24 |
+
|
25 |
+
with left_col:
|
26 |
+
# Create four input fields.
|
27 |
+
sepal_length = st.number_input("Sepal length (cm)", min_value=0.0, max_value=100.0)
|
28 |
+
sepal_width = st.number_input("Sepal width (cm)", min_value=0.0, max_value=100.0)
|
29 |
+
petal_length = st.number_input("Petal length (cm)", min_value=0.0, max_value=100.0)
|
30 |
+
petal_width = st.number_input("Petal width (cm)", min_value=0.0, max_value=100.0)
|
31 |
+
|
32 |
+
datapoint = [sepal_length,sepal_width,petal_length,petal_width]
|
33 |
+
|
34 |
+
# Display the input fields.
|
35 |
+
st.write("Sepal length:", sepal_length)
|
36 |
+
st.write("Sepal width:", sepal_width)
|
37 |
+
st.write("Petal length:", petal_length)
|
38 |
+
st.write("Petal width:", petal_width)
|
39 |
+
st.write(" **This model got accuracy of:** ", 0.8933)
|
40 |
+
|
41 |
+
if(sepal_length!=0 and sepal_width!=0 and petal_length!=0 and petal_width!=0):
|
42 |
+
st.write("---")
|
43 |
+
result_1=predict_class_way1(datapoint)
|
44 |
+
result_2=predict_class_way2(datapoint)
|
45 |
+
|
46 |
+
st.write(f" I guess 🤔 it belongs to (using method 1): **{result_1.capitalize()}** ")
|
47 |
+
st.write(f" I guess 🤔 it belongs to (using method 2): **{result_2.capitalize()}** ")
|
48 |
+
|
49 |
+
if result_1==result_2:
|
50 |
+
st.write(" **Hurray :partying_face: we got same results from both techniques!**")
|
51 |
+
|
52 |
+
with right_col:
|
53 |
+
st_lottie(lottie_flower,height=250,key="flower")
|
54 |
+
|
55 |
+
st.caption("Made with :heart: by Ahmad")
|
56 |
+
|
57 |
+
#using local css to design contact form
|
58 |
+
def local_css_for_contact_form(file_name):
|
59 |
+
with open(file_name) as f:
|
60 |
+
st.markdown(f"<style>{f.read()}</style>",unsafe_allow_html=True)
|
61 |
+
|
62 |
+
local_css_for_contact_form("style.css")
|
model.sav
ADDED
Binary file (1.45 kB). View file
|
|
prediction_helper.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import numpy as np
|
3 |
+
from sklearn import datasets
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
iris_k_mean_model=pickle.load(open('model.sav', 'rb'))
|
7 |
+
classes=['versicolor', 'setosa' , 'virginica']
|
8 |
+
|
9 |
+
iris = datasets.load_iris()
|
10 |
+
x = pd.DataFrame(iris.data, columns=['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width'])
|
11 |
+
|
12 |
+
|
13 |
+
def predict_class_way1(new_data_point):
|
14 |
+
# Calculate the Euclidean distances between the new data point and each of the training data points.
|
15 |
+
distances = np.linalg.norm(x - new_data_point, axis=1)
|
16 |
+
# print(distances,len(distances),np.argmin(distances))
|
17 |
+
|
18 |
+
# The data point with the minimum Euclidean distance is the class of the new data point.
|
19 |
+
class_label = classes[iris_k_mean_model.labels_[np.argmin(distances)]]
|
20 |
+
|
21 |
+
return class_label
|
22 |
+
|
23 |
+
def predict_class_way2(new_data_point):
|
24 |
+
# Calculate the distances between the new data point and each of the cluster centers.
|
25 |
+
distances = np.linalg.norm(iris_k_mean_model.cluster_centers_ - new_data_point, axis=1)
|
26 |
+
# print(distances,len(distances),np.argmin(distances))
|
27 |
+
|
28 |
+
# The data point with the minimum Euclidean distance is the class of the new data point.
|
29 |
+
class_label = classes[np.argmin(distances)]
|
30 |
+
|
31 |
+
return class_label
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
numpy==1.25.2
|
2 |
+
pandas==2.1.0
|
3 |
+
Requests==2.25.1
|
4 |
+
scikit_learn==1.3.0
|
5 |
+
streamlit==1.26.0
|
6 |
+
streamlit_lottie==0.0.5
|
7 |
+
matplotlib==3.7.3
|
8 |
+
seaborn==0.12.2
|
style.css
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* .css-1njjmvq.e1f1d6gn0{
|
2 |
+
right: 100px;
|
3 |
+
}
|
4 |
+
|
5 |
+
.element-container.css-1hynsf2.e1f1d6gn2{
|
6 |
+
right: 100px;
|
7 |
+
} */
|
8 |
+
|
9 |
+
p{
|
10 |
+
font-size: 18px;
|
11 |
+
font-family: 'Times New Roman';
|
12 |
+
}
|
13 |
+
|
14 |
+
/* Hide Streamlit Branding */
|
15 |
+
#MainMenu {
|
16 |
+
visibility: hidden;
|
17 |
+
}
|
18 |
+
|
19 |
+
footer {
|
20 |
+
visibility: hidden;
|
21 |
+
}
|
22 |
+
|
23 |
+
header {
|
24 |
+
visibility: hidden;
|
25 |
+
}
|