Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,22 +26,27 @@ def generate_kindle_cover(prompt):
|
|
| 26 |
|
| 27 |
if response.status_code == 200:
|
| 28 |
response_body = response.json()
|
| 29 |
-
print("Response Body:", response_body) # Debugging line
|
| 30 |
-
|
| 31 |
-
#
|
| 32 |
-
image_data = response_body.get('image_base64') # Replace 'image_base64'
|
| 33 |
if image_data:
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
if image_url:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
return "No image data found in response."
|
| 46 |
else:
|
| 47 |
return f"Error: {response.status_code} - {response.text}"
|
|
|
|
| 26 |
|
| 27 |
if response.status_code == 200:
|
| 28 |
response_body = response.json()
|
| 29 |
+
print("Response Body:", response_body) # Debugging line to inspect the response
|
| 30 |
+
|
| 31 |
+
# Adjust based on actual response structure
|
| 32 |
+
image_data = response_body.get('image_base64') # Replace 'image_base64' if necessary
|
| 33 |
if image_data:
|
| 34 |
+
try:
|
| 35 |
+
image_bytes = base64.b64decode(image_data)
|
| 36 |
+
image = Image.open(BytesIO(image_bytes))
|
| 37 |
+
return image
|
| 38 |
+
except Exception as e:
|
| 39 |
+
return f"Error decoding base64 image: {e}"
|
| 40 |
+
|
| 41 |
+
image_url = response_body.get('image_url') # Replace 'image_url' if necessary
|
| 42 |
if image_url:
|
| 43 |
+
try:
|
| 44 |
+
image_response = requests.get(image_url)
|
| 45 |
+
image = Image.open(BytesIO(image_response.content))
|
| 46 |
+
return image
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f"Error loading image from URL: {e}"
|
| 49 |
+
|
| 50 |
return "No image data found in response."
|
| 51 |
else:
|
| 52 |
return f"Error: {response.status_code} - {response.text}"
|