tilents
user complete1
869c384
import gradio as gr
import gradio as gr
import random
import time
# ๅŠจๆ€็”Ÿๆˆ HTML ๅ’Œ JavaScript ไปฃ็ 
def generate_button_html():
# button_html = f"""
# <script> function show() {{
# // ๅœจ่ฟ™้‡Œๆ‰ง่กŒ JavaScript ไปฃ็ 
# alert("Button clicked!");
# // ้š่—ๆŒ‰้’ฎ
# var button = document.getElementById('my-button2');
# button.style.display = 'none';
# }}
# </script>
# <button id="my-button" onclick="show();">Click Me</button>
# <button id="my-button2" onclick="show();">Click Me2</button>
# """
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 = random.choice(["How are you?", "I love you", "I'm very hungry"])
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()