Spaces:
Running
Running
Update ui.py
Browse files
ui.py
CHANGED
@@ -30,13 +30,15 @@ def create_ui():
|
|
30 |
|
31 |
text_input = gr.Textbox(lines=3, placeholder="請輸入文本...", label="輸入文本", max_lines=5)
|
32 |
|
33 |
-
model_selector = gr.Dropdown(
|
|
|
|
|
|
|
|
|
34 |
|
35 |
analyze_button = gr.Button("分析情緒")
|
36 |
clear_button = gr.Button("清除")
|
37 |
-
|
38 |
-
|
39 |
-
result_output = gr.Markdown(label="分析結果")
|
40 |
|
41 |
# 📌 綁定按鈕功能
|
42 |
def process_analysis(text, model_name):
|
@@ -44,9 +46,9 @@ def create_ui():
|
|
44 |
print(f"📢 [Debug] 模型: {model_name}")
|
45 |
print(f"📢 [Debug] 輸入文本: {text}")
|
46 |
|
47 |
-
|
48 |
result, _ = analyze_sentiment(text, model_name)
|
49 |
-
|
50 |
|
51 |
print(f"📢 [Debug] 回傳結果: {result}")
|
52 |
return result
|
@@ -54,13 +56,13 @@ def create_ui():
|
|
54 |
analyze_button.click(
|
55 |
fn=process_analysis,
|
56 |
inputs=[text_input, model_selector],
|
57 |
-
outputs=[
|
58 |
)
|
59 |
|
60 |
clear_button.click(
|
61 |
-
lambda:
|
62 |
-
inputs=[],
|
63 |
-
outputs=[
|
64 |
)
|
65 |
|
66 |
gr.Markdown(developer_info)
|
|
|
30 |
|
31 |
text_input = gr.Textbox(lines=3, placeholder="請輸入文本...", label="輸入文本", max_lines=5)
|
32 |
|
33 |
+
model_selector = gr.Dropdown(
|
34 |
+
choices=list(MODEL_OPTIONS.keys()),
|
35 |
+
value="🌎 多語言推特情緒分析 (XLM-RoBERTa)",
|
36 |
+
label="選擇 AI 模型"
|
37 |
+
)
|
38 |
|
39 |
analyze_button = gr.Button("分析情緒")
|
40 |
clear_button = gr.Button("清除")
|
41 |
+
result_display = gr.Textbox(value="等待輸入...", label="AI 回應", interactive=False) # 🚀 這裡讓它成為輸出區
|
|
|
|
|
42 |
|
43 |
# 📌 綁定按鈕功能
|
44 |
def process_analysis(text, model_name):
|
|
|
46 |
print(f"📢 [Debug] 模型: {model_name}")
|
47 |
print(f"📢 [Debug] 輸入文本: {text}")
|
48 |
|
49 |
+
result_display.value = "🔄 AI 正在分析,請稍後..." # 🚀 先顯示「分析中」
|
50 |
result, _ = analyze_sentiment(text, model_name)
|
51 |
+
result_display.value = result # 🚀 讓 `result_display` 直接顯示 AI 結果
|
52 |
|
53 |
print(f"📢 [Debug] 回傳結果: {result}")
|
54 |
return result
|
|
|
56 |
analyze_button.click(
|
57 |
fn=process_analysis,
|
58 |
inputs=[text_input, model_selector],
|
59 |
+
outputs=[result_display] # 🚀 讓 `result_display` 直接顯示結果
|
60 |
)
|
61 |
|
62 |
clear_button.click(
|
63 |
+
lambda: "等待輸入...", # 🚀 讓狀態列回到初始值
|
64 |
+
inputs=[],
|
65 |
+
outputs=[result_display]
|
66 |
)
|
67 |
|
68 |
gr.Markdown(developer_info)
|