chaojiemao commited on
Commit
e57d7df
·
verified ·
1 Parent(s): 179a5c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -93
app.py CHANGED
@@ -1,6 +1,5 @@
1
  # -*- coding: utf-8 -*-
2
  # Copyright (c) Alibaba, Inc. and its affiliates.
3
- import spaces
4
  import base64
5
  import copy
6
  import glob
@@ -12,7 +11,8 @@ import shlex
12
  import string
13
  import subprocess
14
  import threading
15
-
 
16
  subprocess.run(shlex.split('pip install flash-attn --no-build-isolation'),
17
  env=os.environ | {'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"})
18
 
@@ -45,9 +45,6 @@ video_sty = '\U0001f3a5' # 🎥
45
 
46
  lock = threading.Lock()
47
 
48
- inference_dict = {
49
- "ACE": ACEInference
50
- }
51
 
52
  class ChatBotUI(object):
53
  def __init__(self,
@@ -85,14 +82,15 @@ class ChatBotUI(object):
85
  self.model_choices[model_name] = model_cfg
86
  print('Models: ', self.model_choices.keys())
87
 
88
- FS.get_from("ms://AI-ModelScope/FLUX.1-dev@ae.safetensors")
89
- FS.get_dir_to_local_dir("ms://AI-ModelScope/FLUX.1-dev@text_encoder_2/")
90
- FS.get_dir_to_local_dir("ms://AI-ModelScope/FLUX.1-dev@tokenizer_2/")
91
- FS.get_dir_to_local_dir("ms://AI-ModelScope/FLUX.1-dev@text_encoder/")
92
- FS.get_dir_to_local_dir("ms://AI-ModelScope/FLUX.1-dev@tokenizer/")
93
-
 
94
  assert len(self.model_choices) > 0
95
- if self.default_model_name == "": self.default_model_name = self.model_choices.keys()[0]
96
  self.model_name = self.default_model_name
97
  self.pipe = ACEInference()
98
  self.pipe.init_from_cfg(self.model_choices[self.default_model_name])
@@ -149,39 +147,39 @@ class ChatBotUI(object):
149
  },
150
  {
151
  'role':
152
- 'user',
153
  'content':
154
- 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : "a girl is on the beach"',
155
  },
156
  {
157
  'role':
158
- 'assistant',
159
  'content':
160
- "A radiant woman stands on a deserted beach, arms outstretched, wearing a beige trench coat, white blouse, light blue jeans, and chic boots, against a backdrop of soft sky and sea. Moments later, she is seen mid-twirl, arms exuberant, with the lighting suggesting dawn or dusk. Then, she runs along the beach, her attire complemented by an off-white scarf and black ankle boots, the tranquil sea behind her. Finally, she holds a paper airplane, her pose reflecting joy and freedom, with the ocean's gentle waves and the sky's soft pastel hues enhancing the serene ambiance.",
161
  },
162
  {
163
  'role':
164
- 'user',
165
  'content':
166
- 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : "A man jogging on a football field"',
167
  },
168
  {
169
  'role':
170
- 'assistant',
171
  'content':
172
- "A determined man in athletic attire, including a blue long-sleeve shirt, black shorts, and blue socks, jogs around a snow-covered soccer field, showcasing his solitary exercise in a quiet, overcast setting. His long dreadlocks, focused expression, and the serene winter backdrop highlight his dedication to fitness. As he moves, his attire, consisting of a blue sports sweatshirt, black athletic pants, gloves, and sneakers, grips the snowy ground. He is seen running past a chain-link fence enclosing the playground area, with a basketball hoop and children's slide, suggesting a moment of solitary exercise amidst the empty field.",
173
  },
174
  {
175
  'role':
176
- 'user',
177
  'content':
178
- 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : " A woman is dancing, HD footage, close-up"',
179
  },
180
  {
181
  'role':
182
- 'assistant',
183
  'content':
184
- 'A young woman with her hair in an updo and wearing a teal hoodie stands against a light backdrop, initially looking over her shoulder with a contemplative expression. She then confidently makes a subtle dance move, suggesting rhythm and movement. Next, she appears poised and focused, looking directly at the camera. Her expression shifts to one of introspection as she gazes downward slightly. Finally, she dances with confidence, her left hand over her heart, symbolizing a poignant moment, all while dressed in the same teal hoodie against a plain, light-colored background.',
185
  },
186
  ]
187
 
@@ -348,6 +346,7 @@ class ChatBotUI(object):
348
  show_download_button=True,
349
  elem_id='image_viewer')
