stable-diffusion/stable_diffusion_api.py

25 lines
660 B
Python

import requests
from dotenv import load_dotenv
from os import getenv
load_dotenv()
response = requests.post(
f'https://api.stability.ai/v2beta/stable-image/generate/sd3',
headers={
'authorization': f'Bearer {getenv("API_KEY")}',
'accept': 'image/*'
},
files={'none': ''},
data={
'prompt': 'Aesthetic pastel magical realism, a man with a retro TV for a head, standing in the center of the desert, vintage photo',
'output_format': 'png',
},
)
if response.status_code == 200:
with open('./test.png', 'wb') as file:
file.write(response.content)
else:
raise Exception(str(response.json()))