File size: 555 Bytes
4ba4a77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import requests
import random
import time

def func2(text):
    filter = False
    API_URL = "https://api-inference.huggingface.co/models/Abderrahim2/bert-finetuned-gender_classification"
    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