Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import requests
|
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
from io import BytesIO
|
|
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
# Replace with your NVIDIA API key
|
|
@@ -25,13 +26,23 @@ def generate_kindle_cover(prompt):
|
|
| 25 |
|
| 26 |
if response.status_code == 200:
|
| 27 |
response_body = response.json()
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
if image_url:
|
| 30 |
image_response = requests.get(image_url)
|
| 31 |
image = Image.open(BytesIO(image_response.content))
|
| 32 |
return image
|
| 33 |
-
|
| 34 |
-
|
| 35 |
else:
|
| 36 |
return f"Error: {response.status_code} - {response.text}"
|
| 37 |
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
from io import BytesIO
|
| 5 |
+
import base64
|
| 6 |
import os
|
| 7 |
|
| 8 |
# Replace with your NVIDIA API key
|
|
|
|
| 26 |
|
| 27 |
if response.status_code == 200:
|
| 28 |
response_body = response.json()
|
| 29 |
+
print("Response Body:", response_body) # Debugging line
|
| 30 |
+
|
| 31 |
+
# Check if image is in base64 format
|
| 32 |
+
image_data = response_body.get('image_base64') # Replace 'image_base64' with the actual key if different
|
| 33 |
+
if image_data:
|
| 34 |
+
image_bytes = base64.b64decode(image_data)
|
| 35 |
+
image = Image.open(BytesIO(image_bytes))
|
| 36 |
+
return image
|
| 37 |
+
|
| 38 |
+
# Check if image is returned as a URL
|
| 39 |
+
image_url = response_body.get('image_url') # Replace 'image_url' with the actual key if different
|
| 40 |
if image_url:
|
| 41 |
image_response = requests.get(image_url)
|
| 42 |
image = Image.open(BytesIO(image_response.content))
|
| 43 |
return image
|
| 44 |
+
|
| 45 |
+
return "No image data found in response."
|
| 46 |
else:
|
| 47 |
return f"Error: {response.status_code} - {response.text}"
|
| 48 |
|