File size: 731 Bytes
869c384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr

def welcome(name,btn):
    # 在回复消息中嵌入 JavaScript 代码
    js_code = "<script>alert('Button clicked!');</script>"
    response = f"Hello! Click the button below:<br><button onclick=\"{js_code}\">Click Me</button>"

    return "response"


with gr.Blocks() as demo:
    gr.Markdown(
    """
    # Hello World!
    Start typing below to see the output.
    """)
    inp = gr.Textbox(placeholder="What is your name?")
    out = gr.Textbox()
    btn = gr.Button("1")
    def changeIcon(btnw):
        # btnw.icon = "didi.jpeg"
        return "tt",gr.update(value="", interactive=True)
    inp.change(welcome, [inp,btn], btn).then(changeIcon,btn,btn)

if __name__ == "__main__":
    demo.launch()