Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,12 +18,6 @@ def load_models():
|
|
18 |
model_name = 'Model/mango_model.h5'
|
19 |
model = tf.keras.models.load_model(model_name)
|
20 |
return model
|
21 |
-
|
22 |
-
def load_labels():
|
23 |
-
with open('dataset_labels.txt', 'r') as file:
|
24 |
-
data = file.read().splitlines()
|
25 |
-
mango_dict = dict(enumerate(data, 1))
|
26 |
-
return mango_dict
|
27 |
|
28 |
def load_image():
|
29 |
uploaded_file = st.file_uploader(label='Pick an image to test')
|
@@ -36,7 +30,7 @@ def load_image():
|
|
36 |
else:
|
37 |
return None
|
38 |
|
39 |
-
def predict(model,
|
40 |
img_array = tf.keras.preprocessing.image.img_to_array(img)
|
41 |
prediction = [img_array]
|
42 |
prediction_test = [1]
|
@@ -44,31 +38,20 @@ def predict(model, categories, img):
|
|
44 |
test_ds = test_ds.cache().batch(32).prefetch(buffer_size = tf.data.experimental.AUTOTUNE)
|
45 |
|
46 |
prediction = model.predict(test_ds)
|
47 |
-
prediction_dict = dict(enumerate(prediction.flatten(), 1))
|
48 |
-
k = Counter(prediction_dict)
|
49 |
-
|
50 |
-
# Finding 3 highest values
|
51 |
-
high = k.most_common(3)
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
flowers.append(categories[key])
|
58 |
-
percentages.append(np.round(value*100, 2))
|
59 |
-
return flowers, percentages
|
60 |
|
61 |
def main():
|
62 |
st.title('Mango Ripeness Classifier 🥭')
|
63 |
model = load_models()
|
64 |
-
categories = load_labels()
|
65 |
image = load_image()
|
66 |
result = st.button('Run on image')
|
67 |
if result:
|
68 |
st.write('Calculating results...')
|
69 |
-
|
70 |
-
st.text(flowers)
|
71 |
-
st.text(percentages)
|
72 |
|
73 |
if __name__ == '__main__':
|
74 |
main()
|
|
|
18 |
model_name = 'Model/mango_model.h5'
|
19 |
model = tf.keras.models.load_model(model_name)
|
20 |
return model
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def load_image():
|
23 |
uploaded_file = st.file_uploader(label='Pick an image to test')
|
|
|
30 |
else:
|
31 |
return None
|
32 |
|
33 |
+
def predict(model, img):
|
34 |
img_array = tf.keras.preprocessing.image.img_to_array(img)
|
35 |
prediction = [img_array]
|
36 |
prediction_test = [1]
|
|
|
38 |
test_ds = test_ds.cache().batch(32).prefetch(buffer_size = tf.data.experimental.AUTOTUNE)
|
39 |
|
40 |
prediction = model.predict(test_ds)
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
if prediction[0]>0.5:
|
43 |
+
return 'unripe'
|
44 |
+
else:
|
45 |
+
return 'ripe'
|
|
|
|
|
|
|
46 |
|
47 |
def main():
|
48 |
st.title('Mango Ripeness Classifier 🥭')
|
49 |
model = load_models()
|
|
|
50 |
image = load_image()
|
51 |
result = st.button('Run on image')
|
52 |
if result:
|
53 |
st.write('Calculating results...')
|
54 |
+
st.write(predict(model, image))
|
|
|
|
|
55 |
|
56 |
if __name__ == '__main__':
|
57 |
main()
|