tmt3103 commited on
Commit
bca7ad9
·
1 Parent(s): ae2a2c7

update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -16,7 +16,7 @@ def predict_sentiment(text):
16
  encoding = tokenizer_sentiment(text, return_tensors='pt', truncation=True, padding=True, max_length=128)
17
  output = model_sentiment(**encoding)
18
  pred = torch.argmax(output.logits, dim=1).item()
19
- sentiment_labels = ["Tiêu cực", "Trung lập", "Tích cực"]
20
  return sentiment_labels[pred] # Trả về nhãn cảm xúc
21
 
22
  def predict_topic(text):
@@ -25,7 +25,7 @@ def predict_topic(text):
25
  encoding = tokenizer_topic(text, return_tensors='pt', truncation=True, padding=True, max_length=128)
26
  output = model_topic(**encoding)
27
  pred = torch.argmax(output.logits, dim=1).item()
28
- topic_labels = ["Giảng viên", "Chương trình đào tạo", "Cơ sở vật chất", "Khác"]
29
  return topic_labels[pred] # Trả về nhãn chủ đề
30
 
31
  # Define a function to handle both predictions at once
@@ -39,9 +39,8 @@ iface = gr.Interface(
39
  fn=classify_sentiment_and_topic,
40
  inputs=gr.Textbox(label="Nhập văn bản để phân loại", placeholder="Gõ văn bản của bạn ở đây..."),
41
  outputs=[gr.Textbox(label="Kết quả phân loại cảm xúc"), gr.Textbox(label="Kết quả phân loại chủ đề")],
42
- layout="vertical", # Thiết lập layout theo chiều dọc
43
  title="Phân loại cảm xúc và chủ đề",
44
- description="Phân loại cảm xúc (Tiêu cực, Trung lập, Tích cực) và chủ đề (Giảng viên, Chương trình đào tạo, Cơ sở vật chất, Khác) của văn bản."
45
  )
46
 
47
  # Launch the app
 
16
  encoding = tokenizer_sentiment(text, return_tensors='pt', truncation=True, padding=True, max_length=128)
17
  output = model_sentiment(**encoding)
18
  pred = torch.argmax(output.logits, dim=1).item()
19
+ sentiment_labels = ["Tiêu cực", "Trung lập", "Tích cực"] # Cập nhật nhãn theo yêu cầu
20
  return sentiment_labels[pred] # Trả về nhãn cảm xúc
21
 
22
  def predict_topic(text):
 
25
  encoding = tokenizer_topic(text, return_tensors='pt', truncation=True, padding=True, max_length=128)
26
  output = model_topic(**encoding)
27
  pred = torch.argmax(output.logits, dim=1).item()
28
+ topic_labels = ["Giảng viên", "Chương trình đào tạo", "Cơ sở vật chất", "Khác"] # Cập nhật nhãn theo yêu cầu
29
  return topic_labels[pred] # Trả về nhãn chủ đề
30
 
31
  # Define a function to handle both predictions at once
 
39
  fn=classify_sentiment_and_topic,
40
  inputs=gr.Textbox(label="Nhập văn bản để phân loại", placeholder="Gõ văn bản của bạn ở đây..."),
41
  outputs=[gr.Textbox(label="Kết quả phân loại cảm xúc"), gr.Textbox(label="Kết quả phân loại chủ đề")],
 
42
  title="Phân loại cảm xúc và chủ đề",
43
+ description="Phân loại cảm xúc (Tiêu cực, Trung lập, Tích cực) và chủ đề (Giảng viên, Chương trình đào tạo, Cơ sở vật chất, Khác) của văn bản.",
44
  )
45
 
46
  # Launch the app