Pranjal-psytech commited on
Commit
f1d45e3
1 Parent(s): 90a3647
Files changed (3) hide show
  1. app.py +66 -4
  2. potatoesV3.h5 +3 -0
  3. requirements.txt +5 -0
app.py CHANGED
@@ -1,7 +1,69 @@
 
 
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import tensorflow as tf
3
  import gradio as gr
4
+ from PIL import Image
5
+ from io import BytesIO
6
+ import matplotlib.pyplot as plt
7
 
 
 
8
 
9
+ # Load the trained TensorFlow model using the Keras API
10
+ model = tf.keras.models.load_model("potatoesV3.h5")
11
+
12
+ # Define the class names for classification
13
+ CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"]
14
+
15
+
16
+ # Define the function for making predictions
17
+ def classify_image(image):
18
+ # Open the image using Pillow
19
+ img = Image.fromarray(image.astype('uint8'), 'RGB')
20
+ new_size = (256, 256)
21
+ img_resized = img.resize(new_size)
22
+ #img_array = np.array(img_resized)
23
+ #img_scaled = img_array / 255.0
24
+ img_array = np.expand_dims(img_resized, axis=0)
25
+ pred = model.predict(img_array)
26
+
27
+ predicted_class = CLASS_NAMES[np.argmax(pred[0])]
28
+ confidence = float(np.max(pred[0]))
29
+
30
+ # Return the predicted class and confidence score
31
+ return {"class": predicted_class, "confidence": confidence,"predict":pred[0]}
32
+ # Resize the image to the desired size
33
+ # new_size = (256, 256)
34
+ # img_resized = image.resize(new_size)
35
+
36
+ # # Convert the image to a numpy array
37
+ # img_array = np.array(img_resized)
38
+
39
+ # # Rescale the image pixel values to [0, 1]
40
+ # img_scaled = img_array / 255.0
41
+
42
+ # #img_array = np.array(img_scaled)
43
+ # img_array = np.expand_dims(img_scaled, axis=0)
44
+ # pred = model.predict(img_array)
45
+
46
+ # # Display the rescaled image
47
+ # #plt.imshow(img_array)
48
+
49
+ # # Format the predicted class and confidence score
50
+ # predicted_class = CLASS_NAMES[np.argmax(pred[0])]
51
+ # confidence = float(np.max(pred[0]))
52
+
53
+ # # Return the predicted class and confidence score
54
+ # return {"class": predicted_class, "confidence": confidence,"predict":pred[0]}
55
+ # img = (BytesIO(image))
56
+ # img = img.resize((256, 256))
57
+ # img_array = np.array(img)
58
+ # img_array = np.expand_dims(img_array, axis=0)
59
+ # pred = model.predict(img_array)
60
+ # return pred[0][0]
61
+
62
+ # Define the Gradio interface for image input
63
+ input_interface = gr.inputs.Image()
64
+
65
+ # Define the Gradio interface for displaying the predicted class and confidence score
66
+ output_interface = gr.Textbox()
67
+
68
+ # Launch the Gradio interface with the classify_image function as the prediction function
69
+ gr.Interface(fn=classify_image, inputs=input_interface, outputs=output_interface).launch()
potatoesV3.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b00b98de869b8adcb804800e0f5277fc078963668a6b7ff50e8718bdbdfea531
3
+ size 2282408
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy
2
+ tensorflow
3
+ gradio
4
+ pillow
5
+ matplotlib