Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,23 +3,30 @@ import requests
|
|
| 3 |
import base64
|
| 4 |
|
| 5 |
def generate_comic(short_story):
|
| 6 |
-
# Split the story into sentences for image generation
|
| 7 |
sentences = short_story.split('. ')
|
| 8 |
-
|
| 9 |
images = []
|
|
|
|
| 10 |
for sentence in sentences:
|
| 11 |
-
if sentence.strip():
|
| 12 |
response = requests.post(
|
| 13 |
"https://api.deepai.org/api/text2img",
|
| 14 |
data={'text': sentence},
|
| 15 |
headers={'api-key': 'ff1119f6-955f-4ead-8e32-3b4c7f4b020c'}
|
| 16 |
)
|
|
|
|
|
|
|
|
|
|
| 17 |
image_url = response.json().get('output_url')
|
| 18 |
if image_url:
|
|
|
|
|
|
|
| 19 |
# Convert image to base64
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Create comic HTML
|
| 25 |
comic_html = '<div style="display: flex; flex-direction: column;">'
|
|
|
|
| 3 |
import base64
|
| 4 |
|
| 5 |
def generate_comic(short_story):
|
|
|
|
| 6 |
sentences = short_story.split('. ')
|
|
|
|
| 7 |
images = []
|
| 8 |
+
|
| 9 |
for sentence in sentences:
|
| 10 |
+
if sentence.strip():
|
| 11 |
response = requests.post(
|
| 12 |
"https://api.deepai.org/api/text2img",
|
| 13 |
data={'text': sentence},
|
| 14 |
headers={'api-key': 'ff1119f6-955f-4ead-8e32-3b4c7f4b020c'}
|
| 15 |
)
|
| 16 |
+
# Print the response for debugging
|
| 17 |
+
print("API Response:", response.json())
|
| 18 |
+
|
| 19 |
image_url = response.json().get('output_url')
|
| 20 |
if image_url:
|
| 21 |
+
print("Generated Image URL:", image_url) # Debugging URL
|
| 22 |
+
|
| 23 |
# Convert image to base64
|
| 24 |
+
try:
|
| 25 |
+
image_data = requests.get(image_url).content
|
| 26 |
+
base64_image = base64.b64encode(image_data).decode('utf-8')
|
| 27 |
+
images.append(f"data:image/png;base64,{base64_image}")
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"Error fetching image: {e}")
|
| 30 |
|
| 31 |
# Create comic HTML
|
| 32 |
comic_html = '<div style="display: flex; flex-direction: column;">'
|