Pranjal-psytech
commited on
Commit
•
2ae5525
1
Parent(s):
d7c9890
"ko:
Browse files
app.py
CHANGED
@@ -15,25 +15,40 @@ CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"]
|
|
15 |
|
16 |
# Define the function for making predictions
|
17 |
|
18 |
-
def classify_image(
|
19 |
-
# Open the
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
# Resize the image to the desired size
|
38 |
# new_size = (256, 256)
|
39 |
# img_resized = image.resize(new_size)
|
@@ -67,7 +82,7 @@ def classify_image(request):
|
|
67 |
examples=[os.path.join(os.path.dirname(__file__),'7227b3db-c212-4370-8b42-443eea1577aa___RS_Early.B 7306.JPG','7456db33-766c-4a68-b924-ddf69d579981___RS_Early.B 6723.JPG','7486e823-64f7-4e43-ab51-26261b077fc2___RS_Early.B 6785.JPG','8829e413-5a7a-4680-b873-e71dfa9dbfe4___RS_LB 3974.JPG','9001b18c-b659-4c56-9dfb-0d0bf64a7b4a___RS_LB 4987.JPG','9009c86e-1205-4694-b0bb-ef7cf78dd104___RS_LB 3995.JPG','Potato_healthy-76-_0_2420.jpg','Potato_healthy-76-_0_6833.jpg','Potato_healthy-76-_0_7539.jpg')]
|
68 |
|
69 |
# Define the Gradio interface for image input
|
70 |
-
input_interface = gr.inputs.
|
71 |
|
72 |
# Define the Gradio interface for displaying the predicted class and confidence score
|
73 |
output_interface = gr.Textbox()
|
|
|
15 |
|
16 |
# Define the function for making predictions
|
17 |
|
18 |
+
def classify_image(image):
|
19 |
+
# Open the image using Pillow
|
20 |
+
img = Image.fromarray(image.astype('uint8'), 'RGB')
|
21 |
+
new_size = (256, 256)
|
22 |
+
img_resized = img.resize(new_size)
|
23 |
+
#img_array = np.array(img_resized)
|
24 |
+
#img_scaled = img_array / 255.0
|
25 |
+
img_array = np.expand_dims(img_resized, axis=0)
|
26 |
+
pred = model.predict(img_array)
|
27 |
+
|
28 |
+
predicted_class = CLASS_NAMES[np.argmax(pred[0])]
|
29 |
+
confidence = float(np.max(pred[0]))
|
30 |
+
|
31 |
+
# Return the predicted class and confidence score
|
32 |
+
return {"class": predicted_class, "confidence": confidence,"predict":pred[0]}
|
33 |
+
#New updated def
|
34 |
+
# def classify_image(file):
|
35 |
+
# # Open the file using requests
|
36 |
+
# response = requests.get(file)
|
37 |
+
# img = Image.open(BytesIO(response.content))
|
38 |
+
|
39 |
+
# # Resize and preprocess the image
|
40 |
+
# img_resized = img.convert("RGB").resize((256, 256))
|
41 |
+
# img_array = np.array(img_resized) / 255.0
|
42 |
+
# img_array = np.expand_dims(img_array, axis=0)
|
43 |
+
|
44 |
+
# # Make predictions
|
45 |
+
# pred = model.predict(img_array)
|
46 |
+
|
47 |
+
# predicted_class = CLASS_NAMES[np.argmax(pred[0])]
|
48 |
+
# confidence = float(np.max(pred[0]))
|
49 |
+
|
50 |
+
# # Return the predicted class and confidence score
|
51 |
+
# return {"class": predicted_class, "confidence": confidence,"predict":pred[0]}
|
52 |
# Resize the image to the desired size
|
53 |
# new_size = (256, 256)
|
54 |
# img_resized = image.resize(new_size)
|
|
|
82 |
examples=[os.path.join(os.path.dirname(__file__),'7227b3db-c212-4370-8b42-443eea1577aa___RS_Early.B 7306.JPG','7456db33-766c-4a68-b924-ddf69d579981___RS_Early.B 6723.JPG','7486e823-64f7-4e43-ab51-26261b077fc2___RS_Early.B 6785.JPG','8829e413-5a7a-4680-b873-e71dfa9dbfe4___RS_LB 3974.JPG','9001b18c-b659-4c56-9dfb-0d0bf64a7b4a___RS_LB 4987.JPG','9009c86e-1205-4694-b0bb-ef7cf78dd104___RS_LB 3995.JPG','Potato_healthy-76-_0_2420.jpg','Potato_healthy-76-_0_6833.jpg','Potato_healthy-76-_0_7539.jpg')]
|
83 |
|
84 |
# Define the Gradio interface for image input
|
85 |
+
input_interface = gr.inputs.Image()
|
86 |
|
87 |
# Define the Gradio interface for displaying the predicted class and confidence score
|
88 |
output_interface = gr.Textbox()
|