generated from RageAgainstThePixel/upm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
com.rest.huggingface 1.0.0-preview.11 (#9)
- added support for custom inference endpoints - added TextToImageB64Response - changed how we name cached items
- Loading branch information
1 parent
fad50a2
commit 87d6b06
Showing
22 changed files
with
183 additions
and
26 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
HuggingFace/Packages/com.rest.huggingface/Runtime/HuggingFaceAuthInfo.cs
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
2 changes: 2 additions & 0 deletions
2
HuggingFace/Packages/com.rest.huggingface/Runtime/HuggingFaceAuthentication.cs
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
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
2 changes: 2 additions & 0 deletions
2
HuggingFace/Packages/com.rest.huggingface/Runtime/HuggingFaceClient.cs
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
2 changes: 2 additions & 0 deletions
2
HuggingFace/Packages/com.rest.huggingface/Runtime/HuggingFaceSettings.cs
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
2 changes: 2 additions & 0 deletions
2
HuggingFace/Packages/com.rest.huggingface/Runtime/HuggingFaceSettingsInfo.cs
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
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
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
4 changes: 3 additions & 1 deletion
4
HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/B64JsonInferenceTaskResponse.cs
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
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
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
18 changes: 18 additions & 0 deletions
18
HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/B64ImageResult.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace HuggingFace.Inference.Multimodal | ||
{ | ||
public sealed class B64ImageResult | ||
{ | ||
[JsonConstructor] | ||
public B64ImageResult([JsonProperty("image")] string blob) | ||
{ | ||
Blob = blob; | ||
} | ||
|
||
[JsonProperty("image")] | ||
public string Blob { get; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/B64ImageResult.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
...s/com.rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageB64Response.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using Newtonsoft.Json; | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
using Utilities.WebRequestRest; | ||
|
||
namespace HuggingFace.Inference.Multimodal.TextToImage | ||
{ | ||
public sealed class TextToImageB64Response : B64JsonInferenceTaskResponse | ||
{ | ||
public TextToImageB64Response(string content, JsonSerializerSettings settings) : base(content, settings) | ||
{ | ||
Result = JsonConvert.DeserializeObject<B64ImageResult>(content, settings); | ||
} | ||
|
||
public B64ImageResult Result { get; private set; } | ||
|
||
public string CachedPath { get; private set; } | ||
|
||
public Texture2D Image { get; private set; } | ||
|
||
public override async Task DecodeAsync(CancellationToken cancellationToken = default) | ||
{ | ||
await Rest.ValidateCacheDirectoryAsync(); | ||
var localFilePath = Path.Combine(Rest.DownloadCacheDirectory, $"{DateTime.UtcNow:yyyy-MM-ddTHH-mm-ssffff}.jpg"); | ||
CachedPath = localFilePath; | ||
var fileStream = new FileStream(localFilePath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None); | ||
|
||
try | ||
{ | ||
await fileStream.WriteAsync(Convert.FromBase64String(Result.Blob), cancellationToken); | ||
await fileStream.FlushAsync(cancellationToken); | ||
} | ||
catch (Exception e) | ||
{ | ||
switch (e) | ||
{ | ||
case TaskCanceledException: | ||
case OperationCanceledException: | ||
throw; | ||
default: | ||
Debug.LogError(e); | ||
throw; | ||
} | ||
} | ||
finally | ||
{ | ||
fileStream.Close(); | ||
await fileStream.DisposeAsync(); | ||
} | ||
|
||
Image = await Rest.DownloadTextureAsync($"file://{localFilePath}", parameters: null, cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
....rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageB64Response.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
m_EditorVersion: 2021.3.24f1 | ||
m_EditorVersionWithRevision: 2021.3.24f1 (cf10dcf7010d) | ||
m_EditorVersion: 2022.3.7f1 | ||
m_EditorVersionWithRevision: 2022.3.7f1 (b16b3b16c7a0) |
Empty file.