API call

#258
by rjsilvario - opened

I need help with the API call to generate the image in a 16:9 aspect ratio. Even pasting the JSON below (following the documentation), the image is always generated in a 1:1 ratio (1024x1024). I appreciate your help.

{
inputs: "Astronaut riding a horse",
parameters: {
negative_prompt: "blurry",
target_size: {
width: 1280,
height: 720
},
},
}

API Documentation: https://huggingface.co/docs/api-inference/tasks/text-to-image?code=python#api-specification

Python code used:

import requests
import uuid
import os

API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
headers = {"Authorization": "Bearer hf_XXXXXXXXXXXXXX"}

def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.content

image_bytes = query({
"inputs": "Astronaut riding a horse", "parameters": { "negative_prompt": "blurry", "target_size": {"width": 1280, "height": 720}, },
})

if not os.path.exists('images'):
os.makedirs('images')

uuid_name = str(uuid.uuid4()) + '.jpg'

with open(os.path.join('images', uuid_name), 'wb') as f:
f.write(image_bytes)

print(f'Image saved in: images/{uuid_name}')

Sign up or log in to comment