Spaces:
Build error
Build error
PatrickSchrML
commited on
Commit
·
17c2a9a
1
Parent(s):
4bb6455
fix base64
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ from io import BytesIO
|
|
10 |
import os
|
11 |
import requests
|
12 |
import json
|
|
|
13 |
# from urllib import parse
|
14 |
|
15 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
@@ -45,7 +46,12 @@ def infer(prompt, n_samples, steps, scale, seed):
|
|
45 |
data = json.load(BytesIO(response.content))
|
46 |
print(data)
|
47 |
for image in data['output']['choices']:
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
49 |
images.append(image_b64)
|
50 |
|
51 |
# payload = {'prompt': prompt}
|
|
|
10 |
import os
|
11 |
import requests
|
12 |
import json
|
13 |
+
import base64
|
14 |
# from urllib import parse
|
15 |
|
16 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
|
|
46 |
data = json.load(BytesIO(response.content))
|
47 |
print(data)
|
48 |
for image in data['output']['choices']:
|
49 |
+
im = Image.open(BytesIO(base64.b64decode(image['image_base64'])))
|
50 |
+
im_file = BytesIO()
|
51 |
+
im.save(im_file, format="JPEG")
|
52 |
+
im_bytes = im_file.getvalue() # im_bytes: image in binary format.
|
53 |
+
im_b64 = base64.b64encode(im_bytes)
|
54 |
+
image_b64 = (f"data:image/jpeg;base64,{im_b64}")
|
55 |
images.append(image_b64)
|
56 |
|
57 |
# payload = {'prompt': prompt}
|