dayuian commited on
Commit
a3452de
·
verified ·
1 Parent(s): 759966c

Update sentiment.py

Browse files
Files changed (1) hide show
  1. sentiment.py +4 -3
sentiment.py CHANGED
@@ -1,5 +1,5 @@
1
  import requests
2
- from config import API_URL, HEADERS
3
 
4
  # 轉換英文分類為中文
5
  def translate_sentiment(label):
@@ -10,7 +10,7 @@ def translate_sentiment(label):
10
  else:
11
  return "😡 **負向**"
12
 
13
- # 轉換信心度為更直觀的等級(加上百分比)
14
  def convert_confidence(score):
15
  percentage = round(score * 100)
16
  if score >= 0.90:
@@ -25,8 +25,9 @@ def convert_confidence(score):
25
  return f"❌ **極低信心(建議忽略)** ({percentage}%)"
26
 
27
  # 調用 Hugging Face API 進行情緒分析
28
- def analyze_sentiment(text):
29
  try:
 
30
  response = requests.post(API_URL, headers=HEADERS, json={"inputs": text})
31
  result = response.json()
32
 
 
1
  import requests
2
+ from config import HEADERS
3
 
4
  # 轉換英文分類為中文
5
  def translate_sentiment(label):
 
10
  else:
11
  return "😡 **負向**"
12
 
13
+ # 轉換信心度為更直觀的等級
14
  def convert_confidence(score):
15
  percentage = round(score * 100)
16
  if score >= 0.90:
 
25
  return f"❌ **極低信心(建議忽略)** ({percentage}%)"
26
 
27
  # 調用 Hugging Face API 進行情緒分析
28
+ def analyze_sentiment(text, model_id):
29
  try:
30
+ API_URL = f"https://api-inference.huggingface.co/models/{model_id}"
31
  response = requests.post(API_URL, headers=HEADERS, json={"inputs": text})
32
  result = response.json()
33