JRQi's picture
Duplicate from GroNLP/LM-Explanation-Demo
4ba4a77
raw
history blame contribute delete
555 Bytes
import requests
import random
import time
def func2(text):
filter = False
API_URL = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2FAbderrahim2%2Fbert-finetuned-gender_classification%26quot%3B%3C%2Fspan%3E%3C!-- HTML_TAG_END -->
headers = {"Authorization": "Bearer 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"}
response = requests.post(API_URL, headers=headers, json=text)
output = response.json()
result = dict()
for out in output[0]:
label = out['label']
if label == 'undefined' and filter: continue
result[label] = out['score']
return result