File size: 1,166 Bytes
e09ba31
f90b008
e09ba31
f90b008
00ac4ab
e09ba31
f90b008
943fd64
f90b008
 
3a3705f
f90b008
 
943fd64
f90b008
 
e09ba31
74db328
f90b008
f66b379
52973d2
55abc26
943fd64
f90b008
 
 
 
 
 
 
 
 
 
 
a5254ee
f90b008
 
 
 
 
 
 
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

# catgories
categories =['Defective_Tyre','Good_Tyre']

# returning classifiers output

def image_classifier(inp):
    model = YOLO("best.pt")

    result = model.predict(source=inp)
    probs = result[0].probs.data

    # Combine the two lists and sort based on values in descending order
    sorted_pairs = sorted(zip(categories, probs), key=lambda x: x[1], reverse=True)

    result = []
    for name, value in sorted_pairs:
        result.append(f'{name}: {value * 100:.2f}%')

    return ', '.join(result)

# gradio code block for input and output
with gr.Blocks() as app:
    gr.Markdown("## Classification for tyre Quality measure (Good tyre and defective tyre) on Yolo-v8")
    with gr.Row():
        inp_img = gr.Image()
        out_txt = gr.Textbox()
    btn = gr.Button(value="Submeter")
    btn.click(image_classifier, inputs=inp_img, outputs=out_txt)

    gr.Markdown("## Exemplos")
    gr.Examples(
        examples=['Sample/Good tyre.png', 'Sample/Bald tyre.jpg'],
        inputs=inp_img,
        outputs=out_txt,
        fn=image_classifier,
        cache_examples=True,
    )

app.launch(share=True)