asserr commited on
Commit
2d63298
·
1 Parent(s): 3d5739b

Add application file

Browse files
Files changed (1) hide show
  1. app.py +0 -47
app.py DELETED
@@ -1,47 +0,0 @@
1
- import tensorflow as tf
2
- import numpy as np
3
- import gradio as gr
4
- import imageio
5
-
6
- # Load the pre-trained model
7
- model = tf.keras.models.load_model("D:/asser/CNN model/Tomatoleaf_CNN.h5")
8
-
9
- # Define the class labels
10
- class_names = [
11
- 'Tomato___Late_blight',
12
- 'Tomato___healthy',
13
- 'Tomato___Early_blight',
14
- 'Tomato___Septoria_leaf_spot',
15
- 'Tomato___Tomato_Yellow_Leaf_Curl_Virus',
16
- 'Tomato___Bacterial_spot',
17
- 'Tomato___Target_Spot',
18
- 'Tomato___Tomato_mosaic_virus',
19
- 'Tomato___Leaf_Mold',
20
- 'Tomato___Spider_mites Two-spotted_spider_mite'
21
- ]
22
-
23
- # Define the prediction function
24
- def predict(image):
25
- # Read and preprocess the image
26
- img = imageio.imread(image) # Load the image
27
- img = tf.image.resize(img, (128, 128)) / 255.0 # Resize and normalize
28
- img = np.expand_dims(img, axis=0) # Expand dimensions to match model input
29
-
30
- # Predict using the model
31
- predictions = model.predict(img)
32
- prediction_probabilities = predictions[0]
33
-
34
- # Map the predictions to the class labels
35
- return {class_names[i]: float(prediction_probabilities[i]) for i in range(len(class_names))}
36
-
37
- # Gradio Interface
38
- interface = gr.Interface(
39
- fn=predict,
40
- inputs=gr.Image(type="file"), # Accept an image file as input
41
- outputs=gr.Label(), # Return class labels with probabilities
42
- title="Tomato Leaf Disease Detection",
43
- description="Upload an image of a tomato leaf to identify its condition."
44
- )
45
-
46
- if __name__ == "__main__":
47
- interface.launch()