File size: 1,130 Bytes
7d73127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c89f1d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gradio as gr
from ultralytics import YOLO
from PIL import Image

model = YOLO("./best.pt")


def process_img(img: gr.Image):
    result = model.predict(img)
    for r in result:
        im_bgr = r.plot()
        return gr.Image(
            label="Output Image with labels", value=Image.fromarray(im_bgr[..., ::-1])
        )


with gr.Blocks() as demo:
    gr.Markdown(value="Port Classification App")

    with gr.Row():
        with gr.Column():
            upload_img = gr.Image(label="Upload Image", type="pil")
            classify_img_button = gr.Button(value="Process Image")

        with gr.Column():
            output_img = gr.Image(label="Output Image with labels")
    with gr.Row():
        gr.Examples(
            examples=[
                "./examples/01.jpg",
                "./examples/02.jpg",
                "./examples/03.jpg",
                "./examples/04.jpg",
                "./examples/05.jpg",
                "./examples/06.jpg",
            ],
            inputs=upload_img
        )
    classify_img_button.click(fn=process_img, inputs=upload_img, outputs=output_img)

    demo.launch()