From 7f4b5eea09dfa3b951f12657144e0cc6eeccda3a Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Thu, 14 Dec 2023 20:46:42 -0500 Subject: [PATCH] com.rest.huggingface 1.0.0-preview.13 (#12) --- .../Inference/Audio/AudioToAudio/AudioToAudioResponse.cs | 8 ++++---- .../Inference/Audio/TextToSpeech/TextToSpeechResponse.cs | 4 ++-- .../Runtime/Inference/B64JsonInferenceTaskResponse.cs | 2 +- .../Runtime/Inference/BinaryInferenceTaskResponse.cs | 2 +- .../ImageSegmentation/ImageSegmentationResponse.cs | 8 ++++---- .../ComputerVision/ImageToImage/ImageToImageResponse.cs | 4 ++-- .../Runtime/Inference/InferenceEndpoint.cs | 4 ++-- .../Multimodal/TextToImage/TextToImageB64Response.cs | 4 ++-- .../Multimodal/TextToImage/TextToImageBinaryResponse.cs | 4 ++-- .../TextGeneration/TextGenerationParameters.cs | 8 ++++---- .../Tests/TestFixture_03_Inference_Audio.cs | 2 +- .../Tests/TestFixture_05_Inference_ComputerVision.cs | 2 +- HuggingFace/Packages/com.rest.huggingface/package.json | 4 ++-- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Audio/AudioToAudio/AudioToAudioResponse.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Audio/AudioToAudio/AudioToAudioResponse.cs index 5c63e78..2e36401 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Audio/AudioToAudio/AudioToAudioResponse.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Audio/AudioToAudio/AudioToAudioResponse.cs @@ -24,10 +24,10 @@ public AudioToAudioResponse(string content, JsonSerializerSettings settings) public IReadOnlyList Results { get; } /// - public override async Task DecodeAsync(CancellationToken cancellationToken = default) - => await Task.WhenAll(Results.Select(result => DecodeAudioAsync(result, cancellationToken)).ToList()); + public override async Task DecodeAsync(bool debug = false, CancellationToken cancellationToken = default) + => await Task.WhenAll(Results.Select(result => DecodeAudioAsync(result, debug, cancellationToken)).ToList()); - private static async Task DecodeAudioAsync(AudioToAudioResult result, CancellationToken cancellationToken) + private static async Task DecodeAudioAsync(AudioToAudioResult result, bool debug = false, CancellationToken cancellationToken = default) { await Rest.ValidateCacheDirectoryAsync(); Rest.TryGetDownloadCacheItem(result.Blob, out var guid); @@ -57,7 +57,7 @@ private static async Task DecodeAudioAsync(AudioToAudioResult result, Cancellati await fileStream.DisposeAsync(); } - result.AudioClip = await Rest.DownloadAudioClipAsync($"file://{localFilePath}", AudioType.MPEG, parameters: null, cancellationToken: cancellationToken); + result.AudioClip = await Rest.DownloadAudioClipAsync($"file://{localFilePath}", AudioType.MPEG, debug: debug, cancellationToken: cancellationToken); } } } diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Audio/TextToSpeech/TextToSpeechResponse.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Audio/TextToSpeech/TextToSpeechResponse.cs index 72bc473..43fa9fd 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Audio/TextToSpeech/TextToSpeechResponse.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Audio/TextToSpeech/TextToSpeechResponse.cs @@ -15,7 +15,7 @@ public sealed class TextToSpeechResponse : BinaryInferenceTaskResponse public AudioClip AudioClip { get; private set; } - public override async Task DecodeAsync(Stream stream, CancellationToken cancellationToken = default) + public override async Task DecodeAsync(Stream stream, bool debug = false, CancellationToken cancellationToken = default) { await Rest.ValidateCacheDirectoryAsync(); var filePath = Path.Combine(Rest.DownloadCacheDirectory, $"{DateTime.UtcNow:yyyy-MM-ddTHH-mm-ssffff}.mp3"); @@ -46,7 +46,7 @@ public override async Task DecodeAsync(Stream stream, CancellationToken cancella await fileStream.DisposeAsync(); } - AudioClip = await Rest.DownloadAudioClipAsync($"file://{filePath}", AudioType.MPEG, parameters: null, cancellationToken: cancellationToken); + AudioClip = await Rest.DownloadAudioClipAsync($"file://{filePath}", AudioType.MPEG, debug: debug, cancellationToken: cancellationToken); } } } diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/B64JsonInferenceTaskResponse.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/B64JsonInferenceTaskResponse.cs index 7b18719..adf3506 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/B64JsonInferenceTaskResponse.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/B64JsonInferenceTaskResponse.cs @@ -13,6 +13,6 @@ protected B64JsonInferenceTaskResponse(string content, JsonSerializerSettings se { } - public abstract Task DecodeAsync(CancellationToken cancellationToken = default); + public abstract Task DecodeAsync(bool debug = false, CancellationToken cancellationToken = default); } } diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/BinaryInferenceTaskResponse.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/BinaryInferenceTaskResponse.cs index 45fa827..6998608 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/BinaryInferenceTaskResponse.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/BinaryInferenceTaskResponse.cs @@ -8,6 +8,6 @@ namespace HuggingFace.Inference { public abstract class BinaryInferenceTaskResponse : InferenceTaskResponse { - public abstract Task DecodeAsync(Stream stream, CancellationToken cancellationToken = default); + public abstract Task DecodeAsync(Stream stream, bool debug = false, CancellationToken cancellationToken = default); } } diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/ComputerVision/ImageSegmentation/ImageSegmentationResponse.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/ComputerVision/ImageSegmentation/ImageSegmentationResponse.cs index a87cf56..6f186e9 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/ComputerVision/ImageSegmentation/ImageSegmentationResponse.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/ComputerVision/ImageSegmentation/ImageSegmentationResponse.cs @@ -21,10 +21,10 @@ public ImageSegmentationResponse(string content, JsonSerializerSettings settings public IReadOnlyList Results { get; } - public override async Task DecodeAsync(CancellationToken cancellationToken = default) - => await Task.WhenAll(Results.Select(result => DecodeImageAsync(result, cancellationToken)).ToList()); + public override async Task DecodeAsync(bool debug = false, CancellationToken cancellationToken = default) + => await Task.WhenAll(Results.Select(result => DecodeImageAsync(result, debug, cancellationToken)).ToList()); - private static async Task DecodeImageAsync(ImageSegmentationResult result, CancellationToken cancellationToken) + private static async Task DecodeImageAsync(ImageSegmentationResult result, bool debug = false, CancellationToken cancellationToken = default) { await Rest.ValidateCacheDirectoryAsync(); Rest.TryGetDownloadCacheItem(result.Blob, out var guid); @@ -54,7 +54,7 @@ private static async Task DecodeImageAsync(ImageSegmentationResult result, Cance await fileStream.DisposeAsync(); } - result.Mask = await Rest.DownloadTextureAsync($"file://{localFilePath}", parameters: null, cancellationToken: cancellationToken); + result.Mask = await Rest.DownloadTextureAsync($"file://{localFilePath}", debug: debug, cancellationToken: cancellationToken); } } } diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/ComputerVision/ImageToImage/ImageToImageResponse.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/ComputerVision/ImageToImage/ImageToImageResponse.cs index 5862935..1bf812b 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/ComputerVision/ImageToImage/ImageToImageResponse.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/ComputerVision/ImageToImage/ImageToImageResponse.cs @@ -15,7 +15,7 @@ public sealed class ImageToImageResponse : BinaryInferenceTaskResponse public Texture2D Image { get; private set; } - public override async Task DecodeAsync(Stream stream, CancellationToken cancellationToken = default) + public override async Task DecodeAsync(Stream stream, bool debug = false, CancellationToken cancellationToken = default) { await Rest.ValidateCacheDirectoryAsync(); var filePath = Path.Combine(Rest.DownloadCacheDirectory, $"{DateTime.UtcNow:yyyy-MM-ddTHH-mm-ssffff}.jpg"); @@ -46,7 +46,7 @@ public override async Task DecodeAsync(Stream stream, CancellationToken cancella await fileStream.DisposeAsync(); } - Image = await Rest.DownloadTextureAsync($"file://{filePath}", parameters: null, cancellationToken: cancellationToken); + Image = await Rest.DownloadTextureAsync($"file://{filePath}", debug: debug, cancellationToken: cancellationToken); } } } diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/InferenceEndpoint.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/InferenceEndpoint.cs index b242a45..5153ec2 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/InferenceEndpoint.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/InferenceEndpoint.cs @@ -120,7 +120,7 @@ async Task CallEndpointAsync() if (jsonResponse is B64JsonInferenceTaskResponse b64JsonInferenceTaskResponse) { - await b64JsonInferenceTaskResponse.DecodeAsync(cancellationToken); + await b64JsonInferenceTaskResponse.DecodeAsync(EnableDebug, cancellationToken); } return jsonResponse; @@ -141,7 +141,7 @@ async Task CallEndpointAsync() try { - await taskResponse.DecodeAsync(contentStream, cancellationToken); + await taskResponse.DecodeAsync(contentStream, EnableDebug, cancellationToken); } finally { diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageB64Response.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageB64Response.cs index 6d13b1e..9d09600 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageB64Response.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageB64Response.cs @@ -23,7 +23,7 @@ public TextToImageB64Response(string content, JsonSerializerSettings settings) : public Texture2D Image { get; private set; } - public override async Task DecodeAsync(CancellationToken cancellationToken = default) + public override async Task DecodeAsync(bool debug = false, CancellationToken cancellationToken = default) { await Rest.ValidateCacheDirectoryAsync(); var localFilePath = Path.Combine(Rest.DownloadCacheDirectory, $"{DateTime.UtcNow:yyyy-MM-ddTHH-mm-ssffff}.jpg"); @@ -53,7 +53,7 @@ public override async Task DecodeAsync(CancellationToken cancellationToken = def await fileStream.DisposeAsync(); } - Image = await Rest.DownloadTextureAsync($"file://{localFilePath}", parameters: null, cancellationToken: cancellationToken); + Image = await Rest.DownloadTextureAsync($"file://{localFilePath}", debug: debug, cancellationToken: cancellationToken); } } } diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageBinaryResponse.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageBinaryResponse.cs index 34670c9..da3c599 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageBinaryResponse.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/Multimodal/TextToImage/TextToImageBinaryResponse.cs @@ -15,7 +15,7 @@ public sealed class TextToImageBinaryResponse : BinaryInferenceTaskResponse public Texture2D Image { get; private set; } - public override async Task DecodeAsync(Stream stream, CancellationToken cancellationToken = default) + public override async Task DecodeAsync(Stream stream, bool debug, CancellationToken cancellationToken = default) { await Rest.ValidateCacheDirectoryAsync(); var localFilePath = Path.Combine(Rest.DownloadCacheDirectory, $"{DateTime.UtcNow:yyyy-MM-ddTHH-mm-ssffff}.jpg"); @@ -45,7 +45,7 @@ public override async Task DecodeAsync(Stream stream, CancellationToken cancella await fileStream.DisposeAsync(); } - Image = await Rest.DownloadTextureAsync($"file://{localFilePath}", parameters: null, cancellationToken: cancellationToken); + Image = await Rest.DownloadTextureAsync($"file://{localFilePath}", debug: debug, cancellationToken: cancellationToken); } } } diff --git a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/NaturalLanguageProcessing/TextGeneration/TextGenerationParameters.cs b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/NaturalLanguageProcessing/TextGeneration/TextGenerationParameters.cs index a29cf1c..a674fa4 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/NaturalLanguageProcessing/TextGeneration/TextGenerationParameters.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Runtime/Inference/NaturalLanguageProcessing/TextGeneration/TextGenerationParameters.cs @@ -5,8 +5,8 @@ namespace HuggingFace.Inference.NaturalLanguageProcessing.TextGeneration public sealed class TextGenerationParameters { public TextGenerationParameters( - [JsonProperty("top_k")] int? topK = null, - [JsonProperty("top_p")] int? topP = null, + [JsonProperty("top_k")] float? topK = null, + [JsonProperty("top_p")] float? topP = null, [JsonProperty("temperature")] float? temperature = null, [JsonProperty("repetition_penalty")] float? repetitionPenalty = null, [JsonProperty("max_new_tokens")] int? maxTokens = null, @@ -30,14 +30,14 @@ public TextGenerationParameters( /// (Default: None). Integer to define the top tokens considered within the sample operation to create new text. /// [JsonProperty("top_k")] - public int? TopK { get; set; } + public float? TopK { get; set; } /// /// (Default: None). Float to define the tokens that are within the sample operation of text generation. /// Add tokens in the sample for more probable to least probable until the sum of the probabilities is greater than top_p. /// [JsonProperty("top_p")] - public int? TopP { get; set; } + public float? TopP { get; set; } /// /// (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation. diff --git a/HuggingFace/Packages/com.rest.huggingface/Tests/TestFixture_03_Inference_Audio.cs b/HuggingFace/Packages/com.rest.huggingface/Tests/TestFixture_03_Inference_Audio.cs index 65baf41..3b4b892 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Tests/TestFixture_03_Inference_Audio.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Tests/TestFixture_03_Inference_Audio.cs @@ -26,7 +26,7 @@ public async Task Test_01_AutomaticSpeechRecognitionTask() var audioPath = AssetDatabase.GUIDToAssetPath("900a512d644c38c47846d9a6e41961f6"); var audioClip = AssetDatabase.LoadAssetAtPath(audioPath); using var input = new SingleSourceAudioInput(audioClip); - var task = new AutomaticSpeechRecognitionTask(input); + var task = new AutomaticSpeechRecognitionTask(input, "distil-whisper/distil-large-v2"); var response = await HuggingFaceClient.InferenceEndpoint.RunInferenceTaskAsync(task); Assert.IsNotNull(response); Assert.IsFalse(string.IsNullOrWhiteSpace(response.Result)); diff --git a/HuggingFace/Packages/com.rest.huggingface/Tests/TestFixture_05_Inference_ComputerVision.cs b/HuggingFace/Packages/com.rest.huggingface/Tests/TestFixture_05_Inference_ComputerVision.cs index e5b90d5..bcee78f 100644 --- a/HuggingFace/Packages/com.rest.huggingface/Tests/TestFixture_05_Inference_ComputerVision.cs +++ b/HuggingFace/Packages/com.rest.huggingface/Tests/TestFixture_05_Inference_ComputerVision.cs @@ -81,7 +81,7 @@ public async Task Test_04_ImageToImage() var texture = AssetDatabase.LoadAssetAtPath(imagePath); using var input = new SingleSourceImageInput(texture); var param = new ImageToImageParameters("Girl with Pearl Earring"); - var task = new ImageToImageTask(input, param); + var task = new ImageToImageTask(input, param, "stabilityai/stable-diffusion-xl-refiner-1.0"); var response = await HuggingFaceClient.InferenceEndpoint.RunInferenceTaskAsync(task); Assert.IsNotNull(response); Assert.IsNotNull(response.Image); diff --git a/HuggingFace/Packages/com.rest.huggingface/package.json b/HuggingFace/Packages/com.rest.huggingface/package.json index 4a7dbea..349a141 100644 --- a/HuggingFace/Packages/com.rest.huggingface/package.json +++ b/HuggingFace/Packages/com.rest.huggingface/package.json @@ -3,7 +3,7 @@ "displayName": "HuggingFace", "description": "A Non-Official HuggingFace Rest Client for Unity (UPM)", "keywords": [], - "version": "1.0.0-preview.12", + "version": "1.0.0-preview.13", "unity": "2021.3", "documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.huggingface#documentation", "changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.huggingface/releases", @@ -20,7 +20,7 @@ "registry": "https://package.openupm.com" }, "dependencies": { - "com.utilities.rest": "2.3.1", + "com.utilities.rest": "2.4.0", "com.utilities.encoder.wav": "1.0.8", "com.utilities.encoder.ogg": "3.0.12" },