sent2547 commited on
Commit
d4c8507
·
verified ·
1 Parent(s): ee0d002

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -1,12 +1,22 @@
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
  def analyze_text(text):
8
  result = nlp(text)[0]
9
- return f"ผลวิเคราะห์: {result['label']} (ความมั่นใจ {result['score']:.2f})"
 
 
 
10
 
11
  demo = gr.Interface(
12
  fn=analyze_text,
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ model_name = "username/your-model-name" # เปลี่ยนเป็นชื่อโมเดลของคุณ
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,