Inference API usage
#4
by
robertwolf
- opened
I am trying to use the inference API and I can't seem to add the 'question' in the inputs for the API, would anyone know how to do it?
This is my current script. It does return a caption, but it does not seem to take into account the text input.
import base64
import json
import requests
API_URL = "https://api-inference.huggingface.co/models/Salesforce/blip2-opt-2.7b"
headers = {"Authorization": f"Bearer {'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'}"}
json_request = {
"inputs": "How could someone get out of the house?",
"parameters":
{
"max_new_tokens": 100
},
"options":
{"wait_for_model": True}
}
def query(filename):
with open(filename, "rb") as f:
data = f.read()
json_request['image'] = base64.b64encode(data).decode('utf-8')
response = requests.request("POST", API_URL, headers=headers, json=json_request)
return json.loads(response.content.decode("utf-8"))
data = query("house.jpg")
print(data)
Hi,
For the moment BLIP and BLIP-2 are only supported by the image-to-text pipeline, and this pipeline doesn't support a text prompt for the moment.
Will discuss this with the team, thanks for bringing it up!