Skip to content

Commit

Permalink
com.rest.huggingface 1.0.0-preview.8 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson authored Jun 19, 2023
1 parent 5161f27 commit 197a6ff
Show file tree
Hide file tree
Showing 112 changed files with 2,436 additions and 206 deletions.
1 change: 1 addition & 0 deletions Runtime/HuggingFace.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"rootNamespace": "HuggingFace",
"references": [
"GUID:a6609af893242c7438d701ddd4cce46a",
"GUID:f7a0d77b5e1d79742a738fb859ee2f28",
"GUID:7958db66189566541a6363568aee1575"
],
"includePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public sealed class AudioClassificationResponse : JsonInferenceTaskResponse
public AudioClassificationResponse(string content, JsonSerializerSettings settings)
: base(content, settings)
{
Results = JsonConvert.DeserializeObject<IReadOnlyList<AudioClassificationResults>>(content, settings);
Results = JsonConvert.DeserializeObject<IReadOnlyList<ScoreResults>>(content, settings);
}

public IReadOnlyList<AudioClassificationResults> Results { get; }
public IReadOnlyList<ScoreResults> Results { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using HuggingFace.Hub;
using UnityEngine.Scripting;

namespace HuggingFace.Inference.Audio.AudioClassification
{
public sealed class AudioClassificationTask : BaseAudioInferenceTask
{
internal AudioClassificationTask() { }
[Preserve]
public AudioClassificationTask() { }

public AudioClassificationTask(SingleSourceAudioInput input, ModelInfo model = null, InferenceOptions options = null)
: base(input, model, options)
Expand Down
4 changes: 3 additions & 1 deletion Runtime/Inference/Audio/AudioToAudio/AudioToAudioTask.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using HuggingFace.Hub;
using UnityEngine.Scripting;

namespace HuggingFace.Inference.Audio.AudioToAudio
{
public sealed class AudioToAudioTask : BaseAudioInferenceTask
{
internal AudioToAudioTask() { }
[Preserve]
public AudioToAudioTask() { }

public AudioToAudioTask(SingleSourceAudioInput input, ModelInfo model = null, InferenceOptions options = null)
: base(input, model, options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using HuggingFace.Hub;
using UnityEngine.Scripting;

namespace HuggingFace.Inference.Audio.AutomaticSpeechRecognition
{
public sealed class AutomaticSpeechRecognitionTask : BaseAudioInferenceTask
{
internal AutomaticSpeechRecognitionTask() { }
[Preserve]
public AutomaticSpeechRecognitionTask() { }

public AutomaticSpeechRecognitionTask(SingleSourceAudioInput input, ModelInfo model = null, InferenceOptions options = null)
: base(input, model ?? new ModelInfo("jonatasgrosman/wav2vec2-large-xlsr-53-english"), options)
: base(input, model, options)
{
}

Expand Down
18 changes: 0 additions & 18 deletions Runtime/Inference/Audio/HuggingFace.Inference.Audio.asmdef

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using UnityEngine;
using Utilities.WebRequestRest;

namespace HuggingFace.Inference.Audio
namespace HuggingFace.Inference.Audio.TextToSpeech
{
public sealed class TextToSpeechResponse : BinaryInferenceTaskResponse
{
Expand Down
6 changes: 4 additions & 2 deletions Runtime/Inference/Audio/TextToSpeech/TextToSpeechTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

using HuggingFace.Hub;
using Newtonsoft.Json;
using UnityEngine.Scripting;

namespace HuggingFace.Inference.Audio
namespace HuggingFace.Inference.Audio.TextToSpeech
{
public sealed class TextToSpeechTask : BaseJsonPayloadInferenceTask
{
internal TextToSpeechTask() { }
[Preserve]
public TextToSpeechTask() { }

public TextToSpeechTask(string input, ModelInfo model = null, InferenceOptions options = null)
: base(model, options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;
using HuggingFace.Hub;

namespace HuggingFace.Inference.Audio
namespace HuggingFace.Inference
{
public abstract class BaseAudioInferenceTask : InferenceTask
{
Expand All @@ -19,7 +19,7 @@ protected BaseAudioInferenceTask(SingleSourceAudioInput input, ModelInfo model,

public SingleSourceAudioInput Input { get; }

public override async Task<byte[]> ToByteArrayAsync(CancellationToken cancellationToken = default)
public override async Task<byte[]> ToByteArrayAsync(CancellationToken cancellationToken)
{
await using var memoryStream = new MemoryStream();
await Input.Audio.CopyToAsync(memoryStream, cancellationToken);
Expand Down
5 changes: 2 additions & 3 deletions Runtime/Inference/BaseImageInferenceTask.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using HuggingFace.Hub;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using HuggingFace.Hub;
using HuggingFace.Inference.ComputerVision;

namespace HuggingFace.Inference
{
Expand All @@ -20,7 +19,7 @@ protected BaseImageInferenceTask(SingleSourceImageInput input, ModelInfo model,

public SingleSourceImageInput Input { get; }

public override async Task<byte[]> ToByteArrayAsync(CancellationToken cancellationToken = default)
public override async Task<byte[]> ToByteArrayAsync(CancellationToken cancellationToken)
{
await using var memoryStream = new MemoryStream();
await Input.Image.CopyToAsync(memoryStream, cancellationToken);
Expand Down
11 changes: 5 additions & 6 deletions Runtime/Inference/BaseJsonPayloadInferenceTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

using HuggingFace.Hub;
using Newtonsoft.Json;
using System.Threading;
using System.Threading.Tasks;

namespace HuggingFace.Inference
{
public abstract class BaseJsonPayloadInferenceTask : InferenceTask
{
protected BaseJsonPayloadInferenceTask() { }

protected BaseJsonPayloadInferenceTask(ModelInfo model, InferenceOptions options)
: base(model, options)
{
}
protected BaseJsonPayloadInferenceTask(ModelInfo model, InferenceOptions options) : base(model, options) { }

public override string ToJson(JsonSerializerSettings settings)
=> JsonConvert.SerializeObject(this, settings);
public override Task<string> ToJsonAsync(JsonSerializerSettings settings, CancellationToken cancellationToken)
=> Task.FromResult(JsonConvert.SerializeObject(this, settings));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//// Licensed under the MIT License. See LICENSE in the project root for license information.

//using System;
//using System.IO;
//using System.Threading;
//using System.Threading.Tasks;
//using UnityEngine;
//using Utilities.WebRequestRest;

//namespace HuggingFace.Inference.ComputerVision.DepthEstimation
//{
// public sealed class DepthEstimationResult : BinaryInferenceTaskResponse
// {
// public string CachedPath { get; private set; }

// public Texture2D Image { get; private set; }

// public override async Task DecodeAsync(Stream stream, CancellationToken cancellationToken = default)
// {
// await Rest.ValidateCacheDirectoryAsync();
// var filePath = Path.Combine(Rest.DownloadCacheDirectory, $"{DateTime.UtcNow:yyyy-MM-ddTHH-mm-ssffff}.jpg");
// Debug.Log(filePath);
// CachedPath = filePath;
// var fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write, FileShare.None);

// try
// {
// await stream.CopyToAsync(fileStream, cancellationToken);
// await fileStream.FlushAsync(cancellationToken);
// }
// catch (Exception e)
// {
// Debug.LogError(e);
// }
// finally
// {
// fileStream.Close();
// await fileStream.DisposeAsync();
// }

// Image = await Rest.DownloadTextureAsync($"file://{filePath}", parameters: null, cancellationToken: cancellationToken);
// }
// }
//}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
using HuggingFace.Hub;

namespace HuggingFace.Inference.ComputerVision.DepthEstimation
{
public class DepthEstimationTask : InferenceTask
{
public DepthEstimationTask(ModelInfo model, InferenceOptions options)
: base(model, options)
{
}

public override string Id => "depth-estimation";
}
}
//// Licensed under the MIT License. See LICENSE in the project root for license information.

//using HuggingFace.Hub;
//using UnityEngine.Scripting;

//namespace HuggingFace.Inference.ComputerVision.DepthEstimation
//{
// public sealed class DepthEstimationTask : BaseImageInferenceTask
// {
// [Preserve]
// public DepthEstimationTask() { }

// public DepthEstimationTask(SingleSourceImageInput input, ModelInfo model = null, InferenceOptions options = null)
// : base(input, model, options)
// {
// }

// public override string Id => "depth-estimation";
// }
//}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace HuggingFace.Inference.ComputerVision.ImageClassification
{
public sealed class ImageClassificationResponse : JsonInferenceTaskResponse
{
public ImageClassificationResponse(string content, JsonSerializerSettings settings) : base(content, settings)
{
Results = JsonConvert.DeserializeObject<IReadOnlyList<ImageClassificationResult>>(content, settings);
Results = JsonConvert.DeserializeObject<IReadOnlyList<ScoreResults>>(content, settings);
}

public IReadOnlyList<ImageClassificationResult> Results { get; }
public IReadOnlyList<ScoreResults> Results { get; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using HuggingFace.Hub;
using UnityEngine.Scripting;

namespace HuggingFace.Inference.ComputerVision.ImageClassification
{
public sealed class ImageClassificationTask : BaseImageInferenceTask
{
internal ImageClassificationTask() { }
[Preserve]
public ImageClassificationTask() { }

public ImageClassificationTask(SingleSourceImageInput input, ModelInfo model = null, InferenceOptions options = null)
: base(input, model, options)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@

namespace HuggingFace.Inference.ComputerVision.ImageSegmentation
{
public sealed class ImageSegmentationResult
public sealed class ImageSegmentationResult : ScoreResults
{
[JsonConstructor]
public ImageSegmentationResult(
[JsonProperty("score")] double score,
[JsonProperty("label")] string label,
[JsonProperty("mask")] string blob)
: base(label, score)
{
Score = score;
Label = label;
Blob = blob;
}

[JsonProperty("score")]
public double Score { get; }

[JsonProperty("label")]
public string Label { get; }

[JsonProperty("mask")]
public string Blob { get; }

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using HuggingFace.Hub;
using UnityEngine.Scripting;

namespace HuggingFace.Inference.ComputerVision.ImageSegmentation
{
public sealed class ImageSegmentationTask : BaseImageInferenceTask
{
[Preserve]
public ImageSegmentationTask() { }

public ImageSegmentationTask(SingleSourceImageInput input, ModelInfo model = null, InferenceOptions options = null)
: base(input, model, options)
{
Expand Down
Loading

0 comments on commit 197a6ff

Please sign in to comment.