Merge branch 'abidlabs/external' of github.com:gradio-app/gradio into abidlabs/external

This commit is contained in:
Abubakar Abid 2021-05-07 12:33:18 -04:00
commit 5b29059481

View File

@ -5,9 +5,10 @@ from gradio import inputs, outputs
def get_huggingface_interface(model_name, api_key, alias):
api_url = "https://api-inference.huggingface.co/models/{}".format(model_name)
headers = {"Authorization": f"Bearer {api_key}"}
# Checking if model exists, and if so, it gets the pipeline
response = requests.request("GET", api_url)
response = requests.request("GET", api_url, headers=headers)
assert response.status_code == 200, "Invalid model name or src"
p = response.json().get('pipeline_tag')
@ -79,7 +80,7 @@ def get_huggingface_interface(model_name, api_key, alias):
payload = pipeline['preprocess'](*input)
payload.update({'options': {'wait_for_model': True}})
data = json.dumps(payload)
response = requests.request("POST", api_url, data=data)
response = requests.request("POST", api_url, headers=headers, data=data)
result = json.loads(response.content.decode("utf-8"))
output = pipeline['postprocess'](result)
return output