Spaces:
Sleeping
Sleeping
# import gradio as gr | |
# import cv2 | |
# from ultralytics import YOLO | |
# model0 = YOLO('yolov8.pt') | |
# model1 = YOLO('yolov8.pt') | |
# model2 = YOLO('yolov8.pt') | |
# model3 = YOLO('yolov8.pt') | |
# model4 = YOLO('yolov8.pt') | |
# model5 = YOLO('yolov8.pt') | |
# models = [model0, model1, model2, model3, model4, model5] | |
# model_names = ["Model 0", "Model 1", "Model 2", "Model 3", "Model 4", "Model 5"] | |
# def show_preds_image(image, model_selection=0): | |
# img = image.read() | |
# outputs = models[model_selection].predict(source=img) | |
# results = outputs[0].cpu().numpy() | |
# for i, det in enumerate(results.boxes.xyxy): | |
# cv2.rectangle( | |
# img, | |
# (int(det[0]), int(det[1])), | |
# (int(det[2]), int(det[3])), | |
# color=(0, 0, 255), | |
# thickness=2, | |
# lineType=cv2.LINE_AA | |
# ) | |
# return cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
# interface_image = gr.Interface( | |
# fn=show_preds_image, | |
# inputs=[ | |
# gr.inputs.Image(type="file", label="Input Image"), | |
# gr.inputs.Dropdown( | |
# choices=[(name, idx) for idx, name in enumerate(model_names)], | |
# label="Select Model", | |
# default=0 | |
# ) | |
# ], | |
# outputs=gr.outputs.Image(type="numpy", label="Output Image"), | |
# title="Panicle detector app", | |
# ) | |
# interface_image.launch() | |
import gradio as gr | |
import cv2 | |
import requests | |
import os | |
from ultralytics import YOLO | |
model0 = YOLO('yolov8.pt') | |
model1 = YOLO('yolov8.pt') | |
model2 = YOLO('yolov8.pt') | |
model3 = YOLO('yolov8.pt') | |
model4 = YOLO('yolov8.pt') | |
model5 = YOLO('yolov8.pt') | |
models = [] | |
models.append(model0) | |
models.append(model1) | |
models.append(model2) | |
models.append(model3) | |
models.append(model4) | |
models.append(model5) | |
path = [['flowering.png']] | |
def show_preds_image(image_path, selection): | |
image = cv2.imread(image_path) | |
outputs = models[selection].predict(source=image_path) | |
results = outputs[0].cpu().numpy() | |
for i, det in enumerate(results.boxes.xyxy): | |
cv2.rectangle( | |
image, | |
(int(det[0]), int(det[1])), | |
(int(det[2]), int(det[3])), | |
color=(0, 0, 255), | |
thickness=2, | |
lineType=cv2.LINE_AA | |
) | |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | |
inputs = [ | |
gr.components.Image(type="filepath", label="Input Image"), | |
gr.components.Dropdown(choices=[str(i) for i in range(len(models))], label="Select Model", type="index"), | |
] | |
outputs_image = [ | |
gr.components.Image(type="numpy", label="Output Image"), | |
] | |
model_select = [] | |
interface_image = gr.Interface( | |
fn=show_preds_image, | |
inputs=inputs, | |
outputs=outputs_image, | |
title="Panicle detector app", | |
examples=path, | |
cache_examples=False, | |
) | |
gr.TabbedInterface( | |
[interface_image], | |
tab_names=['Image inference'] | |
).queue().launch() |