Views
No views yet
multimodal-multilanguage-embedding Inference endpoint.custom task for multimodal-multilanguage-embedding for 🤗 Inference Endpoints. The code for the customized handler is in the handler.py.Custom as task to use the handler.py file.1import json
2from typing import List
3import requests as r
4import base64
5
6ENDPOINT_URL = "endpoint_url"
7HF_TOKEN = "token_key"
8
9def predict(path_to_image: str = None, text : str = None):
10 with open(path_to_image, "rb") as i:
11 b64 = base64.b64encode(i.read())
12
13 payload = {"inputs":
14 {
15 "image": b64.decode("utf-8"),
16 "text": text
17 }
18 }
19
20 response = r.post(
21 ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json=payload
22 )
23 return response.json()
24
25
26prediction = predict(
27 path_to_image="image/accidentdevoiture.webp", text="An image of a cat and a remote control"
28)
29
30print(json.dumps(prediction, indent=2))1{
2 "text_embedding": [-0.009289545938372612,
3 -0.03686045855283737,
4 ...
5 0.038627129048109055,
6 -0.01346363127231597]
7 "image_embedding": [-0.009289545938372612,
8 -0.03686045855283737,
9 ...
10 0.038627129048109055,
11 -0.01346363127231597]
12}