Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
from PIL import Image
|
| 4 |
-
import torch
|
| 5 |
-
import numpy as np
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
# *******************************************************************
|
| 10 |
-
MODEL_ID = "keremberke/vit-base-patch16-224-full-empty-trash-bin"
|
| 11 |
-
CLASS_NAMES = ['Empty', 'Full']
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
# ... (Алдыңғы жауаптағыдай қате өңдеу және болжау коды)
|
| 28 |
-
if not MODEL_LOADED:
|
| 29 |
-
return {"Error": 1.0, "Check Logs": 0.0}
|
| 30 |
-
# ... (Қалған код)
|
| 31 |
-
|
| 32 |
-
try:
|
| 33 |
-
# ... (Болжам жасау)
|
| 34 |
-
return results
|
| 35 |
-
|
| 36 |
-
except Exception as e:
|
| 37 |
-
return {"Error": 1.0, "Check Logs": 0.0}
|
| 38 |
-
|
| 39 |
-
iface = gr.Interface(
|
| 40 |
-
fn=classify_trash_bin,
|
| 41 |
-
inputs=gr.Image(type="numpy", label="SmartTrachAI Input"),
|
| 42 |
-
outputs=gr.Label(num_top_classes=2, label="Prediction"),
|
| 43 |
-
title="SmartTrachAI",
|
| 44 |
-
description="Automated Trash Bin Status Detector."
|
| 45 |
)
|
| 46 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
from PIL import Image
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# Pretrained модельді жүктеу
|
| 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:
|
| 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 интерфейсі
|
| 23 |
+
app = gr.Interface(
|
| 24 |
+
fn=check_trash,
|
| 25 |
+
inputs=gr.Image(type="pil"),
|
| 26 |
+
outputs=gr.Textbox(),
|
| 27 |
+
title="SmartCity Waste Detection",
|
| 28 |
+
description="Қоқыс жәшігін, сыртқа төгілген қоқысты және түрін анықтайды"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
)
|
| 30 |
+
|
| 31 |
+
app.launch()
|