philschmid HF staff commited on
Commit
ccb995f
1 Parent(s): f3126f3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +46 -1
README.md CHANGED
@@ -2,6 +2,51 @@
2
  tags:
3
  - image-to-text
4
  - image-captioning
 
5
  license: bsd-3-clause
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- ---
 
2
  tags:
3
  - image-to-text
4
  - image-captioning
5
+ - endpoints-template
6
  license: bsd-3-clause
7
+ library_name: generic
8
+ ---
9
+
10
+ # Blip Caption 🤗 Inference Endpoints
11
+
12
+ This repository implements a `custom` task for `image-captioning` for 🤗 Inference Endpoints. The code for the customized pipeline is in the [pipeline.py](https://huggingface.co/florentgbelidji/blip_captioning/blob/main/pipeline.py).
13
+ 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 selected_
14
+ ### expected Request payload
15
+ ```json
16
+ {
17
+ "image": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgICAgMC....", // base64 image as bytes
18
+ }
19
+ ```
20
+ below is an example on how to run a request using Python and `requests`.
21
+ ## Run Request
22
+ 1. prepare an image.
23
+ ```bash
24
+ !wget https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg
25
+ ```
26
+ 2. run request
27
+ ```python
28
+ import json
29
+ from typing import List
30
+ import requests as r
31
+ import base64
32
+
33
+ ENDPOINT_URL = ""
34
+ HF_TOKEN = ""
35
+
36
+ def predict(path_to_image: str = None):
37
+ with open(path_to_image, "rb") as i:
38
+ b64 = base64.b64encode(i.read())
39
+ payload = {"inputs": {"image": b64.decode("utf-8"), "candiates": candiates}}
40
+ response = r.post(
41
+ ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json=payload
42
+ )
43
+ return response.json()
44
+ prediction = predict(
45
+ path_to_image="palace.jpg"
46
+ )
47
+ ```
48
+ expected output
49
+ ```python
50
+ ['buckingham palace with flower beds and red flowers']
51
 
52
+ ```