Spaces:
Runtime error
Runtime error
File size: 789 Bytes
237f83b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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'
))
|