Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,7 +68,7 @@ def toggle_ai_button(use_ai):
|
|
| 68 |
return gr.update(visible=use_ai), gr.update(visible=use_ai)
|
| 69 |
|
| 70 |
# ================================
|
| 71 |
-
# 介面配置
|
| 72 |
# ================================
|
| 73 |
with gr.Blocks(css="""
|
| 74 |
#card-group { padding: 15px; border-radius: 12px; background-color: rgba(255, 255, 255, 0.05); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); margin-bottom: 15px; }
|
|
@@ -76,51 +76,55 @@ with gr.Blocks(css="""
|
|
| 76 |
""") as demo:
|
| 77 |
gr.Markdown(project_description())
|
| 78 |
|
| 79 |
-
with gr.
|
| 80 |
-
with gr.
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
# 啟動
|
| 126 |
-
demo.launch()
|
|
|
|
| 68 |
return gr.update(visible=use_ai), gr.update(visible=use_ai)
|
| 69 |
|
| 70 |
# ================================
|
| 71 |
+
# 介面配置 - 分頁版本
|
| 72 |
# ================================
|
| 73 |
with gr.Blocks(css="""
|
| 74 |
#card-group { padding: 15px; border-radius: 12px; background-color: rgba(255, 255, 255, 0.05); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); margin-bottom: 15px; }
|
|
|
|
| 76 |
""") as demo:
|
| 77 |
gr.Markdown(project_description())
|
| 78 |
|
| 79 |
+
with gr.Tabs():
|
| 80 |
+
with gr.Tab("單字例句工具"):
|
| 81 |
+
with gr.Group():
|
| 82 |
+
with gr.Row():
|
| 83 |
+
mode_radio = gr.Radio(
|
| 84 |
+
["查詢單字", "隨機抽單字"],
|
| 85 |
+
label="選擇模式",
|
| 86 |
+
value="查詢單字",
|
| 87 |
+
interactive=True
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
with gr.Group(elem_id="card-group"):
|
| 91 |
+
word_input = gr.Textbox(label="輸入單字", visible=True)
|
| 92 |
+
num_input = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="抽取單字數量")
|
| 93 |
+
source_dropdown = gr.Dropdown(
|
| 94 |
+
choices=get_sources(),
|
| 95 |
+
value="common3000",
|
| 96 |
+
label="選擇單字庫"
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
with gr.Group(elem_id="card-group"):
|
| 100 |
+
use_ai_checkbox = gr.Checkbox(label="使用 AI 生成句子(較慢,約 30 秒)", elem_id="use-ai-checkbox")
|
| 101 |
+
|
| 102 |
+
with gr.Row():
|
| 103 |
+
model_dropdown = gr.Dropdown(
|
| 104 |
+
choices=MODEL_LIST,
|
| 105 |
+
value="gpt2",
|
| 106 |
+
label="選擇 AI 模型",
|
| 107 |
+
visible=False
|
| 108 |
+
)
|
| 109 |
+
ai_warning = gr.Textbox(
|
| 110 |
+
value="⚠️ 使用 AI 生成句子為功能測試,每一個單字的生成過程可能需要 30 秒以上,請耐心等待。",
|
| 111 |
+
visible=False,
|
| 112 |
+
interactive=False,
|
| 113 |
+
label=""
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
result_output = gr.HTML(label="結果")
|
| 117 |
+
status_output = gr.Textbox(label="處理狀態", interactive=False)
|
| 118 |
+
|
| 119 |
+
with gr.Row():
|
| 120 |
+
generate_button = gr.Button("✨ 生成句子", elem_id="generate-button")
|
| 121 |
+
|
| 122 |
+
mode_radio.change(switch_mode, inputs=[mode_radio], outputs=[word_input, num_input])
|
| 123 |
+
use_ai_checkbox.change(toggle_ai_button, inputs=[use_ai_checkbox], outputs=[model_dropdown, ai_warning])
|
| 124 |
+
generate_button.click(process_sentence, inputs=[mode_radio, word_input, source_dropdown, num_input, use_ai_checkbox, model_dropdown], outputs=[result_output, status_output])
|
| 125 |
+
|
| 126 |
+
with gr.Tab("英文小考"):
|
| 127 |
+
gr.HTML("<p>這裡未來可放 quiz 小考頁面的內容或跳轉說明</p>")
|
| 128 |
|
| 129 |
# 啟動
|
| 130 |
+
demo.launch()
|