wissemkarous
commited on
Commit
•
c7700ba
1
Parent(s):
f0c301b
init
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tensorflow.keras import models, layers
|
3 |
+
|
4 |
+
# Define model architecture
|
5 |
+
input_shape = (None, image_size, image_size, channels)
|
6 |
+
n_classes = 3
|
7 |
+
|
8 |
+
model = models.Sequential([
|
9 |
+
resize_and_rescale,
|
10 |
+
data_augmentation,
|
11 |
+
layers.Conv2D(64, kernel_size=3, activation='relu', input_shape=input_shape),
|
12 |
+
layers.MaxPooling2D((2, 2)),
|
13 |
+
layers.Conv2D(64, kernel_size=(3, 3), activation='relu'),
|
14 |
+
layers.MaxPooling2D((2, 2)),
|
15 |
+
layers.Conv2D(64, kernel_size=(3, 3), activation='relu'),
|
16 |
+
layers.MaxPooling2D((2, 2)),
|
17 |
+
layers.Conv2D(64, kernel_size=(3, 3), activation='relu'),
|
18 |
+
layers.MaxPooling2D((2, 2)),
|
19 |
+
layers.Conv2D(64, kernel_size=(3, 3), activation='relu'),
|
20 |
+
layers.MaxPooling2D((2, 2)),
|
21 |
+
layers.Flatten(),
|
22 |
+
layers.Dense(64, activation='relu'),
|
23 |
+
layers.Dense(n_classes, activation='softmax')
|
24 |
+
])
|
25 |
+
|
26 |
+
# Load pre-trained weights
|
27 |
+
model.load_weights('model911.h5')
|
28 |
+
|
29 |
+
# Function to make predictions
|
30 |
+
def classify_image(image):
|
31 |
+
# Preprocess image if necessary
|
32 |
+
# Make prediction
|
33 |
+
prediction = model.predict(image)
|
34 |
+
classes = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
|
35 |
+
return {classes[i]: float(prediction[0][i]) for i in range(len(classes))}
|
36 |
+
|
37 |
+
|
38 |
+
# Input component
|
39 |
+
inputs = gr.inputs.Image(shape=(image_size, image_size))
|
40 |
+
|
41 |
+
# Output component
|
42 |
+
outputs = gr.outputs.Label(num_top_classes=3)
|
43 |
+
|
44 |
+
# Create Gradio interface
|
45 |
+
gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title='Potato Plant Diseases Classifier').launch()
|