Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,57 +19,21 @@ def predict(img):
|
|
| 19 |
prediction_label = class_name[pred]
|
| 20 |
prediction_status = status[pred]
|
| 21 |
recommendation = recommend[pred]
|
| 22 |
-
|
| 23 |
-
# If the predicted label is 1, draw the bounding boxes on the image
|
| 24 |
-
if pred == 1:
|
| 25 |
-
# Example: Assuming the model provides bounding box coordinates in a list of tuples
|
| 26 |
-
# Each tuple is (x, y, w, h) for the bounding box
|
| 27 |
-
bounding_boxes = [(50, 50, 100, 100), (150, 150, 50, 50)] # Example coordinates
|
| 28 |
-
|
| 29 |
-
# Create a copy of the original image
|
| 30 |
-
img_with_boxes = img.copy()
|
| 31 |
-
|
| 32 |
-
# Scale factor to adjust bounding box coordinates
|
| 33 |
-
scale_x = img.shape[1] / 256
|
| 34 |
-
scale_y = img.shape[0] / 256
|
| 35 |
-
|
| 36 |
-
# Calculate the merged bounding box
|
| 37 |
-
min_x = min([x for (x, y, w, h) in bounding_boxes])
|
| 38 |
-
min_y = min([y for (x, y, w, h) in bounding_boxes])
|
| 39 |
-
max_x = max([x + w for (x, y, w, h) in bounding_boxes])
|
| 40 |
-
max_y = max([y + h for (x, y, w, h) in bounding_boxes])
|
| 41 |
-
|
| 42 |
-
# Scale the merged bounding box coordinates back to the original image size
|
| 43 |
-
min_x_scaled = int(min_x * scale_x)
|
| 44 |
-
min_y_scaled = int(min_y * scale_y)
|
| 45 |
-
max_x_scaled = int(max_x * scale_x)
|
| 46 |
-
max_y_scaled = int(max_y * scale_y)
|
| 47 |
-
|
| 48 |
-
# Draw the merged bounding box on the original image
|
| 49 |
-
cv2.rectangle(img_with_boxes, (min_x_scaled, min_y_scaled), (max_x_scaled, max_y_scaled), (0, 255, 0), 2)
|
| 50 |
-
else:
|
| 51 |
-
img_with_boxes = img
|
| 52 |
-
|
| 53 |
-
# Save the output image
|
| 54 |
-
output_path = 'output_image.jpg'
|
| 55 |
-
cv2.imwrite(output_path, img_with_boxes)
|
| 56 |
-
|
| 57 |
-
return img_with_boxes, prediction_label, prediction_status, recommendation, output_path
|
| 58 |
|
| 59 |
|
| 60 |
interface = gr.Interface(
|
| 61 |
fn=predict,
|
| 62 |
inputs='image',
|
| 63 |
outputs=[
|
| 64 |
-
'image',
|
| 65 |
gr.components.Textbox(label='Disease Name'),
|
| 66 |
gr.components.Textbox(label='Disease status'),
|
| 67 |
-
gr.components.Textbox(label='Disease medicine')
|
| 68 |
-
gr.components.File(label='Download Image')
|
| 69 |
],
|
| 70 |
examples=[
|
| 71 |
['download (1).jpeg'], ['download (2).jpeg'], ['download (3).jpeg'],
|
| 72 |
['images (1).jpeg'], ['images (2).jpeg'], ['images (3).jpeg']
|
| 73 |
-
]
|
|
|
|
| 74 |
)
|
| 75 |
interface.launch(debug=True)
|
|
|
|
| 19 |
prediction_label = class_name[pred]
|
| 20 |
prediction_status = status[pred]
|
| 21 |
recommendation = recommend[pred]
|
| 22 |
+
return prediction_label, prediction_status, recommendation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
interface = gr.Interface(
|
| 26 |
fn=predict,
|
| 27 |
inputs='image',
|
| 28 |
outputs=[
|
|
|
|
| 29 |
gr.components.Textbox(label='Disease Name'),
|
| 30 |
gr.components.Textbox(label='Disease status'),
|
| 31 |
+
gr.components.Textbox(label='Disease medicine')
|
|
|
|
| 32 |
],
|
| 33 |
examples=[
|
| 34 |
['download (1).jpeg'], ['download (2).jpeg'], ['download (3).jpeg'],
|
| 35 |
['images (1).jpeg'], ['images (2).jpeg'], ['images (3).jpeg']
|
| 36 |
+
],
|
| 37 |
+
description="Upload an image of a chicken to predict if it has fowl pox. You will receive a status report and a recommended treatment."
|
| 38 |
)
|
| 39 |
interface.launch(debug=True)
|