Spaces:
Sleeping
Sleeping
Update ui.py
Browse files
ui.py
CHANGED
@@ -39,7 +39,7 @@ def create_ui():
|
|
39 |
model_selector = gr.Dropdown(choices=list(MODEL_OPTIONS.keys()), value="🌎 多語言推特情緒分析 (XLM-RoBERTa)", label="選擇 AI 模型")
|
40 |
|
41 |
analyze_button = gr.Button("分析情緒")
|
42 |
-
progress_bar = gr.Textbox(visible=False, label="模型載入進度")
|
43 |
|
44 |
result_output = gr.Markdown(label="分析結果")
|
45 |
|
@@ -47,16 +47,23 @@ def create_ui():
|
|
47 |
def process_analysis(text, model_name):
|
48 |
model_id = MODEL_OPTIONS[model_name]
|
49 |
|
50 |
-
#
|
51 |
if model_id != analyze_sentiment.CURRENT_MODEL:
|
52 |
progress_bar.update("🔄 AI 模型載入中,請稍後...", visible=True)
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
57 |
return result
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
gr.Markdown(developer_info)
|
62 |
|
|
|
39 |
model_selector = gr.Dropdown(choices=list(MODEL_OPTIONS.keys()), value="🌎 多語言推特情緒分析 (XLM-RoBERTa)", label="選擇 AI 模型")
|
40 |
|
41 |
analyze_button = gr.Button("分析情緒")
|
42 |
+
progress_bar = gr.Textbox(value="", visible=False, label="模型載入進度")
|
43 |
|
44 |
result_output = gr.Markdown(label="分析結果")
|
45 |
|
|
|
47 |
def process_analysis(text, model_name):
|
48 |
model_id = MODEL_OPTIONS[model_name]
|
49 |
|
50 |
+
# **當使用者切換模型時,顯示進度條**
|
51 |
if model_id != analyze_sentiment.CURRENT_MODEL:
|
52 |
progress_bar.update("🔄 AI 模型載入中,請稍後...", visible=True)
|
53 |
+
|
54 |
+
# 📌 調用 API 進行分析
|
55 |
+
result, _ = analyze_sentiment(text, model_id)
|
56 |
+
|
57 |
+
# **確保進度條消失**
|
58 |
+
progress_bar.update("", visible=False)
|
59 |
return result
|
60 |
|
61 |
+
# 📌 **修正 Gradio 事件綁定,確保所有輸入 & 輸出正確**
|
62 |
+
analyze_button.click(
|
63 |
+
fn=process_analysis,
|
64 |
+
inputs=[text_input, model_selector],
|
65 |
+
outputs=[result_output, progress_bar]
|
66 |
+
)
|
67 |
|
68 |
gr.Markdown(developer_info)
|
69 |
|