File size: 834 Bytes
cab2178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from transformers import pipeline

# Tải model phân loại rác từ Hugging Face
# Sử dụng model yangy50/garbage-classification như đã trích dẫn ở phần 1
classifier = pipeline("image-classification", model="yangy50/garbage-classification")

def predict(image):
    # Dự đoán và trả về kết quả dưới dạng dictionary {nhãn: độ tin cậy}
    predictions = classifier(image)
    return {p["label"]: p["score"] for p in predictions}

# Tạo giao diện Webapp
iface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=3),
    title="Ứng dụng Phân loại Rác (AI Waste Classification)",
    description="Tải ảnh lên để AI nhận diện loại rác: Cardboard, Glass, Metal, Paper, Plastic, Trash."
)

iface.launch()