sent2547 commited on
Commit
fcf292f
·
verified ·
1 Parent(s): 9e66cf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -1,22 +1,27 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- model_name = "ZombitX64/Thai-sentiment-e5" # เปลี่ยนเป็นชื่อโมเดลของคุณ
5
  nlp = pipeline("sentiment-analysis", model=model_name)
6
 
7
- # สร้าง dict แม็ป label เป็นเลข
8
  label_map = {
9
- "negative": 0,
10
- "neutral": 1,
11
- "positive": 2
 
 
 
 
 
12
  }
13
 
14
  def analyze_text(text):
15
  result = nlp(text)[0]
16
- label = result['label'].lower() # แปลงเป็น lowercase เผื่อโมเดลให้แบบนี้
17
  score = result['score']
18
- code = label_map.get(label, -1) # ถ้า label ไม่อยู่ใน dict ให้เป็น -1
19
- return f"ผลวิเคราะห์: {label} (รหัส: {code}) ความมั่นใจ {score:.2f}"
 
20
 
21
  demo = gr.Interface(
22
  fn=analyze_text,
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ model_name = "ZombitX64/Thai-sentiment-e5"
5
  nlp = pipeline("sentiment-analysis", model=model_name)
6
 
 
7
  label_map = {
8
+ "LABEL_0": 0,
9
+ "LABEL_1": 1,
10
+ "LABEL_2": 2
11
+ }
12
+ label_name_map = {
13
+ "LABEL_0": "negative",
14
+ "LABEL_1": "neutral",
15
+ "LABEL_2": "positive"
16
  }
17
 
18
  def analyze_text(text):
19
  result = nlp(text)[0]
20
+ label = result['label']
21
  score = result['score']
22
+ code = label_map.get(label, -1)
23
+ label_name = label_name_map.get(label, label)
24
+ return f"ผลวิเคราะห์: {label_name} (รหัส: {code}) ความมั่นใจ {score:.2f}"
25
 
26
  demo = gr.Interface(
27
  fn=analyze_text,