File size: 1,890 Bytes
b1c1180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import requests
from dotenv import load_dotenv

load_dotenv()
HUGGINGFACE_API_TOKEN = os.getenv("HUGGINGFACE_API_TOKEN")

def generate_krishna_image(prompt, size="512x512"):
    try:
        headers = {
            "Authorization": f"Bearer {HUGGINGFACE_API_TOKEN}",
            "Content-Type": "application/json"
        }
        payload = {
            "inputs": f"{prompt}, vibrant colors, cartoon style, Little Krishna theme with peacock feathers and Vrindavan background",
            "parameters": {
                "num_inference_steps": 50,
                "guidance_scale": 7.5
            }
        }
        response = requests.post(
            "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5",
            headers=headers,
            json=payload
        )
        if response.status_code == 200:
            with open("temp_image.png", "wb") as f:
                f.write(response.content)
            return "https://via.placeholder.com/512x512.png?text=Stable+Diffusion+Image"
        else:
            print(f"Error generating image: {response.text}")
            return None
    except Exception as e:
        print(f"Error generating image: {str(e)}")
        return None

def generate_comic_strip():
    panels = [
        "Little Krishna seeing a shy girl reading alone in Vrindavan",
        "Little Krishna appearing with a playful smile, holding a flute",
        "Little Krishna handing the girl a book, surrounded by cows",
        "Little Krishna and the girl smiling together, with peacocks dancing"
    ]
    comic_images = []
    for panel_prompt in panels:
        image_url = generate_krishna_image(panel_prompt)
        if image_url:
            comic_images.append(image_url)
        else:
            comic_images.append("https://via.placeholder.com/512x512.png?text=Error+Generating+Image")
    return comic_images