Created
July 26, 2021 17:32
-
-
Save feconroses/302474ddd3f3c466dc069ecf16bb09d7 to your computer and use it in GitHub Desktop.
Add Zero-shot classification to Google Sheets using HuggingFace's API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ANALYZE(input, labels, repo_id="facebook/bart-large-mnli") { | |
endpoint = "https://api-inference.huggingface.co/models/" + repo_id; | |
const payload = JSON.stringify({ | |
"inputs": input, | |
"parameters": {"candidate_labels": labels}}); | |
// Add your token from https://huggingface.co/settings/token | |
const options = { | |
"headers": {"Authorization": "Bearer <YOUR HUGGINGFACE API KEY>"}, | |
"wait_for_model": true, | |
"use_gpu": false, | |
"method" : "POST", | |
"contentType" : "application/json", | |
"payload" : payload, | |
}; | |
const response = UrlFetchApp.fetch(endpoint, options); | |
const data = JSON.parse(response.getContentText()); | |
return data['labels'][0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment