uploaded code
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load your trained model
|
| 7 |
+
model = tf.keras.models.load_model("watermelon_leaf_model.h5") # Ensure this matches the name in your repo
|
| 8 |
+
|
| 9 |
+
# Define the prediction function
|
| 10 |
+
def predict(image):
|
| 11 |
+
# Resize the input image to match the model's input size
|
| 12 |
+
image = image.resize((128, 128)) # Adjust dimensions to match your model
|
| 13 |
+
image = np.array(image) / 255.0 # Normalize pixel values
|
| 14 |
+
image = np.expand_dims(image, axis=0) # Add batch dimension
|
| 15 |
+
prediction = model.predict(image)
|
| 16 |
+
# Replace the below with your actual class names
|
| 17 |
+
class_names = ["Anthracnose", "Downy Mildew", "Mosaic Virus", "Healthy"]
|
| 18 |
+
return {class_names[i]: float(prediction[0][i]) for i in range(len(class_names))}
|
| 19 |
+
|
| 20 |
+
# Create a Gradio interface
|
| 21 |
+
interface = gr.Interface(
|
| 22 |
+
fn=predict,
|
| 23 |
+
inputs=gr.Image(type="pil"),
|
| 24 |
+
outputs=gr.Label()
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
interface.launch()
|