linoyts HF staff commited on
Commit
1e32b52
·
verified ·
1 Parent(s): 77576fe

add randomized seed option

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -17,12 +17,17 @@ pipeline.load_lora_weights(
17
  hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8steps-lora.safetensors"), adapter_name="hyper-sd"
18
  )
19
  pipeline.set_adapters(["hyper-sd"], adapter_weights=[0.125])
20
-
 
 
 
 
 
21
  #####################################
22
  # The function for our Gradio app #
23
  #####################################
24
  @spaces.GPU(duration=120)
25
- def generate(prompt, input_image, progress=gr.Progress(track_tqdm=True)):
26
  """
27
  Runs the Flux Control pipeline for editing the given `input_image`
28
  with the specified `prompt`. The pipeline is on CPU by default.
@@ -35,7 +40,7 @@ def generate(prompt, input_image, progress=gr.Progress(track_tqdm=True)):
35
  max_sequence_length=512,
36
  height=input_image.height,
37
  width=input_image.width,
38
- generator=torch.manual_seed(0)
39
  ).images[0]
40
 
41
  return output_image
@@ -65,14 +70,19 @@ def launch_app():
65
  label="Your edit prompt",
66
  placeholder="e.g. 'Turn the color of the mushroom to blue'"
67
  )
 
68
  generate_button = gr.Button("Generate")
69
 
70
  output_image = gr.Image(label="Edited Image")
71
 
72
  # Connect button to function
73
  generate_button.click(
 
 
 
 
74
  fn=generate,
75
- inputs=[prompt, input_image],
76
  outputs=[output_image],
77
  )
78
 
 
17
  hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8steps-lora.safetensors"), adapter_name="hyper-sd"
18
  )
19
  pipeline.set_adapters(["hyper-sd"], adapter_weights=[0.125])
20
+ MAX_SEED = np.iinfo(np.int32).max
21
+ def get_seed(randomize_seed: bool, seed: int) -> int:
22
+ """
23
+ Get the random seed.
24
+ """
25
+ return np.random.randint(0, MAX_SEED) if randomize_seed else seed
26
  #####################################
27
  # The function for our Gradio app #
28
  #####################################
29
  @spaces.GPU(duration=120)
30
+ def generate(prompt, input_image, seed, progress=gr.Progress(track_tqdm=True)):
31
  """
32
  Runs the Flux Control pipeline for editing the given `input_image`
33
  with the specified `prompt`. The pipeline is on CPU by default.
 
40
  max_sequence_length=512,
41
  height=input_image.height,
42
  width=input_image.width,
43
+ generator=torch.manual_seed(seed)
44
  ).images[0]
45
 
46
  return output_image
 
70
  label="Your edit prompt",
71
  placeholder="e.g. 'Turn the color of the mushroom to blue'"
72
  )
73
+ randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
74
  generate_button = gr.Button("Generate")
75
 
76
  output_image = gr.Image(label="Edited Image")
77
 
78
  # Connect button to function
79
  generate_button.click(
80
+ get_seed,
81
+ inputs=[randomize_seed, seed],
82
+ outputs=[seed],
83
+ ).then(
84
  fn=generate,
85
+ inputs=[prompt, input_image, seed],
86
  outputs=[output_image],
87
  )
88