hysts HF staff commited on
Commit
26f3e39
1 Parent(s): bbe671a

Add an option to sample random seed

Browse files
Files changed (2) hide show
  1. app.py +7 -1
  2. model.py +5 -2
app.py CHANGED
@@ -53,6 +53,8 @@ def create_advanced_demo(model: Model) -> gr.Blocks:
53
  step=1,
54
  value=20,
55
  label='Number of Steps')
 
 
56
  seed = gr.Slider(0,
57
  100000,
58
  step=1,
@@ -83,9 +85,13 @@ def create_advanced_demo(model: Model) -> gr.Blocks:
83
  model_name,
84
  scheduler_type,
85
  num_steps,
 
86
  seed,
87
  ],
88
- outputs=result)
 
 
 
89
  return demo
90
 
91
 
 
53
  step=1,
54
  value=20,
55
  label='Number of Steps')
56
+ randomize_seed = gr.Checkbox(value=False,
57
+ label='Randomize Seed')
58
  seed = gr.Slider(0,
59
  100000,
60
  step=1,
 
85
  model_name,
86
  scheduler_type,
87
  num_steps,
88
+ randomize_seed,
89
  seed,
90
  ],
91
+ outputs=[
92
+ result,
93
+ seed,
94
+ ])
95
  return demo
96
 
97
 
model.py CHANGED
@@ -106,12 +106,15 @@ class Model:
106
  model_name: str,
107
  scheduler_type: str,
108
  num_steps: int,
 
109
  seed: int,
110
- ) -> PIL.Image.Image:
111
  self.set_pipeline(model_name, scheduler_type)
112
  if scheduler_type == 'PNDM':
113
  num_steps = max(4, min(num_steps, 100))
114
- return self.generate(seed, num_steps)[0]
 
 
115
 
116
  @staticmethod
117
  def to_grid(images: list[PIL.Image.Image],
 
106
  model_name: str,
107
  scheduler_type: str,
108
  num_steps: int,
109
+ randomize_seed: bool,
110
  seed: int,
111
+ ) -> tuple[PIL.Image.Image, int]:
112
  self.set_pipeline(model_name, scheduler_type)
113
  if scheduler_type == 'PNDM':
114
  num_steps = max(4, min(num_steps, 100))
115
+ if randomize_seed:
116
+ seed = self.rng.randint(0, 100000)
117
+ return self.generate(seed, num_steps)[0], seed
118
 
119
  @staticmethod
120
  def to_grid(images: list[PIL.Image.Image],