Spaces:
Runtime error
Runtime error
| import tensorflow as tf | |
| from tensorflow.keras.models import load_model | |
| import numpy as np | |
| import gradio as gr | |
| model = load_model('potatodisease.h5') | |
| class_names = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy'] | |
| # Define predict function | |
| def predict(img): | |
| img_array = tf.keras.preprocessing.image.img_to_array(img) | |
| img_array = tf.expand_dims(img_array, 0) | |
| predictions = model.predict(img_array) | |
| predicted_class = class_names[np.argmax(predictions[0])] | |
| confidence = round(100 * (np.max(predictions[0])), 2) | |
| return predicted_class, confidence | |
| # Create Gradio interface | |
| gr.Interface(fn=predict, inputs="image", outputs=["text","text"]).launch(inline=False) |