umang-immersfy commited on
Commit
be9cced
·
1 Parent(s): 0abb49c

Added character checkbox functionality

Browse files
Files changed (2) hide show
  1. app.py +33 -13
  2. core.py +45 -9
app.py CHANGED
@@ -16,6 +16,7 @@ with gr.Blocks() as demo:
16
  current_frame_data = gr.State(None)
17
  details = gr.State({})
18
  image_data_b64 = gr.State([])
 
19
 
20
  with gr.Row():
21
  with gr.Column():
@@ -86,7 +87,11 @@ with gr.Blocks() as demo:
86
  value="",
87
  label="Negative Prompt",
88
  )
89
- chars = gr.Textbox(value="[]", label="Related Characters")
 
 
 
 
90
  with gr.Row():
91
  height = gr.Textbox(value="1024", label="Image Height")
92
  width = gr.Textbox(value="1024", label="Image Width")
@@ -137,7 +142,13 @@ with gr.Blocks() as demo:
137
 
138
  load_images.click(
139
  core.load_from_dropdown,
140
- inputs=[episodes_data, current_episode, current_frame, developer],
 
 
 
 
 
 
141
  outputs=[
142
  episode_dropdown,
143
  frame_dropdown,
@@ -172,7 +183,13 @@ with gr.Blocks() as demo:
172
 
173
  next_button.click(
174
  core.load_data_next,
175
- inputs=[episodes_data, current_episode, current_frame, developer],
 
 
 
 
 
 
176
  outputs=[
177
  episode_dropdown,
178
  frame_dropdown,
@@ -201,7 +218,13 @@ with gr.Blocks() as demo:
201
 
202
  prev_button.click(
203
  core.load_data_prev,
204
- inputs=[episodes_data, current_episode, current_frame, developer],
 
 
 
 
 
 
205
  outputs=[
206
  episode_dropdown,
207
  frame_dropdown,
@@ -312,20 +335,17 @@ with gr.Blocks() as demo:
312
  visual_style,
313
  height,
314
  width,
315
- details
 
316
  ],
317
  outputs=[images, image_data_b64],
318
  )
319
 
320
  save_btn.click(
321
  core.save_images,
322
- inputs=[
323
- image_data_b64,
324
- current_episode,
325
- current_frame,
326
- comic_id,
327
- details
328
- ],
329
  )
330
- demo.launch(auth=("admin", "Qrt@12*34#immersfy"), share=True, ssr_mode=False, debug=True)
 
 
331
  # demo.launch(share=True, ssr_mode=False, debug=True)
 
16
  current_frame_data = gr.State(None)
17
  details = gr.State({})
18
  image_data_b64 = gr.State([])
19
+ choice = gr.State([])
20
 
21
  with gr.Row():
22
  with gr.Column():
 
87
  value="",
88
  label="Negative Prompt",
89
  )
90
+ # chars = gr.Textbox(value="[]", label="Related Characters")
91
+ chars = gr.CheckboxGroup(
92
+ choices=[], value=[], label="Related Characters", interactive=True
93
+ )
94
+
95
  with gr.Row():
96
  height = gr.Textbox(value="1024", label="Image Height")
97
  width = gr.Textbox(value="1024", label="Image Width")
 
142
 
143
  load_images.click(
144
  core.load_from_dropdown,
145
+ inputs=[
146
+ episodes_data,
147
+ current_episode,
148
+ current_frame,
149
+ developer,
150
+ character_data,
151
+ ],
152
  outputs=[
153
  episode_dropdown,
154
  frame_dropdown,
 
183
 
184
  next_button.click(
185
  core.load_data_next,
186
+ inputs=[
187
+ episodes_data,
188
+ current_episode,
189
+ current_frame,
190
+ developer,
191
+ character_data,
192
+ ],
193
  outputs=[
194
  episode_dropdown,
195
  frame_dropdown,
 
218
 
219
  prev_button.click(
220
  core.load_data_prev,
221
+ inputs=[
222
+ episodes_data,
223
+ current_episode,
224
+ current_frame,
225
+ developer,
226
+ character_data,
227
+ ],
228
  outputs=[
229
  episode_dropdown,
230
  frame_dropdown,
 
335
  visual_style,
336
  height,
337
  width,
338
+ details,
339
+ chars,
340
  ],
341
  outputs=[images, image_data_b64],
342
  )
343
 
344
  save_btn.click(
345
  core.save_images,
346
+ inputs=[image_data_b64, current_episode, current_frame, comic_id, details],
 
 
 
 
 
 
347
  )
348
+ demo.launch(
349
+ auth=("admin", "Qrt@12*34#immersfy"), share=True, ssr_mode=False, debug=True
350
+ )
351
  # demo.launch(share=True, ssr_mode=False, debug=True)
core.py CHANGED
@@ -39,6 +39,12 @@ class ComicFrame:
39
  compositions: List[Composition] = dataclasses.field(default_factory=list)
40
 
41
 
 
 
 
 
 
 
42
  def list_current_dir(bucket_name: str, folder_path: str = "") -> list:
43
  try:
44
  response = aws_utils.S3_CLIENT.list_objects_v2(
@@ -54,7 +60,11 @@ def list_current_dir(bucket_name: str, folder_path: str = "") -> list:
54
 
55
 
56
  def load_data_inner(
57
- episodes_data: list, current_episode: int, current_frame: int, is_developer: bool
 
 
 
 
58
  ):
59
  try:
60
  images = []
@@ -81,7 +91,7 @@ def load_data_inner(
81
  curr_frame.compositions[2].seed,
82
  curr_frame.compositions[3].prompt,
83
  curr_frame.compositions[3].seed,
84
- curr_frame.all_characters,
85
  )
86
  except Exception as e:
87
  return (
@@ -179,7 +189,11 @@ def load_metadata_fn(comic_id: str):
179
 
180
 
181
  def load_data_next(
182
- episodes_data: list, current_episode: int, current_frame: int, is_developer: bool
 
 
 
 
183
  ):
184
  if current_frame + 1 < len(episodes_data[current_episode]):
185
  current_frame += 1
@@ -191,12 +205,18 @@ def load_data_next(
191
  return (
192
  gr.update(value=current_episode),
193
  gr.update(value=current_frame),
194
- *load_data_inner(episodes_data, current_episode, current_frame, is_developer),
 
 
195
  )
196
 
197
 
198
  def load_data_prev(
199
- episodes_data: list, current_episode: int, current_frame: int, is_developer: bool
 
 
 
 
200
  ):
201
  if current_frame - 1 >= 0:
202
  current_frame -= 1
@@ -208,17 +228,30 @@ def load_data_prev(
208
  return (
209
  gr.update(value=current_episode),
210
  gr.update(value=current_frame),
211
- *load_data_inner(episodes_data, current_episode, current_frame, is_developer),
 
 
212
  )
213
 
214
 
215
  def load_from_dropdown(
216
- episodes_data: dict, selected_episode: int, selected_frame: int, is_developer: bool
 
 
 
 
217
  ):
218
  return (
219
  gr.update(value=selected_episode),
220
  gr.update(value=selected_frame),
221
- *load_data_inner(episodes_data, selected_episode, selected_frame, is_developer),
 
 
 
 
 
 
 
222
  )
223
 
224
 
@@ -375,9 +408,11 @@ def regenerate_data(
375
  height,
376
  width,
377
  details,
 
378
  ):
379
  images = []
380
  image_data_b64 = []
 
381
  try:
382
  current_scene, frame_num_in_scene = get_scene_number(
383
  details, current_episode, current_frame
@@ -386,7 +421,7 @@ def regenerate_data(
386
  f"Regenerating data for episode {current_episode}, Scene: {current_scene}, frame {frame_num_in_scene}"
387
  )
388
  frame = episodes_data[current_episode][current_frame]
389
- related_chars = [character_data[ch] for ch in frame.all_characters]
390
 
391
  for i, composition in enumerate(frame.compositions):
392
  try:
@@ -525,5 +560,6 @@ def save_images(image_data_b64, current_episode, current_frame, comic_id, detail
525
  print(f"Error saving image {i} to S3: {e}")
526
  continue
527
  print("All images saved successfully!")
 
528
  except Exception as e:
529
  print(f"Error in save_images: {e}")
 
39
  compositions: List[Composition] = dataclasses.field(default_factory=list)
40
 
41
 
42
+ def update_characters(character_data, curr_frame):
43
+ return gr.CheckboxGroup(
44
+ choices=list(character_data.keys()), value=curr_frame.all_characters
45
+ )
46
+
47
+
48
  def list_current_dir(bucket_name: str, folder_path: str = "") -> list:
49
  try:
50
  response = aws_utils.S3_CLIENT.list_objects_v2(
 
60
 
61
 
62
  def load_data_inner(
63
+ episodes_data: list,
64
+ current_episode: int,
65
+ current_frame: int,
66
+ is_developer: bool,
67
+ character_data,
68
  ):
69
  try:
70
  images = []
 
91
  curr_frame.compositions[2].seed,
92
  curr_frame.compositions[3].prompt,
93
  curr_frame.compositions[3].seed,
94
+ update_characters(character_data, curr_frame),
95
  )
96
  except Exception as e:
97
  return (
 
189
 
190
 
191
  def load_data_next(
192
+ episodes_data: list,
193
+ current_episode: int,
194
+ current_frame: int,
195
+ is_developer: bool,
196
+ character_data,
197
  ):
198
  if current_frame + 1 < len(episodes_data[current_episode]):
199
  current_frame += 1
 
205
  return (
206
  gr.update(value=current_episode),
207
  gr.update(value=current_frame),
208
+ *load_data_inner(
209
+ episodes_data, current_episode, current_frame, is_developer, character_data
210
+ ),
211
  )
212
 
213
 
214
  def load_data_prev(
215
+ episodes_data: list,
216
+ current_episode: int,
217
+ current_frame: int,
218
+ is_developer: bool,
219
+ character_data,
220
  ):
221
  if current_frame - 1 >= 0:
222
  current_frame -= 1
 
228
  return (
229
  gr.update(value=current_episode),
230
  gr.update(value=current_frame),
231
+ *load_data_inner(
232
+ episodes_data, current_episode, current_frame, is_developer, character_data
233
+ ),
234
  )
235
 
236
 
237
  def load_from_dropdown(
238
+ episodes_data: dict,
239
+ selected_episode: int,
240
+ selected_frame: int,
241
+ is_developer: bool,
242
+ character_data,
243
  ):
244
  return (
245
  gr.update(value=selected_episode),
246
  gr.update(value=selected_frame),
247
+ *load_data_inner(
248
+ episodes_data,
249
+ selected_episode,
250
+ selected_frame,
251
+ is_developer,
252
+ character_data,
253
+ ),
254
+ # update_characters(character_data)
255
  )
256
 
257
 
 
408
  height,
409
  width,
410
  details,
411
+ chars,
412
  ):
413
  images = []
414
  image_data_b64 = []
415
+ print(chars)
416
  try:
417
  current_scene, frame_num_in_scene = get_scene_number(
418
  details, current_episode, current_frame
 
421
  f"Regenerating data for episode {current_episode}, Scene: {current_scene}, frame {frame_num_in_scene}"
422
  )
423
  frame = episodes_data[current_episode][current_frame]
424
+ related_chars = [character_data[ch] for ch in chars]
425
 
426
  for i, composition in enumerate(frame.compositions):
427
  try:
 
560
  print(f"Error saving image {i} to S3: {e}")
561
  continue
562
  print("All images saved successfully!")
563
+ gr.Info("All images saved successfully!")
564
  except Exception as e:
565
  print(f"Error in save_images: {e}")