omunaman commited on
Commit
717bc0e
·
1 Parent(s): d1f5535

Add application file

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """gradio.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1B520JUHmyofueyUqotN2yj6Gad69uavo
8
+ """
9
+
10
+ import gradio as gr
11
+ import tensorflow as tf
12
+
13
+ model = tf.keras.models.load_model('my_final_model.keras')
14
+
15
+ def predict_disease(image):
16
+ # Preprocess the image
17
+ img = image.reshape((-1, image.shape[0], image.shape[1], 3))
18
+ # Assuming your model expects images with 3 color channels
19
+
20
+ # Perform prediction
21
+ prediction = model.predict(img)
22
+
23
+ # Assuming prediction is a list of probabilities
24
+ labels = ['Early Blight', 'Late Blight', 'Healthy']
25
+ # Replace with your actual class labels
26
+
27
+ # Get predicted class
28
+ predicted_class = labels[prediction.argmax()]
29
+ return predicted_class
30
+
31
+ iface = gr.Interface(
32
+ fn=predict_disease,
33
+ inputs=gr.Image(shape=(224, 224)), # Adjust shape according to model's input
34
+ outputs="text",
35
+ title="Potato Disease Classification",
36
+ description="Upload an image of a potato leaf to classify its disease.",
37
+ )
38
+ iface.launch()
39
+
40
+ def predict_disease(image):
41
+ """
42
+ Preprocesses the image, performs prediction, and returns the predicted class.
43
+
44
+ Args:
45
+ image: The input image as a NumPy array.
46
+
47
+ Returns:
48
+ The predicted class label as a string.
49
+ """
50
+
51
+ # Resize the image using TensorFlow
52
+ img = tf.image.resize(image, [224, 224]) # Resize image using TensorFlow
53
+ # Add batch dimension
54
+ img = tf.expand_dims(img, axis=0)
55
+
56
+ # Assuming your model expects images with 3 color channels
57
+ # Perform prediction
58
+ prediction = model.predict(img)
59
+
60
+ # Assuming prediction is a list of probabilities
61
+ labels = ['Early Blight', 'Late Blight', 'Healthy']
62
+ # Replace with your actual class labels
63
+
64
+ # Get predicted class
65
+ predicted_class = labels[prediction.argmax()]
66
+ return predicted_class
67
+
68
+ # ... (Rest of your code) ...
69
+
70
+ iface = gr.Interface(
71
+ fn=predict_disease,
72
+ inputs=gr.Image(), # Remove shape argument
73
+ outputs="text",
74
+ title="Potato Disease Classification",
75
+ description="Upload an image of a potato leaf to classify its disease.",
76
+ )
77
+ iface.launch()