NhanSoHocCode commited on
Commit
564af2d
·
verified ·
1 Parent(s): a04f69a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py CHANGED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Tải mô hình của bạn từ Hugging Face Hub
5
+ model_id = "NhanSoHocCode/vi-toxic-comment"
6
+ classifier = pipeline("text-classification", model=model_id)
7
+
8
+ # Định nghĩa hàm để xử lý đầu vào và trả về kết quả
9
+ def classify_text(text):
10
+ # Yêu cầu model trả về kết quả cho tất cả các nhãn (label)
11
+ predictions = classifier(text, top_k=None)
12
+
13
+ # Chuyển đổi kết quả thành định dạng mà Gradio có thể hiển thị
14
+ formatted_result = {p['label']: round(p['score'], 4) for p in predictions}
15
+ return formatted_result
16
+
17
+ # Tạo giao diện Gradio
18
+ iface = gr.Interface(
19
+ fn=classify_text,
20
+ inputs=gr.Textbox(lines=5, placeholder="Nhập bình luận tiếng Việt vào đây..."),
21
+ outputs="label",
22
+ title="Phân loại bình luận độc hại",
23
+ description="Đây là ứng dụng demo cho mô hình NhanSoHocCode/vi-toxic-comment. Hãy nhập một bình luận để kiểm tra."
24
+ )
25
+
26
+ # Chạy ứng dụng
27
+ iface.launch()