montyanderson zenafey commited on
Commit
5ab9639
1 Parent(s): cde996a

Add Image Gallery of generated images(of current session)

Browse files

this will allow to compare images you created while using space :)

![image.png](https://cdn-uploads.huggingface.co/production/uploads/646301de2538819c72a12d00/y96qVSSOH2DxE6FoC_RL1.png)

Co-authored-by: Zenafey Baenro <zenafey@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -159,7 +159,7 @@ for model_name in model_list:
159
  name_without_ext = remove_id_and_ext(model_name)
160
  model_names[name_without_ext] = model_name
161
 
162
- def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed):
163
  result = prodia_client.generate({
164
  "prompt": prompt,
165
  "negative_prompt": negative_prompt,
@@ -174,9 +174,12 @@ def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, he
174
 
175
  job = prodia_client.wait(result)
176
 
177
- return job["imageUrl"]
 
178
 
179
- def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed):
 
 
180
  result = prodia_client.transform({
181
  "imageData": image_to_base64(input_image),
182
  "denoising_strength": denoising,
@@ -193,7 +196,10 @@ def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampl
193
 
194
  job = prodia_client.wait(result)
195
 
196
- return job["imageUrl"]
 
 
 
197
 
198
 
199
  css = """
@@ -288,8 +294,7 @@ with gr.Blocks(css=css) as demo:
288
  with gr.Column(scale=2):
289
  image_output = gr.Image(value="https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png")
290
 
291
- text_button.click(txt2img, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed], outputs=image_output)
292
-
293
  with gr.Tab("img2img", id='i2i'):
294
  with gr.Row():
295
  with gr.Column(scale=6, min_width=600):
@@ -327,8 +332,7 @@ with gr.Blocks(css=css) as demo:
327
  with gr.Column(scale=2):
328
  i2i_image_output = gr.Image(value="https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png")
329
 
330
- i2i_text_button.click(img2img, inputs=[i2i_image_input, i2i_denoising, i2i_prompt, i2i_negative_prompt, model, i2i_steps, i2i_sampler, i2i_cfg_scale, i2i_width, i2i_height, i2i_seed], outputs=i2i_image_output)
331
-
332
  with gr.Tab("PNG Info"):
333
  def plaintext_to_html(text, classname=None):
334
  content = "<br>\n".join(html.escape(x) for x in text.split('\n'))
@@ -361,10 +365,16 @@ with gr.Blocks(css=css) as demo:
361
  with gr.Column():
362
  exif_output = gr.HTML(label="EXIF Data")
363
  send_to_txt2img_btn = gr.Button("Send to txt2img")
364
-
365
- image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
366
- send_to_txt2img_btn.click(send_to_txt2img, inputs=[image_input], outputs=[tabs, prompt, negative_prompt, steps, seed,
 
 
 
 
367
  model, sampler, width, height, cfg_scale])
368
-
 
 
369
  demo.queue(concurrency_count=32)
370
  demo.launch()
 
159
  name_without_ext = remove_id_and_ext(model_name)
160
  model_names[name_without_ext] = model_name
161
 
162
+ def txt2img(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed, gallery):
163
  result = prodia_client.generate({
164
  "prompt": prompt,
165
  "negative_prompt": negative_prompt,
 
174
 
175
  job = prodia_client.wait(result)
176
 
177
+ new_images_list = [img['name'] for img in gallery]
178
+ new_images_list.insert(0, job["imageUrl"])
179
 
180
+ return {image_output: job["imageUrl"], gallery_obj: new_images_list}
181
+
182
+ def img2img(input_image, denoising, prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed, gallery):
183
  result = prodia_client.transform({
184
  "imageData": image_to_base64(input_image),
185
  "denoising_strength": denoising,
 
196
 
197
  job = prodia_client.wait(result)
198
 
199
+ new_images_list = [img['name'] for img in gallery]
200
+ new_images_list.insert(0, job["imageUrl"])
201
+
202
+ return {i2i_image_output: job["imageUrl"], gallery_obj: new_images_list}
203
 
204
 
205
  css = """
 
294
  with gr.Column(scale=2):
295
  image_output = gr.Image(value="https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png")
296
 
297
+
 
298
  with gr.Tab("img2img", id='i2i'):
299
  with gr.Row():
300
  with gr.Column(scale=6, min_width=600):
 
332
  with gr.Column(scale=2):
333
  i2i_image_output = gr.Image(value="https://images.prodia.xyz/8ede1a7c-c0ee-4ded-987d-6ffed35fc477.png")
334
 
335
+
 
336
  with gr.Tab("PNG Info"):
337
  def plaintext_to_html(text, classname=None):
338
  content = "<br>\n".join(html.escape(x) for x in text.split('\n'))
 
365
  with gr.Column():
366
  exif_output = gr.HTML(label="EXIF Data")
367
  send_to_txt2img_btn = gr.Button("Send to txt2img")
368
+
369
+ with gr.Tab("Gallery"):
370
+ gallery_obj = gr.Gallery(height=500, columns=4)
371
+
372
+ text_button.click(txt2img, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed, gallery_obj], outputs=[image_output, gallery_obj])
373
+ image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
374
+ send_to_txt2img_btn.click(send_to_txt2img, inputs=[image_input], outputs=[tabs, prompt, negative_prompt, steps, seed,
375
  model, sampler, width, height, cfg_scale])
376
+ i2i_text_button.click(img2img, inputs=[i2i_image_input, i2i_denoising, i2i_prompt, i2i_negative_prompt, model, i2i_steps, i2i_sampler, i2i_cfg_scale, i2i_width, i2i_height, i2i_seed, gallery_obj], outputs=[i2i_image_output, gallery_obj])
377
+
378
+
379
  demo.queue(concurrency_count=32)
380
  demo.launch()