nihal177 commited on
Commit
5b3aad0
·
verified ·
1 Parent(s): ef1f0f7

Upload 5 files

Browse files
Files changed (5) hide show
  1. Model/mango_model.h5 +3 -0
  2. README.md +4 -4
  3. app.py +75 -0
  4. dataset_labels.txt +2 -0
  5. requirements.txt +0 -0
Model/mango_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d044730f579c767f367bfd8bbcc96c61f6b8fa2fe28a5284b9d7069b86487a99
3
+ size 107572392
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
  title: Mango Ripeness Classifier
3
- emoji: 📚
4
- colorFrom: purple
5
- colorTo: yellow
6
  sdk: streamlit
7
- sdk_version: 1.32.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
  title: Mango Ripeness Classifier
3
+ emoji: 🥭
4
+ colorFrom: red
5
+ colorTo: pink
6
  sdk: streamlit
7
+ sdk_version: 1.25.0
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # All imports
2
+ import streamlit as st
3
+ import tensorflow as tf
4
+ from tensorflow import keras
5
+ from PIL import Image
6
+ from tensorflow.keras.preprocessing import image
7
+ import io
8
+ from collections import Counter
9
+ import numpy as np
10
+
11
+ def load_image():
12
+ uploaded_file = st.file_uploader(label='Pick an image to test')
13
+ if uploaded_file is not None:
14
+ image_data = uploaded_file.getvalue()
15
+ st.image(image_data)
16
+
17
+ 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')
30
+ if uploaded_file is not None:
31
+ image_data = uploaded_file.getvalue()
32
+ st.image(image_data)
33
+ img = Image.open(io.BytesIO(image_data))
34
+ img = img.resize((224,224))
35
+ return img
36
+ else:
37
+ return None
38
+
39
+ def predict(model, categories, img):
40
+ img_array = tf.keras.preprocessing.image.img_to_array(img)
41
+ prediction = [img_array]
42
+ prediction_test = [1]
43
+ test_ds = tf.data.Dataset.from_tensor_slices((prediction, prediction_test))
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
+ percentages = []
54
+ flowers = []
55
+ for i in high:
56
+ key, value = i
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
+ flowers, percentages = predict(model, categories, image)
70
+ st.text(flowers)
71
+ st.text(percentages)
72
+
73
+ if __name__ == '__main__':
74
+ main()
75
+
dataset_labels.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ unripe
2
+ ripe
requirements.txt ADDED
Binary file (4.57 kB). View file