TrendFlow / inference_hf /_inference.py
Adapting's picture
inference api
237f83b
raw
history blame
789 Bytes
import json
import requests
from typing import Union,List
class InferenceHF:
headers = {"Authorization": f"Bearer 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"}
API_URL = "https://api-inference.huggingface.co/models/"
@classmethod
def inference(cls, inputs: Union[List[str], str], model_name:str) ->dict:
payload = dict(
inputs = inputs,
options = dict(
wait_for_model=True
)
)
data = json.dumps(payload)
response = requests.request("POST", cls.API_URL+model_name, headers=cls.headers, data=data)
return json.loads(response.content.decode("utf-8"))
if __name__ == '__main__':
print(InferenceHF.inference(
inputs='hi how are you?',
model_name= 't5-small'
))