|
import gradio as gr |
|
|
|
|
|
button_clicked = False |
|
|
|
|
|
def button_click(): |
|
global button_clicked |
|
button_clicked = True |
|
def dynamic_buttons(user_input): |
|
if user_input == "A": |
|
button_html = "<button onclick='button_click()'>点击我</button>" |
|
elif user_input == "B": |
|
button_html = "<button onclick='alert(\"按钮B被点击了!\")'>按钮B</button>" |
|
else: |
|
button_html = "<button onclick='alert(\"未知按钮被点击了!\")'>未知按钮</button>" |
|
return button_html |
|
|
|
iface = gr.Interface( |
|
fn=dynamic_buttons, |
|
inputs="text", |
|
outputs="html", |
|
live=False |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
iface.launch() |
|
|
|
|
|
while True: |
|
if button_clicked: |
|
|
|
|
|
print("按钮A被点击了!") |
|
button_clicked = False |
|
|