huggingface / api-inference-community

Apache License 2.0
161 stars 61 forks source link

Python example fails with json deserialisation error #438

Open janibashamd opened 1 month ago

janibashamd commented 1 month ago

Hi,

Python example provided below is not working image

Check below error: image

Let me know if need anything..

janibashamd commented 1 month ago

Working solution i want to merge is below.. Please check and give me permission so i can raise a PR

`import requests

API_URL = "https://api-inference.huggingface.co/models/gpt2" headers = {"Authorization": f"Bearer {API_TOKEN}"}

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

data = query({"inputs": "Can you please let us know more details about your "}) print(data[0]['generated_text'])`