Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,36 +13,31 @@ import base64
|
|
| 13 |
from io import BytesIO
|
| 14 |
from PIL import Image
|
| 15 |
|
| 16 |
-
|
| 17 |
url_SPR = "http://34.229.166.42:80"
|
| 18 |
url_ICX = "http://54.221.56.4:80"
|
| 19 |
|
| 20 |
print('=='*20)
|
| 21 |
print(os.system("hostname -i"))
|
| 22 |
|
| 23 |
-
|
|
|
|
| 24 |
resp = requests.post(url, data=json.dumps(data))
|
| 25 |
img_str = json.loads(resp.text)["img_str"]
|
| 26 |
|
| 27 |
img_byte = base64.b64decode(img_str)
|
| 28 |
img_io = BytesIO(img_byte) # convert image to file-like object
|
| 29 |
img = Image.open(img_io) # img is now PIL Image object
|
| 30 |
-
_img = img.resize((sizeImg))
|
| 31 |
-
return _img
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
|
|
|
| 35 |
|
| 36 |
-
def img2img_generate(source_img, prompt, steps=25, strength=0.
|
| 37 |
# cpu info
|
| 38 |
# print(subprocess.check_output(["cat /proc/cpuinfo | grep 'model name' |uniq"], stderr=subprocess.STDOUT).decode("utf8"))
|
| 39 |
print('=*'*20)
|
| 40 |
print(type(source_img))
|
| 41 |
print("prompt: ", prompt)
|
| 42 |
buffered = BytesIO()
|
| 43 |
-
|
| 44 |
source_img.save(buffered, format="JPEG")
|
| 45 |
-
print(source_img.size)
|
| 46 |
img_b64 = base64.b64encode(buffered.getvalue())
|
| 47 |
|
| 48 |
data = {"source_img": img_b64.decode(), "prompt": prompt, "steps": steps,
|
|
@@ -50,41 +45,34 @@ def img2img_generate(source_img, prompt, steps=25, strength=0.25, seed=42, guida
|
|
| 50 |
"token": os.environ["access_token"]}
|
| 51 |
|
| 52 |
start_time = time.time()
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
return img
|
| 57 |
|
| 58 |
|
| 59 |
-
def txt2img_generate(prompt, steps=25, seed=42, guidance_scale=7.5):
|
| 60 |
# cpu info
|
| 61 |
# print(subprocess.check_output(["cat /proc/cpuinfo | grep 'model name' |uniq"], stderr=subprocess.STDOUT).decode("utf8"))
|
| 62 |
print("prompt: ", prompt)
|
| 63 |
print("steps: ", steps)
|
| 64 |
data = {"prompt": prompt,
|
| 65 |
-
"steps": steps, "guidance_scale": guidance_scale, "seed": seed
|
|
|
|
| 66 |
start_time = time.time()
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
md = '''
|
| 75 |
-
'''
|
| 76 |
|
| 77 |
css = '''
|
| 78 |
.instruction{position: absolute; top: 0;right: 0;margin-top: 0px !important}
|
| 79 |
.arrow{position: absolute;top: 0;right: -110px;margin-top: -8px !important}
|
| 80 |
#component-4, #component-3, #component-10{min-height: 0}
|
| 81 |
.duplicate-button img{margin: 0}
|
| 82 |
-
img_1{height:
|
| 83 |
-
img_2{height:15rem}
|
| 84 |
-
img_3{height:15rem}
|
| 85 |
-
img_4{height:15rem}
|
| 86 |
-
img_5{height:15rem}
|
| 87 |
-
img_6{height:15rem}
|
| 88 |
'''
|
| 89 |
|
| 90 |
random_seed = random.randint(0, 2147483647)
|
|
@@ -121,11 +109,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 121 |
url_SPR = gr.Textbox(label='url_SPR', value="http://34.229.166.42:80", visible=False)
|
| 122 |
url_CLX = gr.Textbox(label='url_CLX', value="http://54.221.56.4:80", visible=False)
|
| 123 |
|
| 124 |
-
with gr.Column():
|
| 125 |
-
result_image_3 = gr.Image(label="Result01", elem_id="img_3")
|
| 126 |
-
result_image_4 = gr.Image(label="Result02", elem_id="img_4")
|
| 127 |
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
img2img_button.click(fn=img2img_generate, inputs=[url_SPR, source_img, prompt_2, inference_steps_2, strength, seed_2, guidance_scale_2], outputs=result_image_3, queue=False)
|
| 130 |
img2img_button.click(fn=img2img_generate, inputs=[url_CLX, source_img, prompt_2, inference_steps_2, strength, seed_2, guidance_scale_2], outputs=result_image_4, queue=False)
|
| 131 |
-
|
|
|
|
|
|
| 13 |
from io import BytesIO
|
| 14 |
from PIL import Image
|
| 15 |
|
|
|
|
| 16 |
url_SPR = "http://34.229.166.42:80"
|
| 17 |
url_ICX = "http://54.221.56.4:80"
|
| 18 |
|
| 19 |
print('=='*20)
|
| 20 |
print(os.system("hostname -i"))
|
| 21 |
|
| 22 |
+
|
| 23 |
+
def url_requests(url, data):
|
| 24 |
resp = requests.post(url, data=json.dumps(data))
|
| 25 |
img_str = json.loads(resp.text)["img_str"]
|
| 26 |
|
| 27 |
img_byte = base64.b64decode(img_str)
|
| 28 |
img_io = BytesIO(img_byte) # convert image to file-like object
|
| 29 |
img = Image.open(img_io) # img is now PIL Image object
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
return img
|
| 32 |
|
| 33 |
+
def img2img_generate(url, source_img, prompt, steps=25, strength=0.75, seed=42, guidance_scale=7.5):
|
| 34 |
# cpu info
|
| 35 |
# print(subprocess.check_output(["cat /proc/cpuinfo | grep 'model name' |uniq"], stderr=subprocess.STDOUT).decode("utf8"))
|
| 36 |
print('=*'*20)
|
| 37 |
print(type(source_img))
|
| 38 |
print("prompt: ", prompt)
|
| 39 |
buffered = BytesIO()
|
|
|
|
| 40 |
source_img.save(buffered, format="JPEG")
|
|
|
|
| 41 |
img_b64 = base64.b64encode(buffered.getvalue())
|
| 42 |
|
| 43 |
data = {"source_img": img_b64.decode(), "prompt": prompt, "steps": steps,
|
|
|
|
| 45 |
"token": os.environ["access_token"]}
|
| 46 |
|
| 47 |
start_time = time.time()
|
| 48 |
+
img = url_requests(url, data)
|
| 49 |
+
|
|
|
|
| 50 |
return img
|
| 51 |
|
| 52 |
|
| 53 |
+
def txt2img_generate(url, prompt, steps=25, seed=42, guidance_scale=7.5):
|
| 54 |
# cpu info
|
| 55 |
# print(subprocess.check_output(["cat /proc/cpuinfo | grep 'model name' |uniq"], stderr=subprocess.STDOUT).decode("utf8"))
|
| 56 |
print("prompt: ", prompt)
|
| 57 |
print("steps: ", steps)
|
| 58 |
data = {"prompt": prompt,
|
| 59 |
+
"steps": steps, "guidance_scale": guidance_scale, "seed": seed,
|
| 60 |
+
"token": os.environ["access_token"]}
|
| 61 |
start_time = time.time()
|
| 62 |
+
img = url_requests(url, data)
|
| 63 |
+
|
| 64 |
+
return img
|
| 65 |
+
|
| 66 |
+
md = """
|
| 67 |
+
This demo shows the accelerated inference performance of a Stable Diffusion model on **4th Gen Intel Xeon Scalable Processors (Sapphire Rapids)** vs. **3rd Gen Intel Xeon Scalable Processors (Ice Lake)** on Amazon Web Services. Try it and see up to **5x performance speedup** on **4th Gen Intel Xeon**!
|
| 68 |
+
"""
|
|
|
|
|
|
|
| 69 |
|
| 70 |
css = '''
|
| 71 |
.instruction{position: absolute; top: 0;right: 0;margin-top: 0px !important}
|
| 72 |
.arrow{position: absolute;top: 0;right: -110px;margin-top: -8px !important}
|
| 73 |
#component-4, #component-3, #component-10{min-height: 0}
|
| 74 |
.duplicate-button img{margin: 0}
|
| 75 |
+
#img_1, #img_2, #img_3, #img_4{height:15rem}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
'''
|
| 77 |
|
| 78 |
random_seed = random.randint(0, 2147483647)
|
|
|
|
| 109 |
url_SPR = gr.Textbox(label='url_SPR', value="http://34.229.166.42:80", visible=False)
|
| 110 |
url_CLX = gr.Textbox(label='url_CLX', value="http://54.221.56.4:80", visible=False)
|
| 111 |
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
+
with gr.Column():
|
| 114 |
+
result_image_3 = gr.Image(label="4th Gen Intel Xeon Scalable Processors (SPR)", elem_id="img_3")
|
| 115 |
+
result_image_4 = gr.Image(label="3rd Gen Intel Xeon Scalable Processors (ICX)", elem_id="img_4")
|
| 116 |
+
|
| 117 |
+
txt2img_button.click(fn=txt2img_generate, inputs=[url_SPR_txt, prompt, inference_steps, seed, guidance_scale], outputs=result_image_1, queue=False)
|
| 118 |
+
txt2img_button.click(fn=txt2img_generate, inputs=[url_CLX_txt, prompt, inference_steps, seed, guidance_scale], outputs=result_image_2, queue=False)
|
| 119 |
img2img_button.click(fn=img2img_generate, inputs=[url_SPR, source_img, prompt_2, inference_steps_2, strength, seed_2, guidance_scale_2], outputs=result_image_3, queue=False)
|
| 120 |
img2img_button.click(fn=img2img_generate, inputs=[url_CLX, source_img, prompt_2, inference_steps_2, strength, seed_2, guidance_scale_2], outputs=result_image_4, queue=False)
|
| 121 |
+
|
| 122 |
+
demo.queue(default_enabled=False).launch(debug=True)
|