Update backend/dalle_api.py
Browse files- backend/dalle_api.py +27 -22
backend/dalle_api.py
CHANGED
@@ -1,30 +1,35 @@
|
|
1 |
import openai
|
2 |
import os
|
3 |
from dotenv import load_dotenv
|
4 |
-
from messages import krishna_blessings
|
5 |
-
from ayush_messages import ayush_surprises
|
6 |
|
7 |
load_dotenv()
|
8 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
9 |
|
10 |
-
def
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
"
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
1 |
import openai
|
2 |
import os
|
3 |
from dotenv import load_dotenv
|
|
|
|
|
4 |
|
5 |
load_dotenv()
|
6 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
|
8 |
+
def generate_krishna_image(prompt, size="512x512"):
|
9 |
+
try:
|
10 |
+
response = openai.Image.create(
|
11 |
+
prompt=f"{prompt}, vibrant colors, cartoon style, Little Krishna theme with peacock feathers and Vrindavan background",
|
12 |
+
n=1,
|
13 |
+
size=size
|
14 |
+
)
|
15 |
+
image_url = response['data'][0]['url']
|
16 |
+
return image_url
|
17 |
+
except Exception as e:
|
18 |
+
print(f"Error generating image: {str(e)}")
|
19 |
+
return None
|
20 |
|
21 |
+
def generate_comic_strip():
|
22 |
+
panels = [
|
23 |
+
"Little Krishna seeing a shy girl reading alone in Vrindavan",
|
24 |
+
"Little Krishna appearing with a playful smile, holding a flute",
|
25 |
+
"Little Krishna handing the girl a book, surrounded by cows",
|
26 |
+
"Little Krishna and the girl smiling together, with peacocks dancing"
|
27 |
+
]
|
28 |
+
comic_images = []
|
29 |
+
for panel_prompt in panels:
|
30 |
+
image_url = generate_krishna_image(panel_prompt)
|
31 |
+
if image_url:
|
32 |
+
comic_images.append(image_url)
|
33 |
+
else:
|
34 |
+
comic_images.append("https://via.placeholder.com/512x512.png?text=Error+Generating+Image")
|
35 |
+
return comic_images
|