350
 
 
351
  with gr.Accordion(label='Setting', open=False):
352
  with gr.Row():
353
  self.model_name_dd = gr.Dropdown(
@@ -373,6 +372,7 @@ class ChatBotUI(object):
373
  label='Refiner Prompt',
374
  container=False)
375
 
 
376
  with gr.Row():
377
  with gr.Column(scale=8, min_width=500):
378
  with gr.Row():
@@ -393,11 +393,10 @@ class ChatBotUI(object):
393
  visible=self.pipe.input.get("guide_rescale", None) is not None,
394
  label='Rescale')
395
  self.refiner_scale = gr.Slider(minimum=-0.1,
396
- maximum=1.0,
397
- value=self.pipe.input.get("refiner_scale", 0.5),
398
- visible=self.pipe.input.get("refiner_scale",
399
- None) is not None,
400
- label='Refiner Scale')
401
  self.seed = gr.Slider(minimum=-1,
402
  maximum=10000000,
403
  value=-1,
@@ -486,7 +485,7 @@ class ChatBotUI(object):
486
  show_progress=False):
487
  with gr.Column(scale=1, min_width=100, visible=False) as self.upload_panel:
488
  self.upload_btn = gr.Button(value=upload_sty +
489
- ' Upload',
490
  variant='secondary')
491
  with gr.Column(scale=5, min_width=500):
492
  self.text = gr.Textbox(
@@ -498,7 +497,7 @@ class ChatBotUI(object):
498
  variant='primary')
499
  with gr.Column(scale=1, min_width=100):
500
  self.retry_btn = gr.Button(value=refresh_sty +
501
- ' Retry',
502
  variant='secondary')
503
  with gr.Column(scale=1, min_width=100):
504
  self.mode_checkbox = gr.Checkbox(
@@ -507,7 +506,7 @@ class ChatBotUI(object):
507
  with gr.Column(scale=(1 if self.enable_i2v else 0),
508
  min_width=0):
509
  self.video_gen_btn = gr.Button(value=video_sty +
510
- ' Gen Video',
511
  variant='secondary',
512
  visible=self.enable_i2v)
513
  with gr.Column(scale=(1 if self.enable_i2v else 0),
@@ -529,7 +528,7 @@ class ChatBotUI(object):
529
  def set_callbacks(self, *args, **kwargs):
530
 
531
  ########################################
532
- @spaces.GPU(duration=60)
533
  def change_model(model_name):
534
  if model_name not in self.model_choices:
535
  gr.Info('The provided model name is not a valid choice!')
@@ -539,24 +538,21 @@ class ChatBotUI(object):
539
  lock.acquire()
540
  del self.pipe
541
  torch.cuda.empty_cache()
542
- torch.cuda.ipc_collect()
543
- pipe_cfg = self.model_choices[model_name]
544
- infer_name = pipe_cfg.get("INFERENCE_TYPE", "ACE")
545
- self.pipe = inference_dict[infer_name]()
546
- self.pipe.init_from_cfg(pipe_cfg)
547
  self.model_name = model_name
548
  lock.release()
549
 
550
  return (model_name, gr.update(), gr.update(),
551
  gr.Slider(
552
- value=self.pipe.input.get("sample_steps", 20),
553
- visible=self.pipe.input.get("sample_steps", None) is not None),
554
  gr.Slider(
555
  value=self.pipe.input.get("guide_scale", 4.5),
556
  visible=self.pipe.input.get("guide_scale", None) is not None),
557
  gr.Slider(
558
- value=self.pipe.input.get("guide_rescale", 0.5),
559
- visible=self.pipe.input.get("guide_rescale", None) is not None),
560
  gr.Slider(
561
  value=self.pipe.input.get("output_height", 1024),
562
  visible=self.pipe.input.get("output_height", None) is not None),
@@ -567,9 +563,9 @@ class ChatBotUI(object):
567
  value=self.pipe.input.get("refiner_prompt", ""),
568
  visible=self.pipe.input.get("refiner_prompt", None) is not None),
569
  gr.Slider(
570
- value=self.pipe.input.get("refiner_scale", 0.5),
571
- visible=self.pipe.input.get("refiner_scale", None) is not None
572
- ),
573
  gr.Checkbox(
574
  value=self.pipe.input.get("use_ace", True),
575
  visible=self.pipe.input.get("use_ace", None) is not None
@@ -586,6 +582,7 @@ class ChatBotUI(object):
586
  self.output_width, self.refiner_prompt, self.refiner_scale,
587
  self.use_ace])
588
 
 
589
  def mode_change(mode_check):
590
  if mode_check:
591
  # ChatBot
@@ -607,12 +604,12 @@ class ChatBotUI(object):
607
  gr.Column(visible=False),
608
  gr.Markdown(value=self.legacy_inst)
609
  )
