|
|
import gradio as gr |
|
|
from ultralytics import YOLO |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model = YOLO("yolov8n.pt") |
|
|
|
|
|
|
|
|
def detect_damage(image): |
|
|
results = model(image) |
|
|
|
|
|
|
|
|
annotated = results[0].plot() |
|
|
|
|
|
|
|
|
text_outputs = [] |
|
|
for box in results[0].boxes: |
|
|
cls_id = int(box.cls[0].item()) |
|
|
label = model.names[cls_id] |
|
|
conf = float(box.conf[0].item()) |
|
|
text_outputs.append(f"{label} (сенімділік: {conf:.2f})") |
|
|
|
|
|
if not text_outputs: |
|
|
text_outputs.append("✅ Ақау табылған жоқ") |
|
|
|
|
|
return annotated, "\n".join(text_outputs) |
|
|
|
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=detect_damage, |
|
|
inputs=gr.Image(type="pil", label="Машина суретін жүктеңіз"), |
|
|
outputs=[ |
|
|
gr.Image(type="numpy", label="Ақауы белгіленген сурет"), |
|
|
gr.Textbox(label="Диагноз") |
|
|
], |
|
|
title="🚗 Машина зақымын анықтау", |
|
|
description="ИИ машинаның қай бөлігі бұзылғанын рамкамен және мәтін түрінде көрсетеді." |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|