NhanSoHocCode commited on
Commit
0f4d8eb
·
verified ·
1 Parent(s): 6693e5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -7
app.py CHANGED
@@ -1,20 +1,14 @@
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..."),
@@ -23,5 +17,4 @@ iface = gr.Interface(
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, bật API Queue VÀ TẮT TÍNH NĂNG SSR BỊ LỖI
27
  iface.queue().launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  model_id = "NhanSoHocCode/vi-toxic-comment"
5
  classifier = pipeline("text-classification", model=model_id)
6
 
 
7
  def classify_text(text):
 
8
  predictions = classifier(text, top_k=None)
 
 
9
  formatted_result = {p['label']: round(p['score'], 4) for p in predictions}
10
  return formatted_result
11
 
 
12
  iface = gr.Interface(
13
  fn=classify_text,
14
  inputs=gr.Textbox(lines=5, placeholder="Nhập bình luận tiếng Việt vào đây..."),
 
17
  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."
18
  )
19
 
 
20
  iface.queue().launch()