610
-
611
  self.mode_checkbox.change(mode_change, inputs=[self.mode_checkbox],
612
  outputs=[self.legacy_group, self.chat_group,
613
  self.chat_btn, self.ui_mode,
614
  self.upload_panel, self.instruction])
615
 
 
616
  ########################################
617
  def generate_gallery(text, images):
618
  if text.endswith(' '):
@@ -690,9 +687,9 @@ class ChatBotUI(object):
690
  messages = copy.deepcopy(self.enhance_ctx)
691
  messages.append({
692
  'role':
693
- 'user',
694
  'content':
695
- f'Create an imaginative video descriptive caption or modify an earlier caption in ENGLISH for the user input: "{prompt}"',
696
  })
697
  lock.acquire()
698
  outputs = self.enhancer(
@@ -741,33 +738,33 @@ class ChatBotUI(object):
741
  outputs=[self.history, self.chatbot, self.text, self.gallery])
742
 
743
  ########################################
744
- @spaces.GPU(duration=240)
745
  def run_chat(
746
- message,
747
- legacy_image,
748
- ui_mode,
749
- use_ace,
750
- extend_prompt,
751
- history,
752
- images,
753
- use_history,
754
- history_result,
755
- negative_prompt,
756
- cfg_scale,
757
- rescale,
758
- refiner_prompt,
759
- refiner_scale,
760
- step,
761
- seed,
762
- output_h,
763
- output_w,
764
- video_auto,
765
- video_steps,
766
- video_frames,
767
- video_cfg_scale,
768
- video_fps,
769
- video_seed,
770
- progress=gr.Progress(track_tqdm=True)):
771
  legacy_img_ids = []
772
  if ui_mode == 'legacy':
773
  if legacy_image is not None:
@@ -798,12 +795,8 @@ class ChatBotUI(object):
798
  )
799
  continue
800
  placeholder = '{image}' if i == 0 else '{' + f'image{i}' + '}'
801
- if placeholder not in new_message:
802
- new_message = re.sub(f'@{img_id}', placeholder,
803
- new_message)
804
- else:
805
- new_message = re.sub(f'@{img_id} ', "",
806
- new_message, 1)
807
  img_meta = images[img_id]
808
  img_path = img_meta['image']
809
  img_mask = img_meta['mask']
@@ -844,7 +837,7 @@ class ChatBotUI(object):
844
  history_io=history_io,
845
  output_height=output_h,
846
  output_width=output_w,
847
- sampler=self.pipe.input.get("sampler", "ddim"),
848
  sample_steps=step,
849
  guide_scale=cfg_scale,
850
  guide_rescale=rescale,
@@ -915,7 +908,7 @@ class ChatBotUI(object):
915
  device='cuda').manual_seed(video_seed)
916
  pixel_values = load_image(img.convert('RGB'),
917
  max_num=self.llm_max_num).to(
918
- torch.bfloat16).cuda()
919
  prompt = self.captioner.chat(self.llm_tokenizer, pixel_values,
920
  self.llm_prompt,
921
  self.llm_generation_config)
