dayuian commited on
Commit
a7b0235
·
verified ·
1 Parent(s): c9e6f14

Update ui.py

Browse files
Files changed (1) hide show
  1. ui.py +4 -16
ui.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- import matplotlib.pyplot as plt
3
  from sentiment import analyze_sentiment
4
 
5
  # 📌 可選擇的模型
@@ -9,15 +8,6 @@ MODEL_OPTIONS = {
9
  "🇬🇧 英語情緒分析 (DistilBERT)": "distilbert-base-uncased-finetuned-sst-2-english"
10
  }
11
 
12
- # 📌 生成信心度條狀圖
13
- def plot_confidence(score):
14
- fig, ax = plt.subplots(figsize=(4, 1))
15
- ax.barh(["信心度"], [score], color="blue")
16
- ax.set_xlim([0, 1])
17
- ax.set_xticks([0, 0.25, 0.5, 0.75, 1])
18
- ax.set_xlabel("信心度(百分比)")
19
- return fig
20
-
21
  # 📌 Gradio 介面說明
22
  intro_text = """
23
  # 🎯 多語言情緒分析 AI
@@ -52,7 +42,6 @@ def create_ui():
52
  progress_bar = gr.Textbox(visible=False, label="模型載入進度")
53
 
54
  result_output = gr.Markdown(label="分析結果")
55
- plot_output = gr.Plot(label="信心度")
56
 
57
  # 📌 綁定按鈕功能
58
  def process_analysis(text, model_name):
@@ -62,13 +51,12 @@ def create_ui():
62
  if model_id != analyze_sentiment.CURRENT_MODEL:
63
  progress_bar.update("🔄 AI 模型載入中,請稍後...", visible=True)
64
 
65
- result, confidence_score = analyze_sentiment(text, model_id)
66
-
67
- plot = plot_confidence(confidence_score)
68
  progress_bar.update("", visible=False) # 隱藏進度條
69
- return result, plot
70
 
71
- analyze_button.click(process_analysis, inputs=[text_input, model_selector], outputs=[result_output, plot_output, progress_bar])
72
 
73
  gr.Markdown(developer_info)
74
 
 
1
  import gradio as gr
 
2
  from sentiment import analyze_sentiment
3
 
4
  # 📌 可選擇的模型
 
8
  "🇬🇧 英語情緒分析 (DistilBERT)": "distilbert-base-uncased-finetuned-sst-2-english"
9
  }
10
 
 
 
 
 
 
 
 
 
 
11
  # 📌 Gradio 介面說明
12
  intro_text = """
13
  # 🎯 多語言情緒分析 AI
 
42
  progress_bar = gr.Textbox(visible=False, label="模型載入進度")
43
 
44
  result_output = gr.Markdown(label="分析結果")
 
45
 
46
  # 📌 綁定按鈕功能
47
  def process_analysis(text, model_name):
 
51
  if model_id != analyze_sentiment.CURRENT_MODEL:
52
  progress_bar.update("🔄 AI 模型載入中,請稍後...", visible=True)
53
 
54
+ result, _ = analyze_sentiment(text, model_id) # 只返回文字結果
55
+
 
56
  progress_bar.update("", visible=False) # 隱藏進度條
57
+ return result
58
 
59
+ analyze_button.click(process_analysis, inputs=[text_input, model_selector], outputs=[result_output, progress_bar])
60
 
61
  gr.Markdown(developer_info)
62