linoyts HF staff commited on
Commit
0be383f
1 Parent(s): 5fd0376

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -85,9 +85,14 @@ def update_scales(x,prompt,seed, steps, guidance_scale,
85
 
86
  # for spectrum generation
87
  images = []
88
- steps=5
89
- high_scale = x if x > 0 else abs(max(x, -3))
90
- low_scale = x if x < 0 else x * (-1)
 
 
 
 
 
91
 
92
  if img2img_type=="controlnet canny" and img is not None:
93
  control_img = process_controlnet_img(img)
@@ -95,13 +100,16 @@ def update_scales(x,prompt,seed, steps, guidance_scale,
95
  elif img2img_type=="ip adapter" and img is not None:
96
  image = clip_slider.generate(prompt, guidance_scale=guidance_scale, ip_adapter_image=img, scale=x,seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
97
  else:
98
- for i in range(steps):
99
  cur_scale = low_scale + (high_scale - low_scale) * i / (steps - 1)
100
  image = clip_slider.generate(prompt,
101
  #guidance_scale=guidance_scale,
102
  scale=cur_scale, seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
103
  images.append(image)
104
- return export_to_gif(images, "clip.gif", fps=5)
 
 
 
105
 
106
 
107
  def reset_recalc_directions():
@@ -182,6 +190,7 @@ with gr.Blocks(css=css) as demo:
182
  x = gr.Slider(minimum=-3, value=0, step=0.1, maximum=3.5, elem_id="x", interactive=False)
183
  #y = gr.Slider(minimum=-10, value=0, maximum=10, elem_id="y", interactive=False)
184
  output_image = gr.Image(elem_id="image_out")
 
185
  # with gr.Row():
186
  # generate_butt = gr.Button("generate")
187
 
@@ -258,7 +267,7 @@ with gr.Blocks(css=css) as demo:
258
 
259
  iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
260
  seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
261
- x.release(fn=update_scales, inputs=[x, prompt, seed, steps, guidance_scale, avg_diff_x], outputs=[output_image], trigger_mode='always_last')
262
  # generate_butt_a.click(fn=update_scales, inputs=[x_a,y_a, prompt_a, seed_a, steps_a, guidance_scale_a, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale], outputs=[output_image_a])
263
  # submit_a.click(fn=generate,
264
  # inputs=[slider_x_a, slider_y_a, prompt_a, seed_a, iterations_a, steps_a, guidance_scale_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale],
 
85
 
86
  # for spectrum generation
87
  images = []
88
+ img_steps=5
89
+
90
+ if x < 0:
91
+ high_scale = 0
92
+ low_scale = x
93
+ else:
94
+ high_scale = x
95
+ low_scale = 0
96
 
97
  if img2img_type=="controlnet canny" and img is not None:
98
  control_img = process_controlnet_img(img)
 
100
  elif img2img_type=="ip adapter" and img is not None:
101
  image = clip_slider.generate(prompt, guidance_scale=guidance_scale, ip_adapter_image=img, scale=x,seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
102
  else:
103
+ for i in range(img_steps):
104
  cur_scale = low_scale + (high_scale - low_scale) * i / (steps - 1)
105
  image = clip_slider.generate(prompt,
106
  #guidance_scale=guidance_scale,
107
  scale=cur_scale, seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
108
  images.append(image)
109
+ canvas = Image.new('RGB', (1280, 256))
110
+ for i, im in enumerate(images):
111
+ canvas.paste(im, (256 * i, 0))
112
+ return export_to_gif(images, "clip.gif", fps=5), canvas
113
 
114
 
115
  def reset_recalc_directions():
 
190
  x = gr.Slider(minimum=-3, value=0, step=0.1, maximum=3.5, elem_id="x", interactive=False)
191
  #y = gr.Slider(minimum=-10, value=0, maximum=10, elem_id="y", interactive=False)
192
  output_image = gr.Image(elem_id="image_out")
193
+ image_seq = gr.Image()
194
  # with gr.Row():
195
  # generate_butt = gr.Button("generate")
196
 
 
267
 
268
  iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
269
  seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
270
+ x.release(fn=update_scales, inputs=[x, prompt, seed, steps, guidance_scale, avg_diff_x], outputs=[output_image, image_seq], trigger_mode='always_last')
271
  # generate_butt_a.click(fn=update_scales, inputs=[x_a,y_a, prompt_a, seed_a, steps_a, guidance_scale_a, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale], outputs=[output_image_a])
272
  # submit_a.click(fn=generate,
273
  # inputs=[slider_x_a, slider_y_a, prompt_a, seed_a, iterations_a, steps_a, guidance_scale_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale],