tonyhui2234 commited on
Commit
7e28e69
·
verified ·
1 Parent(s): 3ea0e23

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import time
3
+
4
+ def update_fortune(user_input):
5
+ # This function simulates processing the input and updating the fortune image.
6
+ # Simulate an "animation" by waiting a few moments.
7
+ for _ in range(3):
8
+ time.sleep(0.5)
9
+ # After the simulated animation, update the image and reserved text.
10
+ new_image = "fortune2.png" # The new image to display after submission.
11
+ reserved_text = f"Processed input: {user_input}" # Placeholder text; you can modify this later.
12
+ return new_image, reserved_text
13
+
14
+ def enquiry_action():
15
+ # This function is triggered when the '解籤/Stick Enquiry' button is clicked.
16
+ # It returns placeholder text that appears after the button.
17
+ return "Here are some words after the enquiry."
18
+
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown("# Wong Tai Sin Fortuen Stick Enquiry")
21
+
22
+ with gr.Row():
23
+ # Left column with two sections (top and bottom)
24
+ with gr.Column(scale=1):
25
+ # Top left: A row with the input field and submit button
26
+ with gr.Row():
27
+ user_input = gr.Textbox(label="Input Sentence", placeholder="Enter your sentence here...")
28
+ submit_btn = gr.Button("Submit")
29
+
30
+ # Bottom left: A button centered in the box and an output textbox
31
+ with gr.Column():
32
+ enquiry_btn = gr.Button("解籤/Stick Enquiry")
33
+ enquiry_output = gr.Textbox(label="Enquiry Output", placeholder="Output will appear here...")
34
+
35
+ # Right column: Merged area for the fortune image and a reserved text field
36
+ with gr.Column(scale=2):
37
+ fortune_image = gr.Image(value="fortune.png", label="Fortune Image", height=300)
38
+ reserved_text = gr.Textbox(label="Reserved Text Field", placeholder="Reserved for future content...", interactive=False)
39
+
40
+ # Define interactivity:
41
+ # When the submit button is clicked, update the fortune image and reserved text.
42
+ submit_btn.click(fn=update_fortune, inputs=user_input, outputs=[fortune_image, reserved_text])
43
+ # When the enquiry button is clicked, display the enquiry output.
44
+ enquiry_btn.click(fn=enquiry_action, inputs=[], outputs=enquiry_output)
45
+
46
+ demo.launch()