linoyts HF staff commited on
Commit
790c473
·
verified ·
1 Parent(s): b521955

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -3
app.py CHANGED
@@ -24,14 +24,27 @@ pipe = FluxPipeline.from_pretrained(
24
  ).to("cuda")
25
 
26
  @spaces.GPU
27
- def infer(control_image, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
28
  if randomize_seed:
29
  seed = random.randint(0, MAX_SEED)
30
- pipe_prior_output = pipe_prior_redux(control_image)
 
 
 
 
 
 
 
 
 
 
 
 
31
  images = pipe(
32
  guidance_scale=guidance_scale,
33
  num_inference_steps=num_inference_steps,
34
  generator=torch.Generator("cpu").manual_seed(seed),
 
35
  **pipe_prior_output,
36
  ).images[0]
37
  return images, seed
@@ -53,6 +66,20 @@ An adapter for FLUX [dev] to create image variations
53
  with gr.Row():
54
  with gr.Column():
55
  input_image = gr.Image(label="Image to create variations", type="pil")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  run_button = gr.Button("Run")
57
  result = gr.Image(label="Result", show_label=False)
58
 
@@ -107,7 +134,7 @@ An adapter for FLUX [dev] to create image variations
107
  gr.on(
108
  triggers=[run_button.click],
109
  fn = infer,
110
- inputs = [input_image, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
111
  outputs = [result, seed]
112
  )
113
 
 
24
  ).to("cuda")
25
 
26
  @spaces.GPU
27
+ def infer(control_image, prompt, reference_scale= 0.03 , seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
28
  if randomize_seed:
29
  seed = random.randint(0, MAX_SEED)
30
+ pipe_prior_output = pipe_prior_redux(control_image, prompt=prompt)
31
+ cond_size = 729
32
+ hidden_size = 4096
33
+ max_sequence_length = 512
34
+ full_attention_size = max_sequence_length + hidden_size + cond_size
35
+ attention_mask = torch.zeros(
36
+ (full_attention_size, full_attention_size), device="cuda", dtype=torch.bfloat16
37
+ )
38
+ bias = torch.log(
39
+ torch.tensor(reference_scale, dtype=torch.bfloat16, device="cuda").clamp(min=1e-5, max=1)
40
+ )
41
+ attention_mask[:, max_sequence_length : max_sequence_length + cond_size] = bias
42
+ joint_attention_kwargs=dict(attention_mask=attention_mask)
43
  images = pipe(
44
  guidance_scale=guidance_scale,
45
  num_inference_steps=num_inference_steps,
46
  generator=torch.Generator("cpu").manual_seed(seed),
47
+ joint_attention_kwargs=joint_attention_kwargs,
48
  **pipe_prior_output,
49
  ).images[0]
50
  return images, seed
 
66
  with gr.Row():
67
  with gr.Column():
68
  input_image = gr.Image(label="Image to create variations", type="pil")
69
+ prompt = gr.Text(
70
+ label="Prompt",
71
+ show_label=False,
72
+ max_lines=1,
73
+ placeholder="Enter your prompt",
74
+ container=False,
75
+ )
76
+ reference_scale = gr.Slider(
77
+ label="Masking Scale",
78
+ minimum=0.01,
79
+ maximum=0.08,
80
+ step=0.001,
81
+ value=0.03,
82
+ )
83
  run_button = gr.Button("Run")
84
  result = gr.Image(label="Result", show_label=False)
85
 
 
134
  gr.on(
135
  triggers=[run_button.click],
136
  fn = infer,
137
+ inputs = [input_image, prompt, reference_scale, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
138
  outputs = [result, seed]
139
  )
140