Kevin Maik Jablonka commited on
Commit
86d103c
1 Parent(s): 7b4983c

move indices

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -21,6 +21,9 @@ def update_index(direction, current_index, output_text):
21
  if direction == 0:
22
  # Random number
23
  new_index = random.randint(0, len(data) - 1)
 
 
 
24
  else:
25
  new_index = current_index + direction
26
  # Ensure the new index is within bounds
@@ -37,7 +40,19 @@ with gr.Blocks() as demo:
37
  btn_random = gr.Button(value="Random index")
38
 
39
  # Initialize the state
40
- current_index = gr.State(1)
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  # Invisible Number components to pass direction
43
  direction_previous = gr.Number(-1, visible=False)
 
21
  if direction == 0:
22
  # Random number
23
  new_index = random.randint(0, len(data) - 1)
24
+ elif direction == 10:
25
+ # Next
26
+ new_index = current_index
27
  else:
28
  new_index = current_index + direction
29
  # Ensure the new index is within bounds
 
40
  btn_random = gr.Button(value="Random index")
41
 
42
  # Initialize the state
43
+ current_index = gr.Number(
44
+ 1,
45
+ label="Current Index",
46
+ visible=True,
47
+ )
48
+
49
+ direction_constant = gr.Number(10, visible=False)
50
+
51
+ current_index.change(
52
+ update_index,
53
+ inputs=[direction_constant, current_index, output_text],
54
+ outputs=[current_index, output_text],
55
+ )
56
 
57
  # Invisible Number components to pass direction
58
  direction_previous = gr.Number(-1, visible=False)