Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
+
|
7 |
+
# Load Model
|
8 |
+
MODEL = tf.keras.models.load_model("new_cnn_model_tf.h5")
|
9 |
+
CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"]
|
10 |
+
|
11 |
+
# Function to process and predict
|
12 |
+
def predict(image):
|
13 |
+
# Convert image to numpy array
|
14 |
+
image = np.array(image)
|
15 |
+
|
16 |
+
# Expand dimensions to match model input shape
|
17 |
+
img_batch = np.expand_dims(image, 0)
|
18 |
+
|
19 |
+
# Make prediction
|
20 |
+
predictions = MODEL.predict(img_batch)
|
21 |
+
|
22 |
+
# Get class and confidence
|
23 |
+
predicted_class = CLASS_NAMES[np.argmax(predictions[0])]
|
24 |
+
confidence = float(np.max(predictions[0]))
|
25 |
+
|
26 |
+
return f"Prediction: {predicted_class} (Confidence: {confidence:.2f})"
|
27 |
+
|
28 |
+
# Create Gradio Interface
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=predict, # Function to call
|
31 |
+
inputs=gr.Image(type="pil"), # Image input (PIL format)
|
32 |
+
outputs="text", # Text output (prediction result)
|
33 |
+
title="Potato Disease Classifier",
|
34 |
+
description="Upload an image of a potato leaf, and the model will predict whether it's Healthy, Early Blight, or Late Blight."
|
35 |
+
)
|
36 |
+
|
37 |
+
# Launch the app
|
38 |
+
iface.launch()
|