Download app.py from Nurisslam/ML2: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/Nurisslam/ML2/resolve/main/app.py
- Command line
-
hf download hf://spaces/Nurisslam/ML2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Nurisslam/ML2/resolve/main/app.py
1.6 kB
| 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() | |