Nonabzbssbbsbs commited on
Commit
fbb9909
·
verified ·
1 Parent(s): 0c02f1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -9
app.py CHANGED
@@ -2,21 +2,40 @@ import gradio as gr
2
  from ultralytics import YOLO
3
  from PIL import Image
4
 
5
- # Pretrained YOLOv8n моделін жүктеу (ең жеңіл нұсқа)
6
  model = YOLO('yolov8n.pt')
7
 
8
- # Қоқыс жәшігін тексеру функциясы
9
  def check_trash(img):
10
  results = model(img)
11
  boxes = results[0].boxes
12
- output = []
 
 
 
13
  for box in boxes:
14
- label = box.cls.item()
15
  conf = box.conf.item()
16
- if conf > 0.5: # сенімділік threshold
17
- output.append(f"{results[0].names[int(label)]}: {conf*100:.1f}%")
18
- if not output:
19
- return "Қоқыс табылмады"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  return "\n".join(output)
21
 
22
  # Gradio интерфейсі
@@ -25,7 +44,7 @@ app = gr.Interface(
25
  inputs=gr.Image(type="pil"),
26
  outputs=gr.Textbox(),
27
  title="SmartCity Waste Detection",
28
- description="Қоқыс жәшігін, сыртқа төгілген қоқысты және түрін анықтайды"
29
  )
30
 
31
  app.launch()
 
2
  from ultralytics import YOLO
3
  from PIL import Image
4
 
5
+ # Pretrained YOLOv8n моделін жүктеу
6
  model = YOLO('yolov8n.pt')
7
 
8
+ # Қоқыс жәшігін тексеру және дабыл шығару функциясы
9
  def check_trash(img):
10
  results = model(img)
11
  boxes = results[0].boxes
12
+ detected_bins = []
13
+ detected_trash = []
14
+
15
+ # detected object-терді тексеру
16
  for box in boxes:
17
+ label = results[0].names[int(box.cls.item())]
18
  conf = box.conf.item()
19
+ if conf < 0.5:
20
+ continue
21
+ if 'bin' in label or 'container' in label: # жәшік
22
+ detected_bins.append(label)
23
+ else: # басқа detected object-терді қоқыс деп қарау
24
+ detected_trash.append(label)
25
+
26
+ # Нәтижені шығару
27
+ output = []
28
+ if detected_bins:
29
+ if detected_trash:
30
+ output.append("Жәшік: Толы ✅")
31
+ else:
32
+ output.append("Жәшік: Бос ⚪")
33
+ else:
34
+ output.append("Жәшік табылмады ❌")
35
+
36
+ if detected_trash:
37
+ output.append(f"Сыртқа шыққан қоқыс табылды 🚨: {', '.join(detected_trash)}")
38
+
39
  return "\n".join(output)
40
 
41
  # Gradio интерфейсі
 
44
  inputs=gr.Image(type="pil"),
45
  outputs=gr.Textbox(),
46
  title="SmartCity Waste Detection",
47
+ description="Қоқыс жәшігін, сыртқа төгілген қоқысты және толық/бос жәшікті анықтайды"
48
  )
49
 
50
  app.launch()