wenjiao commited on
Commit
4970ac1
1 Parent(s): 3a285d8
Files changed (1) hide show
  1. app.py +6 -16
app.py CHANGED
@@ -90,22 +90,15 @@ def txt2img_generate(prompt, steps=25, seed=42, guidance_scale=7.5):
90
  except:
91
  print('No inference result. Please check server connection')
92
  return None
93
- # return [None, gr.update(visible=True), gr.update(visible=False)]
94
 
95
  img_byte = base64.b64decode(img_str)
96
  img_io = BytesIO(img_byte) # convert image to file-like object
97
  img = Image.open(img_io) # img is now PIL Image object
98
  print("elapsed time: ", time.time() - start_time)
99
 
100
- # if queue_size.isdigit():
101
- # if int(queue_size) > 4:
102
- # return [img, gr.update(visible=False), gr.update(visible=True)]
103
- # elif int(queue_size) <= 4:
104
- # return [img, gr.update(visible=True), gr.update(visible=False)]
105
- # else:
106
- # return [img, gr.update(visible=True), gr.update(visible=False)]
107
  return img
108
 
 
109
  md = """
110
  This demo shows the accelerated inference performance of a Stable Diffusion model on **Intel Xeon Gold 64xx (4th Gen Intel Xeon Scalable Processors codenamed Sapphire Rapids)**. Try it and generate photorealistic images from text! Please note that the demo is in **preview** under limited HW resources. We are committed to continue improving the demo and happy to hear your feedbacks. Thanks for your trying!
111
  You may also want to try creating your own Stable Diffusion with few-shot fine-tuning. Please refer to our <a href=\"https://medium.com/intel-analytics-software/personalized-stable-diffusion-with-few-shot-fine-tuning-on-a-single-cpu-f01a3316b13\">blog</a> and <a href=\"https://github.com/intel/neural-compressor/tree/master/examples/pytorch/diffusion_model/diffusers/textual_inversion\">code</a> available in <a href=\"https://github.com/intel/neural-compressor\">**Intel Neural Compressor**</a> and <a href=\"https://github.com/huggingface/diffusers\">**Hugging Face Diffusers**</a>.
@@ -127,8 +120,8 @@ css = '''
127
  .duplicate-button img{margin: 0}
128
  #mdStyle{font-size: 0.6rem}
129
  .generating.svelte-1w9161c { border: none }
130
- #txtGreenStyle {border: 2px solid #32ec48;}
131
- #txtOrangeStyle {border: 2px solid #e77718;}
132
  '''
133
 
134
  random_seed = random.randint(0, 2147483647)
@@ -137,8 +130,7 @@ with gr.Blocks(css=css) as demo:
137
  gr.Markdown("# Stable Diffusion Inference Demo on 4th Gen Intel Xeon Scalable Processors")
138
  gr.Markdown(md)
139
 
140
- textBoxGreen = gr.Textbox(set_msg, every=3, label='Real-time Jobs in Queue', elem_id='txtGreenStyle', visible=True)
141
- textBoxOrange = gr.Textbox(set_msg, every=3, label='Real-time Jobs in Queue', elem_id='txtOrangeStyle', visible=False)
142
 
143
  with gr.Tab("Text-to-Image"):
144
  with gr.Row(visible=True) as text_to_image:
@@ -169,10 +161,8 @@ with gr.Blocks(css=css) as demo:
169
  result_image_2 = gr.Image()
170
 
171
  txt2img_button.click(fn=txt2img_generate, inputs=[prompt, inference_steps, seed, guidance_scale], outputs=[result_image])
172
- # txt2img_button.click(fn=txt2img_generate, inputs=[prompt, inference_steps, seed, guidance_scale], outputs=[result_image, textBoxGreen, textBoxOrange])
173
 
174
- img2img_button.click(fn=img2img_generate, inputs=[source_img, prompt_2, inference_steps_2, strength, seed_2, guidance_scale_2], outputs=[result_image_2])
175
- # img2img_button.click(fn=img2img_generate, inputs=[source_img, prompt_2, inference_steps_2, strength, seed_2, guidance_scale_2], outputs=[result_image_2, textBoxGreen, textBoxOrange])
176
 
177
  gr.Markdown("**Additional Test Configuration Details:**", elem_id='mdStyle')
178
  gr.Markdown(details, elem_id='mdStyle')
@@ -180,4 +170,4 @@ with gr.Blocks(css=css) as demo:
180
  gr.Markdown("**Notices and Disclaimers:**", elem_id='mdStyle')
181
  gr.Markdown(legal, elem_id='mdStyle')
182
 
183
- demo.queue(max_size=int(os.environ["max_job_size"]), concurrency_count=int(os.environ["max_job_size"])).launch(debug=True, show_api=False)
 
90
  except:
91
  print('No inference result. Please check server connection')
92
  return None
 
93
 
94
  img_byte = base64.b64decode(img_str)
95
  img_io = BytesIO(img_byte) # convert image to file-like object
96
  img = Image.open(img_io) # img is now PIL Image object
97
  print("elapsed time: ", time.time() - start_time)
98
 
 
 
 
 
 
 
 
99
  return img
100
 
101
+
102
  md = """
