Spaces:
Running
Running
Add livestock model to demo
Browse files
app.py
CHANGED
|
@@ -10,21 +10,21 @@ def show_trees(img_path):
|
|
| 10 |
raise gr.Error(f"Error initializing the deepforest model: {model_error}")
|
| 11 |
|
| 12 |
img=cv2.imread(img_path)
|
| 13 |
-
|
| 14 |
if img is None:
|
| 15 |
raise gr.Error(f"Image path is not valid.")
|
| 16 |
-
|
| 17 |
if img.shape[0]<1000 and img.shape[1]<1000:
|
| 18 |
img = model.predict_image(path=img_path, return_plot=True)
|
| 19 |
elif img.shape[0]>1000 or img.shape[1]>1000:
|
| 20 |
img=model.predict_image(path=img_path,return_plot=True,thickness=2)
|
| 21 |
else:
|
| 22 |
-
img = model.predict_image(path=img_path, return_plot=True,thickness=3)
|
| 23 |
-
|
| 24 |
if img is None:
|
| 25 |
raise gr.Error("No predictions were made. Check your test image. Ensure it conists")
|
| 26 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 27 |
-
|
| 28 |
return img
|
| 29 |
|
| 30 |
def show_birds(img_path):
|
|
@@ -34,21 +34,45 @@ def show_birds(img_path):
|
|
| 34 |
except Exception as model_error:
|
| 35 |
raise gr.Error(f"Error initializing the deepforest model: {model_error}")
|
| 36 |
img=cv2.imread(img_path)
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
if img is None:
|
| 39 |
raise gr.Error(f"Image path is not valid.")
|
| 40 |
-
|
| 41 |
if img.shape[0]<1000 and img.shape[1]<1000:
|
| 42 |
img = model.predict_image(path=img_path, return_plot=True)
|
| 43 |
elif img.shape[0]>1000 or img.shape[1]>1000:
|
| 44 |
img=model.predict_image(path=img_path,return_plot=True,thickness=2)
|
| 45 |
else:
|
| 46 |
-
img = model.predict_image(path=img_path, return_plot=True,thickness=3)
|
| 47 |
-
|
| 48 |
if img is None:
|
| 49 |
raise gr.Error("No predictions were made. Check your test image. Ensure it conists")
|
| 50 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 51 |
-
|
| 52 |
return img
|
| 53 |
|
| 54 |
with gr.Blocks() as demo:
|
|
@@ -63,16 +87,26 @@ with gr.Blocks() as demo:
|
|
| 63 |
|
| 64 |
submit_button_trees = gr.Button("Predict trees")
|
| 65 |
submit_button_trees.click(show_trees, inputs=input_image, outputs=output_image)
|
| 66 |
-
|
| 67 |
gr.Markdown('### Predict birds')
|
| 68 |
with gr.Row():
|
| 69 |
with gr.Column():
|
| 70 |
input_image=gr.Image(label="Input image",type="filepath")
|
| 71 |
with gr.Column():
|
| 72 |
output_image=gr.Image(label="Predicted Image")
|
| 73 |
-
|
| 74 |
submit_button_birds = gr.Button("Predict birds")
|
| 75 |
submit_button_birds.click(show_birds,inputs=input_image,outputs=output_image)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
if __name__ == "__main__":
|
| 78 |
-
demo.launch()
|
|
|
|
| 10 |
raise gr.Error(f"Error initializing the deepforest model: {model_error}")
|
| 11 |
|
| 12 |
img=cv2.imread(img_path)
|
| 13 |
+
|
| 14 |
if img is None:
|
| 15 |
raise gr.Error(f"Image path is not valid.")
|
| 16 |
+
|
| 17 |
if img.shape[0]<1000 and img.shape[1]<1000:
|
| 18 |
img = model.predict_image(path=img_path, return_plot=True)
|
| 19 |
elif img.shape[0]>1000 or img.shape[1]>1000:
|
| 20 |
img=model.predict_image(path=img_path,return_plot=True,thickness=2)
|
| 21 |
else:
|
| 22 |
+
img = model.predict_image(path=img_path, return_plot=True,thickness=3)
|
| 23 |
+
|
| 24 |
if img is None:
|
| 25 |
raise gr.Error("No predictions were made. Check your test image. Ensure it conists")
|
| 26 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 27 |
+
|
| 28 |
return img
|
| 29 |
|
| 30 |
def show_birds(img_path):
|
|
|
|
| 34 |
except Exception as model_error:
|
| 35 |
raise gr.Error(f"Error initializing the deepforest model: {model_error}")
|
| 36 |
img=cv2.imread(img_path)
|
| 37 |
+
|
| 38 |
+
if img is None:
|
| 39 |
+
raise gr.Error(f"Image path is not valid.")
|
| 40 |
+
|
| 41 |
+
if img.shape[0]<1000 and img.shape[1]<1000:
|
| 42 |
+
img = model.predict_image(path=img_path, return_plot=True)
|
| 43 |
+
elif img.shape[0]>1000 or img.shape[1]>1000:
|
| 44 |
+
img=model.predict_image(path=img_path,return_plot=True,thickness=2)
|
| 45 |
+
else:
|
| 46 |
+
img = model.predict_image(path=img_path, return_plot=True,thickness=3)
|
| 47 |
+
|
| 48 |
+
if img is None:
|
| 49 |
+
raise gr.Error("No predictions were made. Check your test image. Ensure it conists")
|
| 50 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 51 |
+
|
| 52 |
+
return img
|
| 53 |
+
|
| 54 |
+
def show_livestock(img_path):
|
| 55 |
+
try:
|
| 56 |
+
model = main.deepforest()
|
| 57 |
+
model.load_model(model_name="weecology/deepforest-livestock")
|
| 58 |
+
except Exception as model_error:
|
| 59 |
+
raise gr.Error(f"Error initializing the deepforest model: {model_error}")
|
| 60 |
+
img=cv2.imread(img_path)
|
| 61 |
+
|
| 62 |
if img is None:
|
| 63 |
raise gr.Error(f"Image path is not valid.")
|
| 64 |
+
|
| 65 |
if img.shape[0]<1000 and img.shape[1]<1000:
|
| 66 |
img = model.predict_image(path=img_path, return_plot=True)
|
| 67 |
elif img.shape[0]>1000 or img.shape[1]>1000:
|
| 68 |
img=model.predict_image(path=img_path,return_plot=True,thickness=2)
|
| 69 |
else:
|
| 70 |
+
img = model.predict_image(path=img_path, return_plot=True,thickness=3)
|
| 71 |
+
|
| 72 |
if img is None:
|
| 73 |
raise gr.Error("No predictions were made. Check your test image. Ensure it conists")
|
| 74 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 75 |
+
|
| 76 |
return img
|
| 77 |
|
| 78 |
with gr.Blocks() as demo:
|
|
|
|
| 87 |
|
| 88 |
submit_button_trees = gr.Button("Predict trees")
|
| 89 |
submit_button_trees.click(show_trees, inputs=input_image, outputs=output_image)
|
| 90 |
+
|
| 91 |
gr.Markdown('### Predict birds')
|
| 92 |
with gr.Row():
|
| 93 |
with gr.Column():
|
| 94 |
input_image=gr.Image(label="Input image",type="filepath")
|
| 95 |
with gr.Column():
|
| 96 |
output_image=gr.Image(label="Predicted Image")
|
| 97 |
+
|
| 98 |
submit_button_birds = gr.Button("Predict birds")
|
| 99 |
submit_button_birds.click(show_birds,inputs=input_image,outputs=output_image)
|
| 100 |
|
| 101 |
+
gr.Markdown('### Predict livestock')
|
| 102 |
+
with gr.Row():
|
| 103 |
+
with gr.Column():
|
| 104 |
+
input_image=gr.Image(label="Input image",type="filepath")
|
| 105 |
+
with gr.Column():
|
| 106 |
+
output_image=gr.Image(label="Predicted Image")
|
| 107 |
+
|
| 108 |
+
submit_button_livestock = gr.Button("Predict livestock")
|
| 109 |
+
submit_button_livestock.click(show_livestock,inputs=input_image,outputs=output_image)
|
| 110 |
+
|
| 111 |
if __name__ == "__main__":
|
| 112 |
+
demo.launch()
|