DALL-E Bird Images from Text

KOSTENLOS
Durch OpenedAI | Aktualisiert a month ago | Video, Images
Popularität

0.3 / 10

Latenz

60ms

Service Level

0%

Health Check

N/A

Zurück zu allen Tutorials (1)

Calling the API & loading base64 in Python

Here is an example for correctly calling the API in Python:

import json
import requests
import base64

url = "https://dall-e-bird-images-from-text.p.rapidapi.com/generate"

text = "a crystal blue bird with a black head"

payload = {"text": text}
payload = json.dumps(payload)
headers = {
'x-rapidapi-host': "dall-e-bird-images-from-text.p.rapidapi.com",
'x-rapidapi-key': "YOURKEY",
‘content-type': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers)

b64img = json.loads(response.text)["base64img"]

imgdata = base64.b64decode(b64img)
filename = 'dalle-crystal-bird.jpg'
with open(filename, 'wb') as f:
	f.write(imgdata)