Spaces:
Build error
Build error
| import gradio as gr | |
| from tensorflow.keras import models, layers | |
| # Define model architecture | |
| input_shape = (None, image_size, image_size, channels) | |
| n_classes = 3 | |
| model = models.Sequential([ | |
| resize_and_rescale, | |
| data_augmentation, | |
| layers.Conv2D(64, kernel_size=3, activation='relu', input_shape=input_shape), | |
| layers.MaxPooling2D((2, 2)), | |
| layers.Conv2D(64, kernel_size=(3, 3), activation='relu'), | |
| layers.MaxPooling2D((2, 2)), | |
| layers.Conv2D(64, kernel_size=(3, 3), activation='relu'), | |
| layers.MaxPooling2D((2, 2)), | |
| layers.Conv2D(64, kernel_size=(3, 3), activation='relu'), | |
| layers.MaxPooling2D((2, 2)), | |
| layers.Conv2D(64, kernel_size=(3, 3), activation='relu'), | |
| layers.MaxPooling2D((2, 2)), | |
| layers.Flatten(), | |
| layers.Dense(64, activation='relu'), | |
| layers.Dense(n_classes, activation='softmax') | |
| ]) | |
| # Load pre-trained weights | |
| model.load_weights('model911.h5') | |
| # Function to make predictions | |
| def classify_image(image): | |
| # Preprocess image if necessary | |
| # Make prediction | |
| prediction = model.predict(image) | |
| classes = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy'] | |
| return {classes[i]: float(prediction[0][i]) for i in range(len(classes))} | |
| # Input component | |
| inputs = gr.inputs.Image(shape=(image_size, image_size)) | |
| # Output component | |
| outputs = gr.outputs.Label(num_top_classes=3) | |
| # Create Gradio interface | |
| gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title='Potato Plant Diseases Classifier').launch() | |