103
  This demo shows the accelerated inference performance of a Stable Diffusion model on **Intel Xeon Gold 64xx (4th Gen Intel Xeon Scalable Processors codenamed Sapphire Rapids)**. Try it and generate photorealistic images from text! Please note that the demo is in **preview** under limited HW resources. We are committed to continue improving the demo and happy to hear your feedbacks. Thanks for your trying!
104
  You may also want to try creating your own Stable Diffusion with few-shot fine-tuning. Please refer to our <a href=\"https://medium.com/intel-analytics-software/personalized-stable-diffusion-with-few-shot-fine-tuning-on-a-single-cpu-f01a3316b13\">blog</a> and <a href=\"https://github.com/intel/neural-compressor/tree/master/examples/pytorch/diffusion_model/diffusers/textual_inversion\">code</a> available in <a href=\"https://github.com/intel/neural-compressor\">**Intel Neural Compressor**</a> and <a href=\"https://github.com/huggingface/diffusers\">**Hugging Face Diffusers**</a>.
 
120
  .duplicate-button img{margin: 0}
121
  #mdStyle{font-size: 0.6rem}
122
  .generating.svelte-1w9161c { border: none }
123
+ #txtGreenStyle {2px solid #32ec48;}
124
+ #txtOrangeStyle {2px solid #e77718;}
125
  '''
126
 
127
  random_seed = random.randint(0, 2147483647)
 
130
  gr.Markdown("# Stable Diffusion Inference Demo on 4th Gen Intel Xeon Scalable Processors")
131
  gr.Markdown(md)
132
 
133
+ gr.Textbox(set_msg, every=3, label='Real-time Jobs in Queue', elem_id='txtOrangeStyle')
 
134
 
135
  with gr.Tab("Text-to-Image"):
136
  with gr.Row(visible=True) as text_to_image:
 
161
  result_image_2 = gr.Image()
162
 
163
  txt2img_button.click(fn=txt2img_generate, inputs=[prompt, inference_steps, seed, guidance_scale], outputs=[result_image])
 
164
 
165
+ img2img_button.click(fn=img2img_generate, inputs=[source_img, prompt_2, inference_steps_2, strength, seed_2, guidance_scale_2], outputs=result_image_2)
 
166
 
167
  gr.Markdown("**Additional Test Configuration Details:**", elem_id='mdStyle')
168
  gr.Markdown(details, elem_id='mdStyle')
 
170
  gr.Markdown("**Notices and Disclaimers:**", elem_id='mdStyle')
171
  gr.Markdown(legal, elem_id='mdStyle')
172
 
173
+ demo.queue(max_size=int(os.environ["max_job_size"]), concurrency_count=int(os.environ["max_job_size"])).launch(debug=True, show_api=False)