Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
from tensorflow.keras.preprocessing import image
|
5 |
+
import tensorflow as tf
|
6 |
+
|
7 |
+
# Load the saved model
|
8 |
+
model = load_model('acres-ppdc-01.keras')
|
9 |
+
|
10 |
+
# Define the classes the model was trained on
|
11 |
+
class_labels = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
|
12 |
+
|
13 |
+
def classify_potato_plant(img):
|
14 |
+
# Preprocess the image for the model
|
15 |
+
img = img.resize((256, 256)) # Resize to the same size the model was trained on
|
16 |
+
img = image.img_to_array(img)
|
17 |
+
img = np.expand_dims(img, axis=0)
|
18 |
+
img = img / 255.0 # Normalize the image
|
19 |
+
|
20 |
+
# Make the prediction
|
21 |
+
predictions = model.predict(img)
|
22 |
+
predicted_class = np.argmax(predictions[0])
|
23 |
+
confidence = predictions[0][predicted_class]
|
24 |
+
|
25 |
+
# Get the predicted class and confidence score
|
26 |
+
return class_labels[predicted_class], confidence
|
27 |
+
|
28 |
+
# Create the Gradio interface
|
29 |
+
interface = gr.Interface(
|
30 |
+
fn=classify_potato_plant,
|
31 |
+
inputs=gr.inputs.Image(type="pil"),
|
32 |
+
outputs=[gr.outputs.Label(num_top_classes=1), gr.outputs.Textbox(label="Confidence Score")]
|
33 |
+
)
|
34 |
+
|
35 |
+
# Launch the app
|
36 |
+
if __name__ == "__main__":
|
37 |
+
interface.launch()
|