Skip to content

Commit

Permalink
com.rest.huggingface 1.0.0-preview.13 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson authored Dec 15, 2023
1 parent 2e340d3 commit cdb6a65
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions Runtime/Inference/Audio/AudioToAudio/AudioToAudioResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public AudioToAudioResponse(string content, JsonSerializerSettings settings)
public IReadOnlyList<AudioToAudioResult> Results { get; }

/// <inheritdoc />
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);
Expand Down Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions Runtime/Inference/Audio/TextToSpeech/TextToSpeechResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion Runtime/Inference/B64JsonInferenceTaskResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion Runtime/Inference/BinaryInferenceTaskResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public ImageSegmentationResponse(string content, JsonSerializerSettings settings

public IReadOnlyList<ImageSegmentationResult> 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);
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions Runtime/Inference/InferenceEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async Task<Response> CallEndpointAsync()

if (jsonResponse is B64JsonInferenceTaskResponse b64JsonInferenceTaskResponse)
{
await b64JsonInferenceTaskResponse.DecodeAsync(cancellationToken);
await b64JsonInferenceTaskResponse.DecodeAsync(EnableDebug, cancellationToken);
}

return jsonResponse;
Expand All @@ -141,7 +141,7 @@ async Task<Response> CallEndpointAsync()

try
{
await taskResponse.DecodeAsync(contentStream, cancellationToken);
await taskResponse.DecodeAsync(contentStream, EnableDebug, cancellationToken);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,14 +30,14 @@ public TextGenerationParameters(
/// (Default: None). Integer to define the top tokens considered within the sample operation to create new text.
/// </summary>
[JsonProperty("top_k")]
public int? TopK { get; set; }
public float? TopK { get; set; }

/// <summary>
/// (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.
/// </summary>
[JsonProperty("top_p")]
public int? TopP { get; set; }
public float? TopP { get; set; }

/// <summary>
/// (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation.
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestFixture_03_Inference_Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task Test_01_AutomaticSpeechRecognitionTask()
var audioPath = AssetDatabase.GUIDToAssetPath("900a512d644c38c47846d9a6e41961f6");
var audioClip = AssetDatabase.LoadAssetAtPath<AudioClip>(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<AutomaticSpeechRecognitionTask, AutomaticSpeechRecognitionResponse>(task);
Assert.IsNotNull(response);
Assert.IsFalse(string.IsNullOrWhiteSpace(response.Result));
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestFixture_05_Inference_ComputerVision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task Test_04_ImageToImage()
var texture = AssetDatabase.LoadAssetAtPath<Texture2D>(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<ImageToImageTask, ImageToImageResponse>(task);
Assert.IsNotNull(response);
Assert.IsNotNull(response.Image);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down

0 comments on commit cdb6a65

Please sign in to comment.