File size: 1,609 Bytes
eb5d0a3
6401bea
 
8dc6ea9
eb5d0a3
6401bea
4081e63
af1e476
6401bea
 
 
 
 
 
eb5d0a3
6401bea
 
 
97a5f47
6401bea
 
97a5f47
 
 
6401bea
97a5f47
6401bea
97a5f47
 
eb5d0a3
fa42fb9
6401bea
fa42fb9
 
6401bea
 
 
fd37f56
 
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
import gradio as gr
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
import numpy as np

# Load your Keras model
model = load_model('vege_classifier_model.h5')

# Define the updated classes
classes = [
    'Bean', 'Bitter_Gourd', 'Bottle_Gourd', 'Brinjal', 'Broccoli', 
    'Cabbage', 'Capsicum', 'Carrot', 'Cauliflower', 'Cucumber', 
    'Papaya', 'Potato', 'Pumpkin', 'Radish', 'Tomato'
]

# Define a prediction function
def predict_image(img):
    # Preprocess the image to fit the model's input requirements
    img = img.resize((224, 224))  # Match the model's expected input size
    img_array = image.img_to_array(img)
    img_array = np.expand_dims(img_array, axis=0)  # Create a batch
    img_array /= 255.0  # Rescale the image to [0, 1] to match training preprocessing
    
    # Predict with your model
    predictions = model.predict(img_array)
    predicted_class_index = np.argmax(predictions, axis=1)
    
    # Assuming 'classes' is a list of class names in the order they are represented in the model
    return classes[predicted_class_index[0]]

# Create a simplified Gradio interface
iface = gr.Interface(fn=predict_image, 
                     inputs="image", 
                     outputs="label", 
                     title="Vegetable Image Classifier",
                     description="Classify images of various vegetables into 15 categories: Bean, Bitter Gourd, Bottle Gourd, Brinjal, Broccoli, Cabbage, Capsicum, Carrot, Cauliflower, Cucumber, Papaya, Potato, Pumpkin, Radish, Tomato.")

if __name__ == "__main__":
    iface.launch()