ayush2917 commited on
Commit
9736b95
·
verified ·
1 Parent(s): f8e3c87

Update backend/dalle_api.py

Browse files
Files changed (1) hide show
  1. 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 get_krishna_response(user_input):
11
- # Check for predefined responses
12
- if "birthday" in user_input.lower():
13
- return ayush_surprises["birthday"]
14
- if "shy" in user_input.lower():
15
- return krishna_blessings["shy"]
16
- if "hello" in user_input.lower() or "hi" in user_input.lower():
17
- return krishna_blessings["greeting"]
 
 
 
 
18
 
19
- # Use OpenAI for dynamic responses
20
- prompt = (
21
- "You are Little Krishna, playful and wise. Respond to this in a fun, Krishna-like way: "
22
- f"'{user_input}'"
23
- )
24
- response = openai.Completion.create(
25
- engine="text-davinci-003",
26
- prompt=prompt,
27
- max_tokens=60,
28
- temperature=0.9
29
- )
30
- return response.choices[0].text.strip()
 
 
 
 
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