Example Inference API (model & code ), pls

Hello. I am an absolute beginner, and getting started with HF / Inference API. etc.
I am trying to connect to some model and ask basic question. I have created a read access token, and am using following code to connect to gpt2. But I am getting a status code of response to 404 error.

API_TOKEN=“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”
MODEL = “openai-community/gpt2” #tried a few others as well
API_URL = f"https://api-inference.huggingface.co/models/{MODEL}"
headers = { “Authorization”: f"Bearer {API_TOKEN}"}
prompt = “Tell me about Paris.”
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)

Can someone pls help?

1 Like