multimodalart HF staff commited on
Commit
86be4e6
1 Parent(s): 60fee97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import gradio as gr
2
  import spaces
3
  from clip_slider_pipeline import CLIPSliderFlux
@@ -18,6 +20,11 @@ pipe = FluxPipeline.from_pretrained(base_model,
18
  vae=taef1,
19
  torch_dtype=torch.bfloat16)
20
 
 
 
 
 
 
21
  pipe.transformer.to(memory_format=torch.channels_last)
22
  # pipe.transformer = torch.compile(pipe.transformer, mode="max-autotune", fullgraph=True)
23
  # pipe.enable_model_cpu_offload()
@@ -25,6 +32,20 @@ clip_slider = CLIPSliderFlux(pipe, device=torch.device("cuda"))
25
 
26
  MAX_SEED = 2**32-1
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def convert_to_centered_scale(num):
29
  if num % 2 == 0: # even
30
  start = -(num // 2 - 1)
@@ -85,8 +106,11 @@ def generate(prompt,
85
  scale_middle = scale_total.index(0)
86
  post_generation_slider_update = gr.update(label=comma_concepts_x, value=0, minimum=scale_min, maximum=scale_max, interactive=True)
87
  avg_diff_x = avg_diff.cpu()
88
- print(images)
89
- return x_concept_1,x_concept_2, avg_diff_x, export_to_gif(images, "clip.gif", fps=5), canvas, images, images[scale_middle], post_generation_slider_update, seed
 
 
 
90
 
91
  def update_pre_generated_images(slider_value, total_images):
92
  print(total_images)
 
1
+ import os
2
+ import uuid
3
  import gradio as gr
4
  import spaces
5
  from clip_slider_pipeline import CLIPSliderFlux
 
20
  vae=taef1,
21
  torch_dtype=torch.bfloat16)
22
 
23
+ # Example usage:
24
+ # Assuming 'image_list' is your list of PIL images and 'save_directory' is the folder where you want to save them
25
+ paths = save_images_with_unique_filenames(image_list, 'output_images')
26
+ print(paths)
27
+
28
  pipe.transformer.to(memory_format=torch.channels_last)
29
  # pipe.transformer = torch.compile(pipe.transformer, mode="max-autotune", fullgraph=True)
30
  # pipe.enable_model_cpu_offload()
 
32
 
33
  MAX_SEED = 2**32-1
34
 
35
+ def save_images_with_unique_filenames(image_list, save_directory):
36
+ if not os.path.exists(save_directory):
37
+ os.makedirs(save_directory)
38
+
39
+ paths = []
40
+ for image in image_list:
41
+ unique_filename = f"{uuid.uuid4()}.png"
42
+ file_path = os.path.join(save_directory, unique_filename)
43
+
44
+ image.save(file_path)
45
+ paths.append(file_path)
46
+
47
+ return paths
48
+
49
  def convert_to_centered_scale(num):
50
  if num % 2 == 0: # even
51
  start = -(num // 2 - 1)
 
106
  scale_middle = scale_total.index(0)
107
  post_generation_slider_update = gr.update(label=comma_concepts_x, value=0, minimum=scale_min, maximum=scale_max, interactive=True)
108
  avg_diff_x = avg_diff.cpu()
109
+
110
+ os.makedirs("frames", exist_ok=True)
111
+ image_paths = save_images_with_unique_filenames(images, "frames")
112
+
113
+ return x_concept_1,x_concept_2, avg_diff_x, export_to_gif(images, "clip.gif", fps=5), canvas, image_paths, images[scale_middle], post_generation_slider_update, seed
114
 
115
  def update_pre_generated_images(slider_value, total_images):
116
  print(total_images)