Nurisslam commited on
Commit
ffd60f3
·
verified ·
1 Parent(s): 4453abe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -23
app.py CHANGED
@@ -1,37 +1,38 @@
1
  import streamlit as st
2
- from PIL import Image, ImageDraw
3
- from transformers import pipeline
4
 
5
- # 🚗 Модельді жүктеу
6
- pipe = pipeline("object-detection", model="harpreetsahota/car-dd-segmentation-yolov11")
 
7
 
8
- st.title("🚘 Машинаның зақымын анықтау (Object Detection)")
9
 
10
  # 📂 Файлды жүктеу
11
  uploaded_file = st.file_uploader("Суретті жүктеңіз", type=["jpg","jpeg","png"])
12
 
13
- if uploaded_file is not None:
14
  image = Image.open(uploaded_file).convert("RGB")
15
  st.image(image, caption="Жүктелген сурет", use_column_width=True)
16
 
17
- # 🔍 Анализ жасау
18
  with st.spinner("Анализ жасалуда..."):
19
- preds = pipe(image)
 
20
 
21
- # 📋 Нәтижелер
22
  st.subheader("📋 Нәтиже:")
23
- for pred in preds:
24
- label = pred["label"]
25
- score = pred["score"]
26
- box = pred["box"]
27
- st.write(f"**{label}** (сенімділік: {score:.2f})")
28
-
29
- # Bounding box салу
30
- draw = ImageDraw.Draw(image)
31
- xmin, ymin, xmax, ymax = box["xmin"], box["ymin"], box["xmax"], box["ymax"]
32
- draw.rectangle(((xmin, ymin), (xmax, ymax)), outline="red", width=3)
33
- draw.text((xmin, ymin - 10), f"{label} {score:.2f}", fill="red")
34
-
35
- # 🖼️ Боялған суретті көрсету
36
- st.image(image, caption="Болжам жасалған сурет", use_column_width=True)
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from PIL import Image
3
+ from ultralytics import YOLO
4
 
5
+ # 🚗 YOLO моделін жүктеу
6
+ # Алдымен терминалда орнату керек: pip install ultralytics
7
+ model = YOLO("harpreetsahota/car-dd-segmentation-yolov11")
8
 
9
+ st.title("🚘 Машинаның зақымын анықтау (YOLO Detection)")
10
 
11
  # 📂 Файлды жүктеу
12
  uploaded_file = st.file_uploader("Суретті жүктеңіз", type=["jpg","jpeg","png"])
13
 
14
+ if uploaded_file:
15
  image = Image.open(uploaded_file).convert("RGB")
16
  st.image(image, caption="Жүктелген сурет", use_column_width=True)
17
 
 
18
  with st.spinner("Анализ жасалуда..."):
19
+ # Модельді қолдану
20
+ results = model.predict(image)
21
 
 
22
  st.subheader("📋 Нәтиже:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
+ # Нәтижелерді шығару
25
+ for r in results:
26
+ boxes = r.boxes
27
+ masks = r.masks
28
+
29
+ # Тек label + сенімділік шығару
30
+ for b in boxes:
31
+ cls = int(b.cls[0]) # класстың индексі
32
+ conf = float(b.conf[0]) # сенімділік
33
+ label = model.names[cls] # класстың аты
34
+ st.write(f"**{label}** (сенімділік: {conf:.2f})")
35
+
36
+ # Bounding box/segmentation салынған суретті алу
37
+ plotted_img = r.plot() # OpenCV форматы (numpy массив)
38
+ st.image(plotted_img, caption="Болжам жасалған сурет", use_column_width=True)