wenjiao commited on
Commit
69dd450
1 Parent(s): dbbe9a7
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -30,6 +30,13 @@ def set_msg():
30
  else:
31
  return ["The current traffic is not high. You can submit your job now.", queue_size]
32
 
 
 
 
 
 
 
 
33
  def img2img_generate(source_img, prompt, steps=25, strength=0.75, seed=42, guidance_scale=7.5):
34
 
35
  print('image-to-image')
@@ -56,17 +63,13 @@ def img2img_generate(source_img, prompt, steps=25, strength=0.75, seed=42, guida
56
  print("Compute node: ", json.loads(resp.text)["ip"])
57
  except:
58
  print('No inference result. Please check server connection')
59
- return [None, gr.update(visible=True), gr.update(visible=False)]
60
-
61
  img_byte = base64.b64decode(img_str)
62
  img_io = BytesIO(img_byte) # convert image to file-like object
63
  img = Image.open(img_io) # img is now PIL Image object
64
  print("elapsed time: ", time.time() - start_time)
65
 
66
- if queue_size > 4:
67
- return [img, gr.update(visible=False), gr.update(visible=True)]
68
- elif queue_size <= 4:
69
- return [img, gr.update(visible=True), gr.update(visible=False)]
70
 
71
 
72
  def txt2img_generate(prompt, steps=25, seed=42, guidance_scale=7.5):
@@ -89,20 +92,15 @@ def txt2img_generate(prompt, steps=25, seed=42, guidance_scale=7.5):
89
  print("Compute node: ", json.loads(resp.text)["ip"])
90
  except:
91
  print('No inference result. Please check server connection')
92
- return [None, gr.update(visible=True), gr.update(visible=False)]
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
-
100
- if queue_size > 4:
101
- return [img, gr.update(visible=False), gr.update(visible=True)]
102
- elif queue_size <= 4:
103
- return [img, gr.update(visible=True), gr.update(visible=False)]
104
-
105
-
106
 
107
  md = """
108
  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!
@@ -135,10 +133,9 @@ with gr.Blocks(css=css) as demo:
135
  gr.Markdown("# Stable Diffusion Inference Demo on 4th Gen Intel Xeon Scalable Processors")
136
  gr.Markdown(md)
137
 
138
- queueText = gr.Text()
139
- textBoxGreen = gr.Textbox(set_msg, every=3, label='Real-time Jobs in Queue', elem_id='txtGreenStyle', visible=True, outputs=[queueText])
140
- textBoxOrange = gr.Textbox(set_msg, every=3, label='Real-time Jobs in Queue', elem_id='txtOrangeStyle', visible=False, outputs=[queueText])
141
- queueText = gr.Text(queue_size)
142
 
143
  with gr.Tab("Text-to-Image"):
144
  with gr.Row(visible=True) as text_to_image:
@@ -168,9 +165,9 @@ with gr.Blocks(css=css) as demo:
168
  with gr.Column():
169
  result_image_2 = gr.Image()
170
 
171
- txt2img_button.click(fn=txt2img_generate, inputs=[prompt, inference_steps, seed, guidance_scale], outputs=[result_image, textBoxGreen, textBoxOrange])
172
 
173
- 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])
174
 
175
  gr.Markdown("**Additional Test Configuration Details:**", elem_id='mdStyle')
176
  gr.Markdown(details, elem_id='mdStyle')
 
30
  else:
31
  return ["The current traffic is not high. You can submit your job now.", queue_size]
32
 
33
+ def displayTextBox():
34
+ global queue_size
35
+ if queue_size > 4:
36
+ return [gr.update(visible=False), gr.update(visible=True)]
37
+ elif queue_size <= 4:
38
+ return [gr.update(visible=True), gr.update(visible=False)]
39
+
40
  def img2img_generate(source_img, prompt, steps=25, strength=0.75, seed=42, guidance_scale=7.5):
41
 
42
  print('image-to-image')
 
63
  print("Compute node: ", json.loads(resp.text)["ip"])
64
  except:
65
  print('No inference result. Please check server connection')
66
+ return None
 
67
  img_byte = base64.b64decode(img_str)
68
  img_io = BytesIO(img_byte) # convert image to file-like object
69
  img = Image.open(img_io) # img is now PIL Image object
70
  print("elapsed time: ", time.time() - start_time)
71
 
72
+ return img
 
 
 
73
 
74
 
75
  def txt2img_generate(prompt, steps=25, seed=42, guidance_scale=7.5):
 
92
  print("Compute node: ", json.loads(resp.text)["ip"])
93
  except:
94
  print('No inference result. Please check server connection')
95
+ return None
96
 
97
  img_byte = base64.b64decode(img_str)
98
  img_io = BytesIO(img_byte) # convert image to file-like object
99
  img = Image.open(img_io) # img is now PIL Image object
100
  print("elapsed time: ", time.time() - start_time)
101
 
102
+ return img
103
+
 
 
 
 
 
104
 
105
  md = """
106
  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!
 
133
  gr.Markdown("# Stable Diffusion Inference Demo on 4th Gen Intel Xeon Scalable Processors")
134
  gr.Markdown(md)
135
 
136
+ textBoxGreen = gr.Textbox(set_msg, every=3, label='Real-time Jobs in Queue', elem_id='txtGreenStyle', visible=True)
137
+ textBoxOrange = gr.Textbox(set_msg, every=3, label='Real-time Jobs in Queue', elem_id='txtOrangeStyle', visible=False)
138
+ textBoxGreen.change(displayTextBox, outputs = [textBoxGreen, textBoxOrange])
 
139
 
140
  with gr.Tab("Text-to-Image"):
141
  with gr.Row(visible=True) as text_to_image:
 
165
  with gr.Column():
166
  result_image_2 = gr.Image()
167
 
168
+ txt2img_button.click(fn=txt2img_generate, inputs=[prompt, inference_steps, seed, guidance_scale], outputs=[result_image])
169
 
170
+ img2img_button.click(fn=img2img_generate, inputs=[source_img, prompt_2, inference_steps_2, strength, seed_2, guidance_scale_2], outputs=[result_image_2])
171
 
172
  gr.Markdown("**Additional Test Configuration Details:**", elem_id='mdStyle')
173
  gr.Markdown(details, elem_id='mdStyle')