Created
September 16, 2021 08:47
-
-
Save simoninithomas/8498539a7961f65978f7c84d6cd877fa to your computer and use it in GitHub Desktop.
HuggingFace API Part 2
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
public IEnumerator HFScore(string prompt) | |
{ | |
... | |
// Make the web request | |
UnityWebRequest request = UnityWebRequest.Put(model_url, bytes); | |
request.SetRequestHeader("Content-Type", "application/json"); | |
request.SetRequestHeader("Authorization", "Bearer " + hf_api_key); | |
request.method = "POST"; // Hack to send POST to server instead of PUT | |
yield return request.SendWebRequest(); | |
// If the request return an error set the error on console. | |
if (request.isNetworkError || request.isHttpError) | |
{ | |
Debug.Log(request.error); | |
Debug.Log(request.downloadHandler.data); | |
yield return request.error; | |
} | |
else | |
{ | |
JSONNode data = request.downloadHandler.text; | |
// Process the result | |
yield return ProcessResult(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment