Created
July 20, 2021 18:42
-
-
Save nateraw/2a746ee168311eb4d3e64cedc2629f69 to your computer and use it in GitHub Desktop.
Add Translation to Google Sheets using HuggingFace's API
This file contains hidden or 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 TRANSLATE(text, repo_id="Helsinki-NLP/opus-mt-en-es") { | |
endpoint = "https://api-inference.huggingface.co/pipeline/translation/" + repo_id; | |
const payload = JSON.stringify({ | |
"inputs": text | |
}); | |
// 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[0]['translation_text']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
35