ysharma HF staff commited on
Commit
1c557bb
·
1 Parent(s): 3f7cd03
Files changed (1) hide show
  1. gradio_seg2image.py +19 -14
gradio_seg2image.py CHANGED
@@ -26,10 +26,13 @@ def encode(img_array):
26
  #print(encoded_string)
27
  return encoded_string
28
 
29
- def create_imgcomp(input_image, filename):
30
- encoded_string = encode(input_image)
 
 
31
  #dummyfun(result_gallery)
32
- htmltag = '<img src= "data:image/jpeg;base64,' + encoded_string + '" alt="Original Image"/></div> <img src= "https://ysharma-controlnet-image-comparison.hf.space/file=' + filename + '" alt="Control Net Image"/>'
 
33
  #https://ysharma-controlnetsegmentation.hf.space/file=/tmp/tmpqcz9yeta.png
34
  #https://ysharma-controlnet-image-comparison.hf.space/file=/tmp/tmpg4qx22xy.png
35
  print(f"htmltag is ^^ - {htmltag}")
@@ -155,23 +158,25 @@ def create_demo(process, max_images=12):
155
  'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
156
  )
157
  with gr.Column():
158
- result_gallery = gr.Gallery(label='Output', visible= False,
159
- show_label=False,
160
- elem_id='gallery').style(
161
- grid=2, height='auto')
162
- b1 = gr.Button('Get filenames')
163
- filename = gr.Textbox(label="image file names", visible=False)
164
- b2 = gr.Button('Show Image-Comparison')
165
- imagecomp = gr.HTML()
 
 
166
  ips = [
167
- input_image, prompt, a_prompt, n_prompt, num_samples,
168
  image_resolution, detect_resolution, ddim_steps, scale, seed, eta
169
  ]
170
  run_button.click(fn=process,
171
  inputs=ips,
172
- outputs=[result_gallery, imagecomp],
173
  api_name='seg')
174
- #b1.click(dummyfun, [result_gallery], [filename])
175
  #b2.click(create_imgcomp, [input_image, filename], [imagecomp])
176
 
177
  return demo
 
26
  #print(encoded_string)
27
  return encoded_string
28
 
29
+ def create_imgcomp(input_image, result_image): #(input_image, filename):
30
+ encoded_string_in = encode(input_image)
31
+ encoded_string_out = encode(result_image)
32
+
33
  #dummyfun(result_gallery)
34
+ htmltag = '<img src= "data:image/jpeg;base64,' + encoded_string_in + '" alt="Original Image"/></div> <img src= "data:image/jpeg;base64,' + encoded_string_out + '" alt="Control Net Image"/>'
35
+ #htmltag = '<img src= "data:image/jpeg;base64,' + encoded_string + '" alt="Original Image"/></div> <img src= "https://ysharma-controlnet-image-comparison.hf.space/file=' + filename + '" alt="Control Net Image"/>'
36
  #https://ysharma-controlnetsegmentation.hf.space/file=/tmp/tmpqcz9yeta.png
37
  #https://ysharma-controlnet-image-comparison.hf.space/file=/tmp/tmpg4qx22xy.png
38
  print(f"htmltag is ^^ - {htmltag}")
 
158
  'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
159
  )
160
  with gr.Column():
161
+ #result_gallery = gr.Gallery(label='Output', visible= False,
162
+ # show_label=False,
163
+ # elem_id='gallery').style(
164
+ # grid=2, height='auto')
165
+ result_image = gr.Image(visible=False).style(height='auto', type='numpy')
166
+ #b1 = gr.Button('Get filenames')
167
+ #filename = gr.Textbox(label="image file names", visible=False)
168
+ #b2 = gr.Button('Show Image-Comparison')
169
+ with gr.Box():
170
+ imagecomp = gr.HTML()
171
  ips = [
172
+ input_image, prompt, a_prompt, n_prompt, num_sampls,
173
  image_resolution, detect_resolution, ddim_steps, scale, seed, eta
174
  ]
175
  run_button.click(fn=process,
176
  inputs=ips,
177
+ outputs=[result_image], #[result_gallery, imagecomp],
178
  api_name='seg')
179
+ result_image.change(create_imgcomp, [input_image, result_image], [imagecomp])
180
  #b2.click(create_imgcomp, [input_image, filename], [imagecomp])
181
 
182
  return demo