dayuian commited on
Commit
b2dbf5f
·
verified ·
1 Parent(s): c76dc5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -65,14 +65,13 @@ with gr.Blocks(css="""
65
  interactive=True
66
  )
67
 
68
- with gr.Group(elem_id="card-group"):
69
- word_input = gr.Textbox(label="輸入單字", visible=True)
70
- num_input = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="抽取單字數量")
71
- source_dropdown = gr.Dropdown(
72
- choices=get_sources(),
73
- value="common3000",
74
- label="選擇單字庫"
75
- )
76
 
77
  with gr.Group(elem_id="card-group"):
78
  use_ai_checkbox = gr.Checkbox(label="使用 AI 生成句子(較慢,約 30 秒)", elem_id="use-ai-checkbox")
@@ -99,6 +98,21 @@ with gr.Blocks(css="""
99
  with gr.Row():
100
  generate_button = gr.Button("✨ 生成句子", elem_id="generate-button")
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  with gr.Tab("英文小考"):
103
  quiz_source_dropdown = gr.Dropdown(
104
  choices=get_sources(),
@@ -119,16 +133,7 @@ with gr.Blocks(css="""
119
  questions = generate_fill_in_blank_exam(source, num)
120
  quiz_questions_state.value = questions
121
 
122
- radios = []
123
- for i, q in enumerate(questions):
124
- radios.append(
125
- gr.Radio(
126
- choices=q['options'],
127
- label=f"第 {i + 1} 題:{q['sentence']}",
128
- interactive=True
129
- )
130
- )
131
-
132
  return radios
133
 
134
  def submit_exam(*user_answers):
@@ -148,5 +153,4 @@ with gr.Blocks(css="""
148
  outputs=quiz_score_display
149
  )
150
 
151
-
152
  demo.launch()
 
65
  interactive=True
66
  )
67
 
68
+ word_input = gr.Textbox(label="輸入單字", visible=True)
69
+ num_input = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="抽取單字數量", visible=False)
70
+ source_dropdown = gr.Dropdown(
71
+ choices=get_sources(),
72
+ value="common3000",
73
+ label="選擇單字庫"
74
+ )
 
75
 
76
  with gr.Group(elem_id="card-group"):
77
  use_ai_checkbox = gr.Checkbox(label="使用 AI 生成句子(較慢,約 30 秒)", elem_id="use-ai-checkbox")
 
98
  with gr.Row():
99
  generate_button = gr.Button("✨ 生成句子", elem_id="generate-button")
100
 
101
+ def switch_mode(mode):
102
+ return gr.update(visible=(mode == '查詢單字')), gr.update(visible=(mode == '隨機抽單字'))
103
+
104
+ mode_radio.change(
105
+ switch_mode,
106
+ inputs=[mode_radio],
107
+ outputs=[word_input, num_input]
108
+ )
109
+
110
+ generate_button.click(
111
+ process_sentence,
112
+ inputs=[mode_radio, word_input, source_dropdown, num_input, use_ai_checkbox, model_dropdown],
113
+ outputs=[result_output, status_output]
114
+ )
115
+
116
  with gr.Tab("英文小考"):
117
  quiz_source_dropdown = gr.Dropdown(
118
  choices=get_sources(),
 
133
  questions = generate_fill_in_blank_exam(source, num)
134
  quiz_questions_state.value = questions
135
 
136
+ radios = render_exam_interface(questions)
 
 
 
 
 
 
 
 
 
137
  return radios
138
 
139
  def submit_exam(*user_answers):
 
153
  outputs=quiz_score_display
154
  )
155
 
 
156
  demo.launch()