nehulagrawal's picture
Update app.py
f66b379
raw
history blame
1.17 kB
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)