hitty commited on
Commit
3894a12
·
1 Parent(s): 0633e23

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +47 -0
  2. final_model.h5 +3 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import tensorflow as tf
4
+ from tensorflow.keras.applications.resnet50 import preprocess_input
5
+ from tensorflow.keras.preprocessing.image import img_to_array, load_img
6
+
7
+ # Load pre-trained model
8
+ model = tf.keras.models.load_model('./final_model.h5')
9
+
10
+ # Set page title and layout
11
+ st.title('Image Classification App')
12
+ st.markdown("""
13
+ ### Upload an image and let the model classify it!
14
+ """)
15
+
16
+ # Define vegetable names
17
+ vegetable_names = ['Bean', 'Bitter Gourd', 'Bottle Gourd', 'Brinjal', 'Broccoli', 'Cabbage',
18
+ 'Capsicum', 'Carrot', 'Cauliflower', 'Cucumber', 'Papaya', 'Potato', 'Pumpkin',
19
+ 'Radish', 'Tomato']
20
+
21
+ # File uploader
22
+ uploaded_file = st.file_uploader('Choose an image', type=['jpg', 'jpeg', 'png'])
23
+
24
+ if uploaded_file is not None:
25
+ # Display uploaded image
26
+ image = Image.open(uploaded_file)
27
+ st.image(image, caption='Uploaded Image', use_column_width=True)
28
+
29
+ # Preprocess image
30
+ image = load_img(uploaded_file, target_size=(224, 224))
31
+ img_array = img_to_array(image)
32
+ img_array = tf.expand_dims(img_array, 0)
33
+ img_array = preprocess_input(img_array)
34
+
35
+ # Make prediction
36
+ predictions = model.predict(img_array)
37
+ class_indices = tf.argmax(predictions, axis=1).numpy()
38
+ class_names = [vegetable_names[i] for i in class_indices]
39
+ confidence_values = tf.reduce_max(predictions, axis=1).numpy() * 100
40
+ decoded_predictions = list(zip(class_names, confidence_values))
41
+
42
+ # Display predictions
43
+ st.subheader('Predictions')
44
+ for pred in decoded_predictions:
45
+ label = pred[0]
46
+ confidence = pred[1]
47
+ st.write(f'Class: {label}, Confidence: {confidence:.2f}%')
final_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:deb16572c0c17f0017cbd2ea72b9c94b704be6f115f8225548858260011e7a46
3
+ size 9571744