jkidkwitl commited on
Commit
cab2178
·
verified ·
1 Parent(s): 9aa43ff

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Tải model phân loại rác từ Hugging Face
5
+ # Sử dụng model yangy50/garbage-classification như đã trích dẫn ở phần 1
6
+ classifier = pipeline("image-classification", model="yangy50/garbage-classification")
7
+
8
+ def predict(image):
9
+ # Dự đoán và trả về kết quả dưới dạng dictionary {nhãn: độ tin cậy}
10
+ predictions = classifier(image)
11
+ return {p["label"]: p["score"] for p in predictions}
12
+
13
+ # Tạo giao diện Webapp
14
+ iface = gr.Interface(
15
+ fn=predict,
16
+ inputs=gr.Image(type="pil"),
17
+ outputs=gr.Label(num_top_classes=3),
18
+ title="Ứng dụng Phân loại Rác (AI Waste Classification)",
19
+ description="Tải ảnh lên để AI nhận diện loại rác: Cardboard, Glass, Metal, Paper, Plastic, Trash."
20
+ )
21
+
22
+ iface.launch()