-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (49 loc) · 2.15 KB
/
main.py
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
51
52
53
54
55
import streamlit as st
import tensorflow as tf
import numpy as np
#Tensorflow Model Prediction
def model_prediction(test_image):
model = tf.keras.models.load_model("trained_model.h5")
image = tf.keras.preprocessing.image.load_img(test_image,target_size=(64,64))
input_arr = tf.keras.preprocessing.image.img_to_array(image)
input_arr = np.array([input_arr]) #convert single image to batch
predictions = model.predict(input_arr)
return np.argmax(predictions) #return index of max element
#Sidebar
st.sidebar.title("Dashboard")
app_mode = st.sidebar.selectbox("Select Page",["Home","About Project","Prediction"])
#Main Page
if(app_mode=="Home"):
st.header("FRUITS & VEGETABLES RECOGNITION SYSTEM")
image_path = "home_img.jpg"
st.image(image_path)
#About Project
elif(app_mode=="About Project"):
st.header("About Project")
st.subheader("About Dataset")
st.text("This dataset contains images of the following food items:")
st.code("fruits- banana, apple, pear, grapes, orange, kiwi, watermelon, pomegranate, pineapple, mango.")
st.code("vegetables- cucumber, carrot, capsicum, onion, potato, lemon, tomato, raddish, beetroot, cabbage, lettuce, spinach, soy bean, cauliflower, bell pepper, chilli pepper, turnip, corn, sweetcorn, sweet potato, paprika, jalepeño, ginger, garlic, peas, eggplant.")
st.subheader("Content")
st.text("This dataset contains three folders:")
st.text("1. train (100 images each)")
st.text("2. test (10 images each)")
st.text("3. validation (10 images each)")
#Prediction Page
elif(app_mode=="Prediction"):
st.header("Model Prediction")
test_image = st.file_uploader("Choose an Image:")
if(st.button("Show Image")):
st.image(test_image,width=4,use_column_width=True)
#Predict button
if(st.button("Predict")):
st.snow()
st.write("Our Prediction")
result_index = model_prediction(test_image)
#Reading Labels
with open("labels.txt") as f:
content = f.readlines()
label = []
for i in content:
label.append(i[:-1])
st.success("Model is Predicting it's a {}".format(label[result_index]))