|
import gradio as gr |
|
|
|
import gradio as gr |
|
import random |
|
import time |
|
|
|
def generate_button_html(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button_html = f""" |
|
<script> alert("Button clicked!") </script> |
|
""" |
|
button_html = button_html.replace("\n","<br>") |
|
print(button_html) |
|
return button_html |
|
|
|
with gr.Blocks() as demo: |
|
chatbot = gr.Chatbot() |
|
btn = gr.Button(value="Submit") |
|
btn.visible = False |
|
msg = gr.Textbox() |
|
clear = gr.ClearButton([msg, chatbot]) |
|
|
|
def respond(message, chat_history): |
|
|
|
bot_message = f"Hello! Click the button below:<br>{generate_button_html()}" |
|
chat_history.append((message, bot_message)) |
|
time.sleep(2) |
|
|
|
btn.visible = True |
|
gr.update(value="", interactive=True) |
|
return "", chat_history,btn |
|
|
|
msg.submit(respond, [msg, chatbot], [msg, chatbot]) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|