linoyts HF Staff commited on
Commit
41610b4
·
verified ·
1 Parent(s): 38355c3

initial ui changes

Browse files

add random seed + advanced options

Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -37,6 +37,13 @@ CONCEPTS_MAP = {'age':'age','animal fur':'animal_fur', 'deterioration': 'deterio
37
 
38
  concept_options = list(CONCEPTS_MAP.keys())
39
 
 
 
 
 
 
 
 
40
  @spaces.GPU
41
  def get_image_embeds(pil_image, model=clip_model, preproc=preprocess, dev=device):
42
  """Get CLIP image embeddings for a given PIL image"""
@@ -188,19 +195,25 @@ with gr.Blocks(title="Image Concept Composition") as demo:
188
  concept_name3 = gr.Dropdown(concept_options, label="concept 3", value= None, info="concept type")
189
  rank3 = gr.Slider(minimum=1, maximum=50, value=30, step=1, label="Rank 3")
190
 
191
- prompt = gr.Textbox(label="Guidance Prompt (Optional)", placeholder="Optional text prompt to guide generation")
 
 
 
 
 
 
 
192
 
193
- with gr.Row():
194
- scale = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Scale")
195
- seed = gr.Number(value=420, label="Seed", precision=0)
196
 
197
- submit_btn = gr.Button("Generate")
198
 
199
  with gr.Column():
200
  output_image = gr.Image(label="composed output", show_label=True)
201
 
202
  submit_btn.click(
203
- fn=process_and_display,
 
 
 
204
  inputs=[
205
  base_image,
206
  concept_image1, concept_name1,
 
37
 
38
  concept_options = list(CONCEPTS_MAP.keys())
39
 
40
+
41
+ MAX_SEED = np.iinfo(np.int32).max
42
+ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
43
+ if randomize_seed:
44
+ seed = random.randint(0, MAX_SEED)
45
+ return seed
46
+
47
  @spaces.GPU
48
  def get_image_embeds(pil_image, model=clip_model, preproc=preprocess, dev=device):
49
  """Get CLIP image embeddings for a given PIL image"""
 
195
  concept_name3 = gr.Dropdown(concept_options, label="concept 3", value= None, info="concept type")
196
  rank3 = gr.Slider(minimum=1, maximum=50, value=30, step=1, label="Rank 3")
197
 
198
+ submit_btn = gr.Button("Generate")
199
+
200
+ with gr.Accordion("Advanced options", open=False):
201
+ prompt = gr.Textbox(label="Guidance Prompt (Optional)", placeholder="Optional text prompt to guide generation")
202
+ with gr.Row():
203
+ scale = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Scale")
204
+ randomize_seed = gr,Checkbox(value=True, label="Randomize seed")
205
+ seed = gr.Number(value=0, label="Seed", precision=0)
206
 
 
 
 
207
 
 
208
 
209
  with gr.Column():
210
  output_image = gr.Image(label="composed output", show_label=True)
211
 
212
  submit_btn.click(
213
+ fn=randomize_seed_fn,
214
+ inputs=[seed, randomize_seed],
215
+ outputs=seed,
216
+ ).then(fn=process_and_display,
217
  inputs=[
218
  base_image,
219
  concept_image1, concept_name1,