CurryMindFree commited on
Commit
66bbd50
·
verified ·
1 Parent(s): 47b8e11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -18
app.py CHANGED
@@ -1,33 +1,53 @@
1
  import gradio as gr
2
 
3
- def show_textbox():
4
- return gr.update(visible=True)
5
-
6
  def func1():
 
7
  return "one"
8
 
9
  def func2():
 
10
  return "two"
11
 
12
- def ui_test(ip):
13
- one=func1()
14
- show_textbox()
15
- if(user_input!=None&user_input=="y"):
 
 
 
 
 
 
 
 
16
  return one
17
- two = func2()
18
- return two
 
 
 
19
 
20
-
21
 
22
- demo = gr.Interface(
23
- fn=ui_test,
24
- inputs=gr.Textbox(),
25
- outputs="text",
26
- user_input = gr.Textbox(
27
- label="Your input",
28
  visible=False
29
  )
30
-
31
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  demo.launch()
 
1
  import gradio as gr
2
 
 
 
 
3
  def func1():
4
+ print("func1 runs")
5
  return "one"
6
 
7
  def func2():
8
+ print("func2 runs")
9
  return "two"
10
 
11
+ # First submission
12
+ def step1(_):
13
+ one = func1()
14
+ return (
15
+ one, # save result
16
+ gr.update(visible=True), # show second textbox
17
+ "Please enter y or n"
18
+ )
19
+
20
+ # Second submission
21
+ def step2(user_input, one):
22
+ if user_input.strip().lower() == "y":
23
  return one
24
+ return func2()
25
+
26
+ with gr.Blocks() as demo:
27
+
28
+ state = gr.State()
29
 
30
+ first_input = gr.Textbox(label="Enter anything")
31
 
32
+ second_input = gr.Textbox(
33
+ label="Enter y",
 
 
 
 
34
  visible=False
35
  )
36
+
37
+ output = gr.Textbox(label="Output")
38
+
39
+ # First Enter
40
+ first_input.submit(
41
+ step1,
42
+ inputs=first_input,
43
+ outputs=[state, second_input, output]
44
+ )
45
+
46
+ # Second Enter
47
+ second_input.submit(
48
+ step2,
49
+ inputs=[second_input, state],
50
+ outputs=output
51
+ )
52
 
53
  demo.launch()