Skip to content

Instantly share code, notes, and snippets.

@simoninithomas
Created September 16, 2021 08:47
Show Gist options
  • Save simoninithomas/8498539a7961f65978f7c84d6cd877fa to your computer and use it in GitHub Desktop.
Save simoninithomas/8498539a7961f65978f7c84d6cd877fa to your computer and use it in GitHub Desktop.
HuggingFace API Part 2
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