mentorship-project / text2image.py
IshmamF's picture
Update text2image.py
1090b30 verified
raw
history blame
774 Bytes
import requests
import os
import json
STABLE_API = os.getenv("STABLE_API")
def generate_image(prompt):
url = "https://stablediffusionapi.com/api/v3/text2img"
payload = json.dumps({
"key": STABLE_API,
"prompt": prompt,
"negative_prompt": None,
"width": "512",
"height": "512",
"samples": "1",
"num_inference_steps": "20",
"seed": None,
"guidance_scale": 7.5,
"safety_checker": "yes",
"multi_lingual": "no",
"panorama": "no",
"self_attention": "no",
"upscale": "no",
"embeddings_model": None,
"webhook": None,
"track_id": None
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
return response.json()["output"][0]