Examples

#131
by goodasdgood - opened

Examples with hugginface api
code1
#!pip install pillow # Install Pillow if not already installed

import requests
from PIL import Image
from io import BytesIO
from IPython.display import display

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

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

image_bytes = query({"inputs": "ship in the sea"})

Decode and display the image

image = Image.open(BytesIO(image_bytes))
display(image)

code2
!curl https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev
-X POST
-d '{"inputs": "Astronaut riding a horse"}'
-H 'Content-Type: application/json'
-H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
-o image.png # Changed '-output' to '-o' and removed indent

Sign up or log in to comment