|
import gradio as gr |
|
from ultralytics import YOLO |
|
|
|
|
|
categories =['Defective_Tyre','Good_Tyre'] |
|
|
|
|
|
|
|
def image_classifier(inp): |
|
model = YOLO("best.pt") |
|
|
|
result = model.predict(source=inp) |
|
probs = result[0].probs.data |
|
|
|
|
|
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) |
|
|
|
|
|
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) |