srijonashraf commited on
Commit
f8dc06f
1 Parent(s): ef71904

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from tensorflow.keras.models import load_model
5
+
6
+ # Load your model with the new path
7
+ model_path = 'best_model.keras'
8
+ model = load_model(model_path)
9
+
10
+ # Define the image size your model expects
11
+ IMG_SIZE = (224, 224)
12
+
13
+ # Define class names
14
+ class_names = [
15
+ 'Corn___Common_Rust',
16
+ 'Corn___Gray_Leaf_Spot',
17
+ 'Corn___Healthy',
18
+ 'Corn___Northern_Leaf_Blight',
19
+ 'Corn___Northern_Leaf_Spot',
20
+ 'Corn___Phaeosphaeria_Leaf_Spot'
21
+ ]
22
+
23
+ # Define prediction function
24
+ def predict(image):
25
+ img_array = tf.image.resize(image, IMG_SIZE)
26
+ img_array = tf.expand_dims(img_array, axis=0) / 255.0
27
+
28
+ predictions = model.predict(img_array)
29
+ predicted_class = np.argmax(predictions[0])
30
+ confidence = np.max(predictions[0])
31
+
32
+ if confidence <= 0.8:
33
+ return "Unknown Object"
34
+ else:
35
+ return {class_names[predicted_class]: float(confidence)}
36
+
37
+ # Create Gradio interface
38
+ interface = gr.Interface(
39
+ fn=predict,
40
+ inputs=gr.Image(type="pil"),
41
+ outputs=gr.Label(num_top_classes=6),
42
+ title="Maize Leaf Disease Detection",
43
+ description="Upload an image of a maize leaf to classify its disease."
44
+ )
45
+
46
+ # Launch the interface
47
+ if __name__ == "__main__":
48
+ interface.launch()