Khunanya commited on
Commit
df19fbb
·
verified ·
1 Parent(s): 6306b41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -1,19 +1,23 @@
1
- from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
 
2
 
3
- # ใช้โมเดลภาษาไทยที่ถูก fine-tune sentiment แล้ว (ตัวอย่าง)
4
- model_name = "pangpond/best-wangchanberta-sentiment" # โมเดลนี้ถูกเทรนมาแล้ว
5
- clf = pipeline("text-classification", model=model_name, tokenizer=model_name)
6
 
7
  def classify_text(text):
8
  result = clf(text)[0]
9
  label = result['label']
10
  score = round(result['score'], 2)
11
 
12
- if label == "pos":
 
13
  label_name = "ความคิดเห็นเชิงบวก 😀"
14
- elif label == "neg":
15
- label_name = "ความคิดเห็นเชิงลบ 😞"
16
  else:
17
- label_name = "ความคิดเห็นเป็นกลาง 😐"
18
 
19
  return f"{label_name} (ความมั่นใจ: {score})"
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # โหลดโมเดลที่ฝึกแล้ว หรือโมเดล pretrained
5
+ clf = pipeline("text-classification", model="distilbert-base-uncased")
 
6
 
7
  def classify_text(text):
8
  result = clf(text)[0]
9
  label = result['label']
10
  score = round(result['score'], 2)
11
 
12
+ # เปลี่ยนชื่อ label ให้เข้าใจง่าย
13
+ if label == "LABEL_1":
14
  label_name = "ความคิดเห็นเชิงบวก 😀"
 
 
15
  else:
16
+ label_name = "ความคิดเห็นเชิงลบ 😞"
17
 
18
  return f"{label_name} (ความมั่นใจ: {score})"
19
+
20
+
21
+ demo = gr.Interface(fn=classify_text, inputs="text", outputs="text", title="Text Classifier")
22
+
23
+ demo.launch()