Spaces:
Build error
Build error
| import torch | |
| import gradio as gr | |
| from huggingface_hub import hf_hub_download | |
| from PIL import Image | |
| REPO_ID = "camilacorreamelo/sugerydetection" | |
| FILENAME = "best (2).pt" | |
| yolov5_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME) | |
| model = torch.hub.load('ultralytics/yolov5', 'custom', path=yolov5_weights, force_reload=True) # local repo | |
| def object_detection(im, size=640): | |
| results = model(im) # inference | |
| #results.print() # print results to screen | |
| #results.show() # display results | |
| #results.save() # save as results1.jpg, results2.jpg... etc. | |
| results.render() # updates results.imgs with boxes and labels | |
| return Image.fromarray(results.ims[0]) | |
| title = "Surgery Instruments Detection" | |
| description = """This model helps to detect surgery instruments. It may help to medical shcool classes | |
| """ | |
| image = gr.inputs.Image(shape=(640, 640), image_mode="RGB", source="upload", label="Imagem", optional=False) | |
| outputs = gr.outputs.Image(type="pil", label="Output Image") | |
| gr.Interface( | |
| fn=object_detection, | |
| inputs=image, | |
| outputs=outputs, | |
| title=title, | |
| description=description, | |
| examples=[["example/01.jpg"], ["example/02.jpg"], | |
| ["example/03.jpg"], ["example/04.jpg"], ["example/05.jpg"], | |
| ["example/06.jpg"]]).launch() |