Manish Gupta commited on
Commit
c66c6a2
·
1 Parent(s): 9cc7eb2

Fixed the image selection.

Browse files
Files changed (1) hide show
  1. app.py +7 -14
app.py CHANGED
@@ -87,15 +87,9 @@ def save_image(
87
  print("Image saved successfully!")
88
 
89
 
90
- # Function to handle image selection and enable the save button
91
- def select_image(selected_image_index, images):
92
- # Get the selected image from its index
93
- selected_image = images[selected_image_index]
94
- return gr.update(interactive=True), selected_image
95
-
96
-
97
  with gr.Blocks() as demo:
98
- selected_image = gr.State(None)
 
99
  current_index = gr.State(0)
100
  character_data = gr.State([])
101
 
@@ -126,16 +120,15 @@ with gr.Blocks() as demo:
126
  )
127
 
128
  # When an image is clicked
129
- images.select(
130
- select_image,
131
- inputs=[gr.Number(), images],
132
- outputs=[save_button, selected_image],
133
- )
134
 
135
  save_button.click(
136
  save_image,
137
  inputs=[
138
- selected_image,
139
  comic_id,
140
  character_data,
141
  current_index,
 
87
  print("Image saved successfully!")
88
 
89
 
 
 
 
 
 
 
 
90
  with gr.Blocks() as demo:
91
+ # selected_image = gr.State(None)
92
+ selected_image_index = gr.State()
93
  current_index = gr.State(0)
94
  character_data = gr.State([])
95
 
 
120
  )
121
 
122
  # When an image is clicked
123
+ def get_select_index(evt: gr.SelectData):
124
+ return evt.index
125
+
126
+ images.select(get_select_index, None, selected_image_index)
 
127
 
128
  save_button.click(
129
  save_image,
130
  inputs=[
131
+ images[selected_image_index],
132
  comic_id,
133
  character_data,
134
  current_index,