Commit ·
de1f3eb
1
Parent(s): f5f8dd8
Create new file
Browse files
README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- feature-extraction
|
| 4 |
+
- endpoints-template
|
| 5 |
+
license: bsd-3-clause
|
| 6 |
+
library_name: generic
|
| 7 |
+
---
|
| 8 |
+
# Fork of [salesforce/BLIP](https://github.com/salesforce/BLIP) for a `feature-extraction` task on 🤗Inference endpoint.
|
| 9 |
+
This repository implements a `custom` task for `feature-extraction` for 🤗 Inference Endpoints. The code for the customized pipeline is in the [pipeline.py](https://huggingface.co/florentgbelidji/blip-embeddings/blob/main/pipeline.py).
|
| 10 |
+
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_
|
| 11 |
+
### expected Request payload
|
| 12 |
+
```json
|
| 13 |
+
{
|
| 14 |
+
"image": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgICAgMC....", // base64 image as bytes
|
| 15 |
+
}
|
| 16 |
+
```
|
| 17 |
+
below is an example on how to run a request using Python and `requests`.
|
| 18 |
+
## Run Request
|
| 19 |
+
1. prepare an image.
|
| 20 |
+
```bash
|
| 21 |
+
!wget https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg
|
| 22 |
+
```
|
| 23 |
+
2.run request
|
| 24 |
+
```python
|
| 25 |
+
import json
|
| 26 |
+
from typing import List
|
| 27 |
+
import requests as r
|
| 28 |
+
import base64
|
| 29 |
+
ENDPOINT_URL = ""
|
| 30 |
+
HF_TOKEN = ""
|
| 31 |
+
def predict(path_to_image: str = None):
|
| 32 |
+
with open(path_to_image, "rb") as i:
|
| 33 |
+
b64 = base64.b64encode(i.read())
|
| 34 |
+
payload = {"inputs": {"image": b64.decode("utf-8")}}
|
| 35 |
+
response = r.post(
|
| 36 |
+
ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json=payload
|
| 37 |
+
)
|
| 38 |
+
return response.json()
|
| 39 |
+
prediction = predict(
|
| 40 |
+
path_to_image="palace.jpg"
|
| 41 |
+
)
|
| 42 |
+
```
|
| 43 |
+
expected output
|
| 44 |
+
```python
|
| 45 |
+
{'feature_vector': [0.016450975090265274,
|
| 46 |
+
-0.5551009774208069,
|
| 47 |
+
0.39800673723220825,
|
| 48 |
+
-0.6809228658676147,
|
| 49 |
+
2.053842782974243,
|
| 50 |
+
-0.4712907075881958,...]
|
| 51 |
+
}
|
| 52 |
+
```
|