Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Load the trained model
|
7 |
+
model = tf.keras.models.load_model('/content/tato.h5')
|
8 |
+
|
9 |
+
# Define class labels (update with your dataset's class names)
|
10 |
+
class_labels = ['Late Blight', 'Early Blight', 'Healthy']
|
11 |
+
|
12 |
+
# Define a prediction function
|
13 |
+
def predict(image):
|
14 |
+
# Resize and preprocess the image
|
15 |
+
image = image.resize((224, 224)) # Resize to match model input size
|
16 |
+
image_array = np.array(image) / 255.0 # Normalize the image
|
17 |
+
image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
|
18 |
+
|
19 |
+
# Make predictions
|
20 |
+
predictions = model.predict(image_array)
|
21 |
+
predicted_class = class_labels[np.argmax(predictions)] # Map prediction to class label
|
22 |
+
confidence = np.max(predictions) # Get the highest confidence score
|
23 |
+
|
24 |
+
return f"Predicted Class: {predicted_class}" #with confidence {confidence:.2f}"
|
25 |
+
|
26 |
+
# Create a Gradio interface
|
27 |
+
interface = gr.Interface(
|
28 |
+
fn=predict, # The prediction function
|
29 |
+
inputs=gr.Image(type="pil"), # Input type (image as PIL object)
|
30 |
+
outputs="text", # Output type (text)
|
31 |
+
title="Plant Disease Classifier",
|
32 |
+
description="Upload an image of a plant leaf to identify its condition."
|
33 |
+
)
|
34 |
+
|
35 |
+
# Launch the interface
|
36 |
+
interface.launch()
|