tonyhui2234 commited on
Commit
6b34957
·
verified ·
1 Parent(s): 7e28e69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -21
app.py CHANGED
@@ -2,45 +2,55 @@ 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()
 
2
  import time
3
 
4
  def update_fortune(user_input):
5
+ # Simulate processing and an "animation"
 
6
  for _ in range(3):
7
  time.sleep(0.5)
8
+ # Update the fortune image and reserved text field
9
+ new_image = "fortune2.png" # New fortune image after submission.
10
+ reserved_text = f"Processed input: {user_input}" # Placeholder reserved text.
11
+ # Make the bottom left enquiry components visible.
12
+ show_bottom = gr.update(visible=True)
13
+ return new_image, reserved_text, show_bottom, show_bottom
14
 
15
  def enquiry_action():
16
+ # This function is triggered by the bottom left enquiry 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 left and bottom left)
24
  with gr.Column(scale=1):
25
+ # Top left container with subtitle and input field + submit button
26
+ with gr.Group():
27
+ gr.Markdown("**有什麼問題/Type your question**")
28
+ with gr.Row():
29
+ user_input = gr.Textbox(placeholder="Enter your sentence here...", show_label=False)
30
+ submit_btn = gr.Button("Submit")
31
 
32
+ # Bottom left container (initially hidden) with its subtitle and enquiry button
33
+ with gr.Group(visible=False) as bottom_left_group:
34
+ gr.Markdown("**解籤/Stick Enquiry**")
35
  enquiry_btn = gr.Button("解籤/Stick Enquiry")
36
  enquiry_output = gr.Textbox(label="Enquiry Output", placeholder="Output will appear here...")
37
 
38
+ # Right column: merged section for fortune image and reserved text
39
  with gr.Column(scale=2):
40
+ gr.Markdown("**籤文/fortune explanation**")
41
+ fortune_image = gr.Image(value="fortune.png", label=None, height=300)
42
  reserved_text = gr.Textbox(label="Reserved Text Field", placeholder="Reserved for future content...", interactive=False)
43
 
44
+ # When the submit button is clicked:
45
+ # - Update the fortune image and reserved text,
46
+ # - And reveal the bottom left enquiry section.
47
+ submit_btn.click(
48
+ fn=update_fortune,
49
+ inputs=user_input,
50
+ outputs=[fortune_image, reserved_text, enquiry_btn, enquiry_output]
51
+ )
52
+
53
+ # The enquiry button's click updates its output.
54
  enquiry_btn.click(fn=enquiry_action, inputs=[], outputs=enquiry_output)
55
 
56
  demo.launch()