@@ -926,9 +919,9 @@ class ChatBotUI(object):
926
  messages = copy.deepcopy(self.enhance_ctx)
927
  messages.append({
928
  'role':
929
- 'user',
930
  'content':
931
- f'Create an imaginative video descriptive caption or modify an earlier caption in ENGLISH for the user input: "{prompt}"',
932
  })
933
  lock.acquire()
934
  outputs = self.enhancer(
@@ -963,7 +956,7 @@ class ChatBotUI(object):
963
  return (history, images, gr.Image(value=save_path),
964
  history_result, self.get_history(
965
  history), gr.update(), gr.update(
966
- visible=False), retry_msg)
967
 
968
  chat_inputs = [
969
  self.legacy_image_uploader, self.ui_mode, self.use_ace,
@@ -1013,13 +1006,9 @@ class ChatBotUI(object):
1013
  w = int(w / ratio)
1014
  img = img.resize((w, h))
1015
  edit_image.append(img)
1016
- if img_mask is not None:
1017
- img_mask = img_mask if np.sum(np.array(img_mask)) > 0 else None
1018
  edit_image_mask.append(
1019
  img_mask if img_mask is not None else None)
1020
  edit_task.append(task)
1021
- if ref1 is not None:
1022
- ref1 = ref1 if np.sum(np.array(ref1)) > 0 else None
1023
  if ref1 is not None:
1024
  edit_image.append(ref1)
1025
  edit_image_mask.append(None)
@@ -1059,8 +1048,9 @@ class ChatBotUI(object):
1059
  img_id = get_md5(img_b64)[:12]
1060
  save_path = os.path.join(self.cache_dir, f'{img_id}.png')
1061
  img.convert('RGB').save(save_path)
 
1062
  return self.get_history(history), gr.update(value=''), gr.update(
1063
- visible=False), gr.update(value=save_path), gr.update(value=-1)
1064
 
1065
  with self.eg:
1066
  self.example_task = gr.Text(label='Task Name',
@@ -1090,7 +1080,6 @@ class ChatBotUI(object):
1090
  examples_per_page=4,
1091
  cache_examples=False,
1092
  run_on_click=True)
1093
-
1094
  ########################################
1095
  def upload_image():
1096
  return (gr.update(visible=True,
@@ -1181,7 +1170,7 @@ class ChatBotUI(object):
1181
  image, history, images)
1182
  return gr.update(visible=False), gr.update(
1183
  visible=True), gr.update(
1184
- value=self.get_history(history)), history, images
1185
 
1186
  self.sub_btn_1.click(
1187
  submit_upload_image,
@@ -1197,7 +1186,7 @@ class ChatBotUI(object):
1197
  imagemask, mask_type, history, images)
1198
  return gr.update(visible=False), gr.update(
1199
  visible=True), gr.update(
1200
- value=self.get_history(history)), history, images
1201
 
1202
  self.sub_btn_2.click(submit_edit_image,
1203
  inputs=[
@@ -1413,6 +1402,7 @@ class ChatBotUI(object):
1413
  return history, images, img_id
1414
 
1415
 
 
1416
  if __name__ == '__main__':
1417
  cfg = "config/chatbot_ui.yaml"
1418
  with gr.Blocks() as demo:
 
1
  # -*- coding: utf-8 -*-
2
  # Copyright (c) Alibaba, Inc. and its affiliates.
 
3
  import base64
4
  import copy
5
  import glob
 
11
  import string
12
  import subprocess
13
  import threading
14
+ import spaces
15
+
16
  subprocess.run(shlex.split('pip install flash-attn --no-build-isolation'),
17
  env=os.environ | {'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"})
18
 
 
45
 
46
  lock = threading.Lock()
47
 
 
 
 
48
 
49
  class ChatBotUI(object):
50
  def __init__(self,
 
82
  self.model_choices[model_name] = model_cfg
83
  print('Models: ', self.model_choices.keys())
84
 
85
+ #FS.get_from("ms://AI-ModelScope/FLUX.1-dev@flux1-dev.safetensors")
86
+ #FS.get_from("ms://AI-ModelScope/FLUX.1-dev@ae.safetensors")
87
+ #FS.get_dir_to_local_dir("ms://AI-ModelScope/FLUX.1-dev@text_encoder_2/")
88
+ #FS.get_dir_to_local_dir("ms://AI-ModelScope/FLUX.1-dev@tokenizer_2/")
89
+ #FS.get_dir_to_local_dir("ms://AI-ModelScope/FLUX.1-dev@text_encoder/")
90
+ #FS.get_dir_to_local_dir("ms://AI-ModelScope/FLUX.1-dev@tokenizer/")
91
+
92
  assert len(self.model_choices) > 0
93
+ if self.default_model_name == "": self.default_model_name = list(self.model_choices.keys())[0]
94
  self.model_name = self.default_model_name
95
  self.pipe = ACEInference()
96
  self.pipe.init_from_cfg(self.model_choices[self.default_model_name])
 
147
  },
148
  {
149
  'role':
150
+ 'user',
151
  'content':
152
+ 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : "a girl is on the beach"',
153
  },
154
  {
155
  'role':
156
+ 'assistant',
157
  'content':
158
+ "A radiant woman stands on a deserted beach, arms outstretched, wearing a beige trench coat, white blouse, light blue jeans, and chic boots, against a backdrop of soft sky and sea. Moments later, she is seen mid-twirl, arms exuberant, with the lighting suggesting dawn or dusk. Then, she runs along the beach, her attire complemented by an off-white scarf and black ankle boots, the tranquil sea behind her. Finally, she holds a paper airplane, her pose reflecting joy and freedom, with the ocean's gentle waves and the sky's soft pastel hues enhancing the serene ambiance.",
159
  },
160
  {
161
  'role':
162
+ 'user',
163
  'content':
164
+ 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : "A man jogging on a football field"',
165
  },
166
  {
167
  'role':
168
+ 'assistant',
169
  'content':
170
+ "A determined man in athletic attire, including a blue long-sleeve shirt, black shorts, and blue socks, jogs around a snow-covered soccer field, showcasing his solitary exercise in a quiet, overcast setting. His long dreadlocks, focused expression, and the serene winter backdrop highlight his dedication to fitness. As he moves, his attire, consisting of a blue sports sweatshirt, black athletic pants, gloves, and sneakers, grips the snowy ground. He is seen running past a chain-link fence enclosing the playground area, with a basketball hoop and children's slide, suggesting a moment of solitary exercise amidst the empty field.",
171
  },
172
  {
173
  'role':
174
+ 'user',
175
  'content':
176
+ 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : " A woman is dancing, HD footage, close-up"',
177
  },
178
  {
179
  'role':
180
+ 'assistant',
181
  'content':
182
+ 'A young woman with her hair in an updo and wearing a teal hoodie stands against a light backdrop, initially looking over her shoulder with a contemplative expression. She then confidently makes a subtle dance move, suggesting rhythm and movement. Next, she appears poised and focused, looking directly at the camera. Her expression shifts to one of introspection as she gazes downward slightly. Finally, she dances with confidence, her left hand over her heart, symbolizing a poignant moment, all while dressed in the same teal hoodie against a plain, light-colored background.',
183
  },
184
  ]
185
 
 
346
  show_download_button=True,
347
  elem_id='image_viewer')
348
 
349
+
350
  with gr.Accordion(label='Setting', open=False):
351
  with gr.Row():
352
  self.model_name_dd = gr.Dropdown(
 
372
  label='Refiner Prompt',
373
  container=False)
374
 
375
+
376
  with gr.Row():
377
  with gr.Column(scale=8, min_width=500):
378
  with gr.Row():
 
393
  visible=self.pipe.input.get("guide_rescale", None) is not None,
394
  label='Rescale')
395
  self.refiner_scale = gr.Slider(minimum=-0.1,
396
+ maximum=1.0,
397
+ value=self.pipe.input.get("refiner_scale", -1),
398
+ visible=self.pipe.input.get("refiner_scale", None) is not None,
399
+ label='Refiner Scale')
 
400
  self.seed = gr.Slider(minimum=-1,
401
  maximum=10000000,
402
  value=-1,
 
485
  show_progress=False):
486
  with gr.Column(scale=1, min_width=100, visible=False) as self.upload_panel:
487
  self.upload_btn = gr.Button(value=upload_sty +
488
+ ' Upload',
489
  variant='secondary')
490
  with gr.Column(scale=5, min_width=500):
491
  self.text = gr.Textbox(
 
497
  variant='primary')
498
  with gr.Column(scale=1, min_width=100):
499
  self.retry_btn = gr.Button(value=refresh_sty +
500
+ ' Retry',
501
  variant='secondary')
502
  with gr.Column(scale=1, min_width=100):
503
  self.mode_checkbox = gr.Checkbox(
 
506
  with gr.Column(scale=(1 if self.enable_i2v else 0),
507
  min_width=0):
508
  self.video_gen_btn = gr.Button(value=video_sty +
509
+ ' Gen Video',
510
  variant='secondary',
511
  visible=self.enable_i2v)
512
  with gr.Column(scale=(1 if self.enable_i2v else 0),
 
528
  def set_callbacks(self, *args, **kwargs):
529
 
530
  ########################################
531
+ #@spaces.GPU(duration=60)
532
  def change_model(model_name):
533
  if model_name not in self.model_choices:
534
  gr.Info('The provided model name is not a valid choice!')
 
538
  lock.acquire()
539
  del self.pipe
540
  torch.cuda.empty_cache()
541
+ self.pipe = ACEInference()
542
+ self.pipe.init_from_cfg(self.model_choices[model_name])
 
 
 
543
  self.model_name = model_name
544
  lock.release()
545
 
546
  return (model_name, gr.update(), gr.update(),
547
  gr.Slider(
548
+ value=self.pipe.input.get("sample_steps", 20),
549
+ visible=self.pipe.input.get("sample_steps", None) is not None),
550
  gr.Slider(
551
  value=self.pipe.input.get("guide_scale", 4.5),
552
  visible=self.pipe.input.get("guide_scale", None) is not None),
553
  gr.Slider(
554
+ value=self.pipe.input.get("guide_rescale", 0.5),
555
+ visible=self.pipe.input.get("guide_rescale", None) is not None),
556
  gr.Slider(
557
  value=self.pipe.input.get("output_height", 1024),
558
  visible=self.pipe.input.get("output_height", None) is not None),
 
563
  value=self.pipe.input.get("refiner_prompt", ""),
564
  visible=self.pipe.input.get("refiner_prompt", None) is not None),
565
  gr.Slider(
566
+ value=self.pipe.input.get("refiner_scale", -1),
567
+ visible=self.pipe.input.get("refiner_scale", None) is not None
568
+ ),
569
  gr.Checkbox(
570
  value=self.pipe.input.get("use_ace", True),
571
  visible=self.pipe.input.get("use_ace", None) is not None
 
582
  self.output_width, self.refiner_prompt, self.refiner_scale,
583
  self.use_ace])
584
 
585
+
586
  def mode_change(mode_check):
587
  if mode_check:
588
  # ChatBot
 
604
  gr.Column(visible=False),
605
  gr.Markdown(value=self.legacy_inst)
606
  )
 
607
  self.mode_checkbox.change(mode_change, inputs=[self.mode_checkbox],
608
  outputs=[self.legacy_group, self.chat_group,
609
  self.chat_btn, self.ui_mode,
610
  self.upload_panel, self.instruction])
611
 
612
+
613
  ########################################
614
  def generate_gallery(text, images):
615
  if text.endswith(' '):
 
687
  messages = copy.deepcopy(self.enhance_ctx)
688
  messages.append({
689
  'role':
690
+ 'user',
691
  'content':
692
+ f'Create an imaginative video descriptive caption or modify an earlier caption in ENGLISH for the user input: "{prompt}"',
693
  })
694
  lock.acquire()
695
  outputs = self.enhancer(
 
738
  outputs=[self.history, self.chatbot, self.text, self.gallery])
739
 
740
  ########################################
741
+ @spaces.GPU(duration=120)
742
  def run_chat(
743
+ message,
744
+ legacy_image,
745
+ ui_mode,
746
+ use_ace,
747
+ extend_prompt,
748
+ history,
749
+ images,
750
+ use_history,
751
+ history_result,
752
+ negative_prompt,
753
+ cfg_scale,
754
+ rescale,
755
+ refiner_prompt,
756
+ refiner_scale,
757
+ step,
758
+ seed,
759
+ output_h,
760
+ output_w,
761
+ video_auto,
762
+ video_steps,
763
+ video_frames,
764
+ video_cfg_scale,
765
+ video_fps,
766
+ video_seed,
767
+ progress=gr.Progress(track_tqdm=True)):
768
  legacy_img_ids = []
769
  if ui_mode == 'legacy':
770
  if legacy_image is not None:
 
795
  )
796
  continue
797
  placeholder = '{image}' if i == 0 else '{' + f'image{i}' + '}'
798
+ new_message = re.sub(f'@{img_id}', placeholder,
799
+ new_message)
 
 
 
 
800
  img_meta = images[img_id]
801
  img_path = img_meta['image']
802
  img_mask = img_meta['mask']
 
837
  history_io=history_io,
838
  output_height=output_h,
839
  output_width=output_w,
840
+ sampler='ddim',
841
  sample_steps=step,
842
  guide_scale=cfg_scale,
843
  guide_rescale=rescale,
 
908
  device='cuda').manual_seed(video_seed)
909
  pixel_values = load_image(img.convert('RGB'),
910
  max_num=self.llm_max_num).to(
911
+ torch.bfloat16).cuda()
912
  prompt = self.captioner.chat(self.llm_tokenizer, pixel_values,
913
  self.llm_prompt,
914
  self.llm_generation_config)
 
919
  messages = copy.deepcopy(self.enhance_ctx)
920
  messages.append({
921
  'role':
922
+ 'user',
923
  'content':
924
+ f'Create an imaginative video descriptive caption or modify an earlier caption in ENGLISH for the user input: "{prompt}"',
925
  })
926
  lock.acquire()
927
  outputs = self.enhancer(
 
956
  return (history, images, gr.Image(value=save_path),
957
  history_result, self.get_history(
958
  history), gr.update(), gr.update(
959
+ visible=False), retry_msg)
960
 
961
  chat_inputs = [
962
  self.legacy_image_uploader, self.ui_mode, self.use_ace,
 
1006
  w = int(w / ratio)
1007
  img = img.resize((w, h))
1008
  edit_image.append(img)
 
 
1009
  edit_image_mask.append(
1010
  img_mask if img_mask is not None else None)
1011
  edit_task.append(task)
 
 
1012
  if ref1 is not None:
1013
  edit_image.append(ref1)
1014
  edit_image_mask.append(None)
 
1048
  img_id = get_md5(img_b64)[:12]
1049
  save_path = os.path.join(self.cache_dir, f'{img_id}.png')
1050
  img.convert('RGB').save(save_path)
1051
+
1052
  return self.get_history(history), gr.update(value=''), gr.update(
1053
+ visible=False), gr.update(value=save_path), gr.update(value=-1)
1054
 
1055
  with self.eg:
1056
  self.example_task = gr.Text(label='Task Name',
 
1080
  examples_per_page=4,
1081
  cache_examples=False,
1082
  run_on_click=True)
 
1083
  ########################################
1084
  def upload_image():
1085
  return (gr.update(visible=True,
 
1170
  image, history, images)
1171
  return gr.update(visible=False), gr.update(
1172
  visible=True), gr.update(
1173
+ value=self.get_history(history)), history, images
1174
 
1175
  self.sub_btn_1.click(
1176
  submit_upload_image,
 
1186
  imagemask, mask_type, history, images)
1187
  return gr.update(visible=False), gr.update(
1188
  visible=True), gr.update(
1189
+ value=self.get_history(history)), history, images
1190
 
1191
  self.sub_btn_2.click(submit_edit_image,
1192
  inputs=[
 
1402
  return history, images, img_id
1403
 
1404
 
1405
+
1406
  if __name__ == '__main__':
1407
  cfg = "config/chatbot_ui.yaml"
1408
  with gr.Blocks() as demo: