ML2 / app.py
Nurisslam's picture
Update app.py
4233955 verified
import gradio as gr
from ultralytics import YOLO
# ---- Модельді жүктеу ----
# Мұнда сен өзіңнің fine-tune жасаған моделі "car_damage.pt" файлын қолданасың
# Мысалы, label тізімі: ["Бампер бұзылған", "Крыло майысқан", "Фара сынған", "Шина зақымдалған"]
model = YOLO("yolov8n.pt")
# ---- Predict функциясы ----
def detect_damage(image):
results = model(image)
# Annotated image (рамка салынған сурет)
annotated = results[0].plot() # numpy image
# Text results
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)
# ---- Gradio интерфейс ----
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()