|
import gradio as gr |
|
import time |
|
|
|
def update_fortune(user_input): |
|
|
|
for _ in range(3): |
|
time.sleep(0.5) |
|
|
|
new_image = "fortune2.png" |
|
reserved_text = f"Processed input: {user_input}" |
|
|
|
show_bottom = gr.update(visible=True) |
|
return new_image, reserved_text, show_bottom, show_bottom |
|
|
|
def enquiry_action(): |
|
|
|
return "Here are some words after the enquiry." |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Wong Tai Sin Fortuen Stick Enquiry") |
|
|
|
with gr.Row(): |
|
|
|
with gr.Column(scale=1): |
|
|
|
with gr.Group(): |
|
gr.Markdown("**有什麼問題/Type your question**") |
|
with gr.Row(): |
|
user_input = gr.Textbox(placeholder="Enter your sentence here...", show_label=False) |
|
submit_btn = gr.Button("Submit") |
|
|
|
|
|
with gr.Group(visible=False) as bottom_left_group: |
|
gr.Markdown("**解籤/Stick Enquiry**") |
|
enquiry_btn = gr.Button("解籤/Stick Enquiry") |
|
enquiry_output = gr.Textbox(label="Enquiry Output", placeholder="Output will appear here...") |
|
|
|
|
|
with gr.Column(scale=2): |
|
gr.Markdown("**籤文/fortune explanation**") |
|
fortune_image = gr.Image(value="fortune.png", label=None, height=300) |
|
reserved_text = gr.Textbox(label="Reserved Text Field", placeholder="Reserved for future content...", interactive=False) |
|
|
|
|
|
|
|
|
|
submit_btn.click( |
|
fn=update_fortune, |
|
inputs=user_input, |
|
outputs=[fortune_image, reserved_text, enquiry_btn, enquiry_output] |
|
) |
|
|
|
|
|
enquiry_btn.click(fn=enquiry_action, inputs=[], outputs=enquiry_output) |
|
|
|
demo.launch() |
|
|