wenjiao commited on
Commit
32a5d3a
1 Parent(s): 627c09f
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -23,6 +23,16 @@ url = f"http://{myip}:{myport}"
23
 
24
  queue_size = 0
25
 
 
 
 
 
 
 
 
 
 
 
26
  def set_msg():
27
  global queue_size
28
  if queue_size > int(os.environ["max_queue_size"]):
@@ -30,12 +40,6 @@ def set_msg():
30
  else:
31
  return "The current traffic is not high. You can submit your job now."
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
 
@@ -64,11 +68,11 @@ def img2img_generate(source_img, prompt, steps=25, strength=0.75, seed=42, guida
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
 
@@ -100,7 +104,7 @@ def txt2img_generate(prompt, steps=25, seed=42, guidance_scale=7.5):
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!
@@ -134,9 +138,7 @@ with gr.Blocks(css=css) as demo:
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
- textBoxOrange.change(displayTextBox, outputs = [textBoxGreen, textBoxOrange])
140
 
141
  with gr.Tab("Text-to-Image"):
142
  with gr.Row(visible=True) as text_to_image:
@@ -168,7 +170,7 @@ with gr.Blocks(css=css) as demo:
168
 
169
  txt2img_button.click(fn=txt2img_generate, inputs=[prompt, inference_steps, seed, guidance_scale], outputs=[result_image])
170
 
171
- img2img_button.click(fn=img2img_generate, inputs=[source_img, prompt_2, inference_steps_2, strength, seed_2, guidance_scale_2], outputs=[result_image_2])
172
 
173
  gr.Markdown("**Additional Test Configuration Details:**", elem_id='mdStyle')
174
  gr.Markdown(details, elem_id='mdStyle')
@@ -176,4 +178,4 @@ with gr.Blocks(css=css) as demo:
176
  gr.Markdown("**Notices and Disclaimers:**", elem_id='mdStyle')
177
  gr.Markdown(legal, elem_id='mdStyle')
178
 
179
- demo.queue(max_size=int(os.environ["max_job_size"]), concurrency_count=int(os.environ["max_job_size"])).launch(debug=True, show_api=False)
 
23
 
24
  queue_size = 0
25
 
26
+ def displayTextBox():
27
+ global queue_size
28
+ if queue_size > 4:
29
+ # return [gr.update(visible=False), gr.update(visible=True)]
30
+ return gr.update(elem_id='txtOrangeStyle')
31
+ # elif queue_size <= 4:
32
+ # # return [gr.update(visible=True), gr.update(visible=False)]
33
+ # return gr.update(elem_id='txtGreenStyle')
34
+
35
+
36
  def set_msg():
37
  global queue_size
38
  if queue_size > int(os.environ["max_queue_size"]):
 
40
  else:
41
  return "The current traffic is not high. You can submit your job now."
42
 
 
 
 
 
 
 
43
 
44
  def img2img_generate(source_img, prompt, steps=25, strength=0.75, seed=42, guidance_scale=7.5):
45
 
 
68
  except:
69
  print('No inference result. Please check server connection')
70
  return None
71
+
72
  img_byte = base64.b64decode(img_str)
73
  img_io = BytesIO(img_byte) # convert image to file-like object
74
  img = Image.open(img_io) # img is now PIL Image object
75
  print("elapsed time: ", time.time() - start_time)
 
76
  return img
77
 
78
 
 
104
  print("elapsed time: ", time.time() - start_time)
105
 
106
  return img
107
+
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!
 
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
+ textBoxGreen.change(displayTextBox, outputs = [textBoxGreen])
 
 
142
 
143
  with gr.Tab("Text-to-Image"):
144
  with gr.Row(visible=True) as text_to_image:
 
170
 
171
  txt2img_button.click(fn=txt2img_generate, inputs=[prompt, inference_steps, seed, guidance_scale], outputs=[result_image])
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)
174
 
175
  gr.Markdown("**Additional Test Configuration Details:**", elem_id='mdStyle')
176
  gr.Markdown(details, elem_id='mdStyle')
 
178
  gr.Markdown("**Notices and Disclaimers:**", elem_id='mdStyle')
179
  gr.Markdown(legal, elem_id='mdStyle')
180
 
181
+ demo.queue(max_size=int(os.environ["max_job_size"]), concurrency_count=int(os.environ["max_job_size"])).launch(debug=True, show_api=False)