Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,6 @@ def call_api(negative_prompt, positive_prompt, api_key):
|
|
25 |
# Check if the request was successful
|
26 |
if response.status_code == 200:
|
27 |
data = response.json()['result'][0]['data']
|
28 |
-
format = response.json()['result'][0]['format']
|
29 |
|
30 |
# Decode the base64 string to bytes
|
31 |
image_data = base64.b64decode(data)
|
@@ -33,7 +32,13 @@ def call_api(negative_prompt, positive_prompt, api_key):
|
|
33 |
# Convert bytes data to an image
|
34 |
image = Image.open(BytesIO(image_data))
|
35 |
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
else:
|
38 |
return "Failed to fetch the image. Please check the API key and inputs."
|
39 |
|
|
|
25 |
# Check if the request was successful
|
26 |
if response.status_code == 200:
|
27 |
data = response.json()['result'][0]['data']
|
|
|
28 |
|
29 |
# Decode the base64 string to bytes
|
30 |
image_data = base64.b64decode(data)
|
|
|
32 |
# Convert bytes data to an image
|
33 |
image = Image.open(BytesIO(image_data))
|
34 |
|
35 |
+
# Save the image as PNG to a buffer
|
36 |
+
buffer = BytesIO()
|
37 |
+
image.save(buffer, format="PNG")
|
38 |
+
|
39 |
+
# Return the buffer content to display it directly in the interface
|
40 |
+
buffer.seek(0)
|
41 |
+
return buffer
|
42 |
else:
|
43 |
return "Failed to fetch the image. Please check the API key and inputs."
|
44 |
|