Spaces:
Sleeping
Sleeping
Upload 9 files
Browse files- .gitattributes +1 -0
- app.py +75 -0
- download (1).jpeg +0 -0
- download (2).jpeg +0 -0
- download (3).jpeg +0 -0
- fowl_pox_model.keras +3 -0
- images (1).jpeg +0 -0
- images (2).jpeg +0 -0
- images (3).jpeg +0 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
fowl_pox_model.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from keras.models import load_model
|
| 2 |
+
import cv2
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
pox_model = load_model('fowl_pox_model.keras', compile=True)
|
| 7 |
+
class_name = {0: 'Healthy', 1: 'Chicken have fowl pox', 2: 'Unknown'}
|
| 8 |
+
status = {0: 'Non Critical', 1: 'Critical', 2: 'N/A'}
|
| 9 |
+
recommend = {0: 'No need medicine', 1: 'Panadol', 2: 'N/A'}
|
| 10 |
+
|
| 11 |
+
def predict(img):
|
| 12 |
+
# Resize the image to the required size for the model
|
| 13 |
+
img_resized = cv2.resize(img, (256, 256))
|
| 14 |
+
|
| 15 |
+
# Make the prediction
|
| 16 |
+
pred = pox_model.predict(img_resized.reshape(1, 256, 256, 3)).argmax()
|
| 17 |
+
|
| 18 |
+
# Get the prediction details
|
| 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)
|
download (1).jpeg
ADDED
|
download (2).jpeg
ADDED
|
download (3).jpeg
ADDED
|
fowl_pox_model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:43fd84c267a4c486c1819b245c544f0508e72576e1ec276faea9c43b8d82e43a
|
| 3 |
+
size 218070017
|
images (1).jpeg
ADDED
|
images (2).jpeg
ADDED
|
images (3).jpeg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
keras
|
| 3 |
+
opencv-python
|