File size: 1,357 Bytes
8293818
 
 
 
 
 
14632bf
8293818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2cc4c0e
8293818
 
 
 
2cc4c0e
8293818
 
 
 
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
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

# Load the trained model
model = tf.keras.models.load_model('tato.h5')

# Define class labels (update with your dataset's class names)
class_labels = ['Late Blight', 'Early Blight', 'Healthy']

# Define a prediction function
def predict(image):
    # Resize and preprocess the image
    image = image.resize((224, 224))  # Resize to match model input size
    image_array = np.array(image) / 255.0  # Normalize the image
    image_array = np.expand_dims(image_array, axis=0)  # Add batch dimension
    
    # Make predictions
    predictions = model.predict(image_array)
    predicted_class = class_labels[np.argmax(predictions)]  # Map prediction to class label
    confidence = np.max(predictions)  # Get the highest confidence score
    
    return f"Predicted Class: {predicted_class}" #with confidence {confidence:.2f}"

# Create a Gradio interface
interface = gr.Interface(
    theme="Subh775/orchid_candy",
    fn=predict,  # The prediction function
    inputs=gr.Image(type="pil"),  # Input type (image as PIL object)
    outputs="text",  # Output type (text)
    title="Plant Disease Classifier",
    description="Upload an image of a potato plant leaf to identify its condition (Early_blight, Late_blight, Healthy)"
)

# Launch the interface
interface.launch()