area444 commited on
Commit
536987a
·
verified ·
1 Parent(s): 902417f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -1,16 +1,20 @@
1
  import gradio as gr
2
 
3
- # Function that controls the visibility of the panel
4
  def check_words(user_text, input_text):
5
  # If the entered text is "user" and "casa", show the second panel
6
  if user_text == 'user' and input_text == "casa":
7
- return gr.update(visible=True) # Show the second panel
8
  else:
9
- return gr.update(visible=False) # Keep the panel hidden
10
 
11
  # Function to hide the second panel when the button is pressed
12
  def hide_panel():
13
- return gr.update(visible=False) # Hide the second panel
 
 
 
 
14
 
15
  # Create the Gradio interface
16
  with gr.Blocks() as demo:
@@ -26,22 +30,23 @@ with gr.Blocks() as demo:
26
  # Create the first panel (visible from the start)
27
  with gr.Column() as panel_1:
28
  # Panel where the text is entered
29
- user_text, input_text
30
 
31
  # Create the second panel that is initially hidden
32
  with gr.Column(visible=False) as panel_2:
33
  # This panel will be shown if the condition is met
34
  gr.Textbox(value="Panel activado. Se escribieron 'user' y 'casa'.", label="Resultado")
35
- # Add a second button inside Panel 2 to hide the panel
36
  btn_2 = gr.Button("Ocultar el Panel", visible=True)
37
- btn_2.click(hide_panel, outputs=panel_2) # Hide the second panel when clicked
38
 
39
  # Configure the buttons and the panel visibility
40
- btn_1.click(check_words, inputs=[user_text, input_text], outputs=panel_2)
41
-
42
  # Launch the Gradio interface
43
  demo.launch()
44
 
45
 
46
 
47
 
 
 
1
  import gradio as gr
2
 
3
+ # Function that controls the visibility of the panels
4
  def check_words(user_text, input_text):
5
  # If the entered text is "user" and "casa", show the second panel
6
  if user_text == 'user' and input_text == "casa":
7
+ return gr.update(visible=True), gr.update(visible=False) # Show Panel 2 and hide Panel 1
8
  else:
9
+ return gr.update(visible=False), gr.update(visible=True) # Keep Panel 2 hidden and show Panel 1
10
 
11
  # Function to hide the second panel when the button is pressed
12
  def hide_panel():
13
+ return gr.update(visible=False) # Hide Panel 2
14
+
15
+ # Function to show the first panel when the second button is pressed
16
+ def show_panel_1():
17
+ return gr.update(visible=True) # Show Panel 1
18
 
19
  # Create the Gradio interface
20
  with gr.Blocks() as demo:
 
30
  # Create the first panel (visible from the start)
31
  with gr.Column() as panel_1:
32
  # Panel where the text is entered
33
+ user_text, input_text, btn_1 # Add btn_1 here
34
 
35
  # Create the second panel that is initially hidden
36
  with gr.Column(visible=False) as panel_2:
37
  # This panel will be shown if the condition is met
38
  gr.Textbox(value="Panel activado. Se escribieron 'user' y 'casa'.", label="Resultado")
39
+ # Add a second button inside Panel 2 to hide the panel and show Panel 1 again
40
  btn_2 = gr.Button("Ocultar el Panel", visible=True)
41
+ btn_2.click([hide_panel, show_panel_1], outputs=[panel_2, panel_1]) # Hide Panel 2 and show Panel 1
42
 
43
  # Configure the buttons and the panel visibility
44
+ btn_1.click(check_words, inputs=[user_text, input_text], outputs=[panel_2, panel_1]) # Hide Panel 1 and show Panel 2
45
+
46
  # Launch the Gradio interface
47
  demo.launch()
48
 
49
 
50
 
51
 
52
+