youngtsai commited on
Commit
83627a0
·
1 Parent(s): 2a3dc52

generate_topics_button.click(

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -45,10 +45,12 @@ def generate_topics(model, max_tokens, sys_content, scenario, eng_level, user_ge
45
  topics = json.loads(content)["topics"]
46
  topics_text = json.dumps(topics)
47
 
48
- return topics_text
 
 
49
 
50
  def update_topic_input(topic):
51
- return topic, gr.update(elem_classes=["btn-max-length", "btn-highlight"])
52
 
53
  def generate_points(model, max_tokens, sys_content, scenario, eng_level, topic, user_generate_points_prompt):
54
  """
@@ -335,17 +337,18 @@ with gr.Blocks(css=CSS) as demo:
335
 
336
  with gr.Column():
337
  generate_topics_button = gr.Button("AI Generate Topic Sentences")
338
- topic_output = gr.Textbox(label="AI Generated Topic 主題", visible=False, value=[])
339
 
340
  @gr.render(inputs=topic_output)
341
  def render_topics(topics):
342
- buttons = []
343
  topics_list = json.loads(topics)
344
- for i, topic in enumerate(topics_list):
345
- btn = gr.Button(topic, elem_id=f"topic_button_{i}", elem_classes=["btn-max-length"])
346
- btn.click(fn=update_topic_input, inputs=gr.Textbox(value=topic, visible=False), outputs=[topic_input, btn])
347
- buttons.append(btn)
348
- return buttons
 
 
349
 
350
  gr.Markdown("## 3. Generate Points 要點")
351
  default_generate_points_prompt = """
@@ -535,7 +538,7 @@ with gr.Blocks(css=CSS) as demo:
535
  eng_level_input,
536
  user_generate_topics_prompt
537
  ],
538
- outputs=topic_output
539
  )
540
 
541
  generate_points_button.click(
 
45
  topics = json.loads(content)["topics"]
46
  topics_text = json.dumps(topics)
47
 
48
+ is_visible = gr.update(visible=False)
49
+
50
+ return topics_text, is_visible
51
 
52
  def update_topic_input(topic):
53
+ return topic
54
 
55
  def generate_points(model, max_tokens, sys_content, scenario, eng_level, topic, user_generate_points_prompt):
56
  """
 
337
 
338
  with gr.Column():
339
  generate_topics_button = gr.Button("AI Generate Topic Sentences")
340
+ topic_output = gr.Textbox(label="AI Generated Topic 主題", visible=True, value=[])
341
 
342
  @gr.render(inputs=topic_output)
343
  def render_topics(topics):
 
344
  topics_list = json.loads(topics)
345
+ topic_radio = gr.Radio(topics_list, label="Topics", elem_id="topic_button")
346
+ topic_radio.select(
347
+ fn=update_topic_input,
348
+ inputs=[topic_radio],
349
+ outputs=[topic_input]
350
+ )
351
+ return topic_radio
352
 
353
  gr.Markdown("## 3. Generate Points 要點")
354
  default_generate_points_prompt = """
 
538
  eng_level_input,
539
  user_generate_topics_prompt
540
  ],
541
+ outputs=[topic_output, topic_output]
542
  )
543
 
544
  generate_points_button.click(