Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -99,46 +99,45 @@ with gr.Blocks(css="""
|
|
| 99 |
label=""
|
| 100 |
)
|
| 101 |
|
|
|
|
| 102 |
with gr.Row():
|
| 103 |
generate_button = gr.Button("✨ 生成句子", elem_id="generate-button")
|
| 104 |
gr.HTML("<a href='https://你的空白quiz網址' target='_blank'><button style='background-color:#ff5722;color:white;'>📝 生成小考</button></a>")
|
| 105 |
-
def generate_exam(word, model_name):
|
| 106 |
-
try:
|
| 107 |
-
question = generate_mcq(word, model_name)
|
| 108 |
-
return f"<p>{question}</p>"
|
| 109 |
-
except Exception as e:
|
| 110 |
-
return f"<p style='color:red;'>❌ 出題失敗:{str(e)}</p>"
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
|
|
|
| 114 |
|
|
|
|
| 115 |
def switch_mode(mode):
|
| 116 |
if mode == '查詢單字':
|
| 117 |
return gr.update(visible=True), gr.update(visible=False)
|
| 118 |
else:
|
| 119 |
return gr.update(visible=False), gr.update(visible=True)
|
| 120 |
|
| 121 |
-
|
| 122 |
-
switch_mode,
|
| 123 |
-
inputs=[mode_radio],
|
| 124 |
-
outputs=[word_input, num_input]
|
| 125 |
-
)
|
| 126 |
-
|
| 127 |
def toggle_ai_button(use_ai):
|
| 128 |
model_visibility = gr.update(visible=use_ai)
|
| 129 |
warning_visibility = gr.update(visible=use_ai)
|
| 130 |
return model_visibility, warning_visibility
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
use_ai_checkbox.change(
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
)
|
| 137 |
|
| 138 |
generate_button.click(
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
)
|
| 143 |
|
| 144 |
demo.launch()
|
|
|
|
| 99 |
label=""
|
| 100 |
)
|
| 101 |
|
| 102 |
+
# ---- 按鈕區塊 ----
|
| 103 |
with gr.Row():
|
| 104 |
generate_button = gr.Button("✨ 生成句子", elem_id="generate-button")
|
| 105 |
gr.HTML("<a href='https://你的空白quiz網址' target='_blank'><button style='background-color:#ff5722;color:white;'>📝 生成小考</button></a>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
+
# ---- 結果 & 狀態顯示 ----
|
| 108 |
+
result_output = gr.HTML(label="結果")
|
| 109 |
+
status_output = gr.Textbox(label="處理狀態", interactive=False)
|
| 110 |
|
| 111 |
+
# ---- 切換模式函數 ----
|
| 112 |
def switch_mode(mode):
|
| 113 |
if mode == '查詢單字':
|
| 114 |
return gr.update(visible=True), gr.update(visible=False)
|
| 115 |
else:
|
| 116 |
return gr.update(visible=False), gr.update(visible=True)
|
| 117 |
|
| 118 |
+
# ---- 切換 AI 按鈕函數 ----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
def toggle_ai_button(use_ai):
|
| 120 |
model_visibility = gr.update(visible=use_ai)
|
| 121 |
warning_visibility = gr.update(visible=use_ai)
|
| 122 |
return model_visibility, warning_visibility
|
| 123 |
|
| 124 |
+
# ---- 把這些事件綁定「獨立寫」出來,不要放在任何 Group 或 Row 裡 ----
|
| 125 |
+
mode_radio.change(
|
| 126 |
+
switch_mode,
|
| 127 |
+
inputs=[mode_radio],
|
| 128 |
+
outputs=[word_input, num_input]
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
use_ai_checkbox.change(
|
| 132 |
+
toggle_ai_button,
|
| 133 |
+
inputs=[use_ai_checkbox],
|
| 134 |
+
outputs=[model_dropdown, ai_warning]
|
| 135 |
)
|
| 136 |
|
| 137 |
generate_button.click(
|
| 138 |
+
process_sentence,
|
| 139 |
+
inputs=[mode_radio, word_input, source_dropdown, num_input, use_ai_checkbox, model_dropdown],
|
| 140 |
+
outputs=[result_output, status_output]
|
| 141 |
)
|
| 142 |
|
| 143 |
demo.launch()
|