Views
No views yet
image-captioning task on 🤗Inference endpoint.custom task for image-captioning for 🤗 Inference Endpoints. The code for the customized pipeline is in the pipeline.py.
To use deploy this model a an Inference Endpoint you have to select Custom as task to use the pipeline.py file. -> double check if it is selected1{
2 "image": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgICAgMC....", // base64 image as bytes
3}requests.!wget https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg1import json
2from typing import List
3import requests as r
4import base64
5
6ENDPOINT_URL = ""
7HF_TOKEN = ""
8
9def predict(path_to_image: str = None):
10 with open(path_to_image, "rb") as i:
11 image = i.read()
12 payload = {
13 "inputs": [image],
14 "parameters": {
15 "do_sample": True,
16 "top_p":0.9,
17 "min_length":5,
18 "max_length":20
19 }
20 }
21 response = r.post(
22 ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json=payload
23 )
24 return response.json()
25prediction = predict(
26 path_to_image="palace.jpg"
27)
28 "parameters": {
"num_beams":5,
"max_length":20
} "parameters": {
"num_beams":1,
"max_length":20,
"do_sample": True,
"top_k":50,
"top_p":0.95
} "parameters": {
"penalty_alpha":0.6,
"top_k":4
"max_length":512
}['buckingham palace with flower beds and red flowers']