import gradio as gr import tensorflow as tf import cv2 import numpy as np def classify_image(image): # Read and resize the image image = cv2.resize(image, (100, 100)) # Normalize the image image = image / 255.0 # Expand dimensions to match the input shape of the model image = np.expand_dims(image, axis=0) # Perform prediction using the trained model prediction = model.predict(image) # Get the predicted label label = classes[np.argmax(prediction[0])] return label # Load the pre-trained model model = tf.keras.models.load_model('./my_model.h5') # Define the class labels classes = { 0: 'Bacterial_spot', 1: 'Early_blight', 2: 'Late_blight', 3: 'Leaf_Mold', 4: 'Septoria_leaf_spot', 5: 'Spider_mites', 6: 'Target_Spot', 7: 'Tomato_Yellow_Leaf_Curl_Virus', 8: 'Tomato_mosaic_virus', 9: 'healthy' } # Define the input and output interfaces for Gradio v3.x input_interface = gr.Image() # Removed 'shape' argument output_interface = gr.Textbox() # Create the Gradio interface gr.Interface(fn=classify_image, inputs=input_interface, outputs=output_interface).launch()