Download app.py from Nurisslam/ML3: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/spaces/Nurisslam/ML3/resolve/main/app.py
- Command line
-
hf download hf://spaces/Nurisslam/ML3/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Nurisslam/ML3/resolve/main/app.py
1.52 kB
| import streamlit as st | |
| from PIL import Image | |
| from ultralytics import YOLO | |
| # 🚗 YOLO моделін жүктеу | |
| # Алдымен терминалда орнату керек: pip install ultralytics | |
| model = YOLO("models/best.pt") | |
| st.title("🚘 Машинаның зақымын анықтау (YOLO Detection)") | |
| # 📂 Файлды жүктеу | |
| uploaded_file = st.file_uploader("Суретті жүктеңіз", type=["jpg","jpeg","png"]) | |
| if uploaded_file: | |
| image = Image.open(uploaded_file).convert("RGB") | |
| st.image(image, caption="Жүктелген сурет", use_column_width=True) | |
| with st.spinner("Анализ жасалуда..."): | |
| # Модельді қолдану | |
| results = model.predict(image) | |
| st.subheader("📋 Нәтиже:") | |
| # Нәтижелерді шығару | |
| for r in results: | |
| boxes = r.boxes | |
| masks = r.masks | |
| # Тек label + сенімділік шығару | |
| for b in boxes: | |
| cls = int(b.cls[0]) # класстың индексі | |
| conf = float(b.conf[0]) # сенімділік | |
| label = model.names[cls] # класстың аты | |
| st.write(f"**{label}** (сенімділік: {conf:.2f})") | |
| # Bounding box/segmentation салынған суретті алу | |
| plotted_img = r.plot() # OpenCV форматы (numpy массив) | |
| st.image(plotted_img, caption="Болжам жасалған сурет", use_column_width=True) | |