File size: 744 Bytes
6507cd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import requests
from urllib.parse import quote

def generate_and_save_image(prompt: str, path: str, width: int = 800, height: int = 800):
    base_url = "https://image.pollinations.ai/prompt/"
    encoded_prompt = quote(prompt)
    url = f"{base_url}{encoded_prompt}?width={width}&height={height}&nologo=true"
    response = requests.get(url)
    if response.status_code == 200:
        with open(path, "wb") as f:
            f.write(response.content)
        print(f"Image saved to {path}")
    else:
        print(f"Failed to generate image. Status code: {response.status_code}")
        print(response.text)

if __name__ == "__main__":
    generate_and_save_image("Anime girl wearing school uniform and pink hair.", "output.png", 512, 512)