Skip to content

Commit 10e6b6b

Browse files
committed
Supertonic demo
1 parent 7a35320 commit 10e6b6b

File tree

25 files changed

+574
-264
lines changed

25 files changed

+574
-264
lines changed

BuildDemos.bat

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CD Examples/TensorStack.Example.Extractors
2+
rmdir /s /q bin\Build\ExtractorDemo
3+
dotnet publish -c Release /p:PublishProfile=SelfContained
4+
5+
CD ..\TensorStack.Example.TextGeneration
6+
rmdir /s /q bin\Build\TextDemo
7+
dotnet publish -c Release /p:PublishProfile=SelfContained
8+
9+
CD ..\TensorStack.Example.Upscaler
10+
rmdir /s /q bin\Build\UpscaleDemo
11+
dotnet publish -c Release /p:PublishProfile=SelfContained
12+
13+
CD ..\..

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.1.81</Version>
3+
<Version>0.1.84</Version>
44
<Company>TensorStack</Company>
55
<Copyright>TensorStack - 2025</Copyright>
66
<RepositoryUrl>https://github.com/TensorStack-AI/TensorStack</RepositoryUrl>

Examples/TensorStack.Example.Upscaler/Properties/PublishProfiles/SelfContained_DML.pubxml renamed to Examples/TensorStack.Example.Extractors/Properties/PublishProfiles/SelfContained.pubxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<Configuration>Release</Configuration>
66
<Platform>Any CPU</Platform>
7-
<PublishDir>bin\Build\UpscaleDemo_DirectML\</PublishDir>
7+
<PublishDir>bin\Build\ExtractorDemo\</PublishDir>
88
<PublishProtocol>FileSystem</PublishProtocol>
99
<_TargetId>Folder</_TargetId>
1010
<TargetFramework>net9.0-windows10.0.17763.0</TargetFramework>

Examples/TensorStack.Example.Extractors/Properties/PublishProfiles/SelfContained_CUDA.pubxml

Lines changed: 0 additions & 17 deletions
This file was deleted.

Examples/TensorStack.Example.Extractors/Settings.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"Channels": 3,
99
"SampleSize": 0,
1010
"OutputChannels": 1,
11-
"Path": "Models\\Canny.onnx",
11+
"Path": "Models\\Canny\\model.onnx",
1212
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/Canny/model.onnx?download=true"
1313
},
1414
{
@@ -19,7 +19,7 @@
1919
"Channels": 3,
2020
"SampleSize": 0,
2121
"OutputChannels": 1,
22-
"Path": "Models\\SoftEdge.onnx",
22+
"Path": "Models\\SoftEdge\\model.onnx",
2323
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/SoftEdge/model.onnx?download=true"
2424
},
2525
{
@@ -31,7 +31,7 @@
3131
"OutputChannels": 1,
3232
"OutputNormalization": "MinMaxOneToOne",
3333
"IsDynamicOutput": true,
34-
"Path": "Models\\Depth.onnx",
34+
"Path": "Models\\Depth\\model.onnx",
3535
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/Depth/model.onnx?download=true"
3636
},
3737
{
@@ -41,7 +41,7 @@
4141
"Channels": 3,
4242
"SampleSize": 0,
4343
"OutputChannels": 1,
44-
"Path": "Models\\LineDrawing.onnx",
44+
"Path": "Models\\LineDrawing\\model.onnx",
4545
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/LineDrawing/model.onnx?download=true"
4646
},
4747
{
@@ -53,7 +53,7 @@
5353
"OutputChannels": 1,
5454
"IsDynamicOutput": true,
5555
"OutputNormalization": "MinMaxOneToOne",
56-
"Path": "Models\\DepthAnything-Small.onnx",
56+
"Path": "Models\\DepthAnything-Small\\model.onnx",
5757
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/DepthAnything-Small/model.onnx?download=true"
5858
},
5959
{
@@ -65,7 +65,7 @@
6565
"OutputChannels": 1,
6666
"IsDynamicOutput": true,
6767
"OutputNormalization": "MinMaxOneToOne",
68-
"Path": "Models\\DepthAnything-Base.onnx",
68+
"Path": "Models\\DepthAnything-Base\\model.onnx",
6969
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/DepthAnything-Base/model.onnx?download=true"
7070
},
7171
{
@@ -77,7 +77,7 @@
7777
"OutputChannels": 1,
7878
"IsDynamicOutput": true,
7979
"OutputNormalization": "MinMaxOneToOne",
80-
"Path": "Models\\DepthAnything-Large.onnx",
80+
"Path": "Models\\DepthAnything-Large\\model.onnx",
8181
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/DepthAnything-Large/model.onnx?download=true"
8282
},
8383
{
@@ -87,7 +87,7 @@
8787
"Channels": 3,
8888
"SampleSize": 1024,
8989
"OutputChannels": 1,
90-
"Path": "Models\\BiRefNet.onnx",
90+
"Path": "Models\\BiRefNet\\model.onnx",
9191
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/BiRefNet/model.onnx?download=true"
9292
},
9393
{
@@ -98,7 +98,7 @@
9898
"Channels": 3,
9999
"SampleSize": 1024,
100100
"OutputChannels": 1,
101-
"Path": "Models\\RMBGv1.4.onnx",
101+
"Path": "Models\\RMBGv1.4\\model.onnx",
102102
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/RMBGv1.4/model.onnx?download=true"
103103
},
104104
{
@@ -108,7 +108,7 @@
108108
"Channels": 3,
109109
"SampleSize": 1024,
110110
"OutputChannels": 1,
111-
"Path": "Models\\RMBGv2.0.onnx",
111+
"Path": "Models\\RMBGv2.0\\model.onnx",
112112
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/RMBGv2.0/model.onnx?download=true"
113113
},
114114
{
@@ -118,7 +118,7 @@
118118
"IsDefault": true,
119119
"Channels": 3,
120120
"SampleSize": 640,
121-
"Path": "Models\\Pose-Body7.onnx",
121+
"Path": "Models\\Pose-Body7\\model.onnx",
122122
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/Pose-Body7/model.onnx?download=true"
123123
},
124124
{
@@ -127,7 +127,7 @@
127127
"Type": "Pose",
128128
"Channels": 3,
129129
"SampleSize": 640,
130-
"Path": "Models\\Pose-Coco.onnx",
130+
"Path": "Models\\Pose-Coco\\model.onnx",
131131
"UrlPath": "https://huggingface.co/saddam213/DemoApp/resolve/main/Extractor/Pose-Coco/model.onnx?download=true"
132132
}
133133
]

Examples/TensorStack.Example.Extractors/TensorStack.Example.Extractors.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5+
<AssemblyName>ExtractorDemo</AssemblyName>
56
<TargetFramework>net9.0-windows10.0.17763.0</TargetFramework>
67
<PlatformTarget>x64</PlatformTarget>
78
<UseWPF>true</UseWPF>

Examples/TensorStack.Example.TextGeneration/App.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public App()
2828
// Add WPFCommon
2929
builder.Services.AddWPFCommon<MainWindow, Settings>(configuration);
3030

31-
// builder.Services.AddSingleton<IMediaService, MediaService>();
3231
builder.Services.AddSingleton<ITextService, TextService>();
32+
builder.Services.AddSingleton<IWhisperService, WhisperService>();
33+
builder.Services.AddSingleton<ISupertonicService, SupertonicService>();
3334

3435
_appHost = builder.Build();
3536

Examples/TensorStack.Example.Extractors/Properties/PublishProfiles/SelfContained_DML.pubxml renamed to Examples/TensorStack.Example.TextGeneration/Properties/PublishProfiles/SelfContained.pubxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<Configuration>Release</Configuration>
66
<Platform>Any CPU</Platform>
7-
<PublishDir>bin\Build\ExtractorDemo_DirectML\</PublishDir>
7+
<PublishDir>bin\Build\TextDemo\</PublishDir>
88
<PublishProtocol>FileSystem</PublishProtocol>
99
<_TargetId>Folder</_TargetId>
1010
<TargetFramework>net9.0-windows10.0.17763.0</TargetFramework>
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using TensorStack.Common;
5+
using TensorStack.Common.Pipeline;
6+
using TensorStack.Common.Tensor;
7+
using TensorStack.Example.Common;
8+
using TensorStack.Providers;
9+
using TensorStack.TextGeneration.Common;
10+
using TensorStack.TextGeneration.Pipelines.Supertonic;
11+
12+
namespace TensorStack.Example.Services
13+
{
14+
public class SupertonicService : ServiceBase, ISupertonicService
15+
{
16+
private readonly Settings _settings;
17+
private IPipeline _currentPipeline;
18+
private CancellationTokenSource _cancellationTokenSource;
19+
private bool _isLoaded;
20+
private bool _isLoading;
21+
private bool _isExecuting;
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="SupertonicService"/> class.
25+
/// </summary>
26+
/// <param name="settings">The settings.</param>
27+
public SupertonicService(Settings settings)
28+
{
29+
_settings = settings;
30+
}
31+
32+
/// <summary>
33+
/// Gets a value indicating whether this instance is loaded.
34+
/// </summary>
35+
public bool IsLoaded
36+
{
37+
get { return _isLoaded; }
38+
private set { SetProperty(ref _isLoaded, value); }
39+
}
40+
41+
/// <summary>
42+
/// Gets a value indicating whether this instance is loading.
43+
/// </summary>
44+
public bool IsLoading
45+
{
46+
get { return _isLoading; }
47+
private set { SetProperty(ref _isLoading, value); NotifyPropertyChanged(nameof(CanCancel)); }
48+
}
49+
50+
/// <summary>
51+
/// Gets a value indicating whether this instance is executing.
52+
/// </summary>
53+
public bool IsExecuting
54+
{
55+
get { return _isExecuting; }
56+
private set { SetProperty(ref _isExecuting, value); NotifyPropertyChanged(nameof(CanCancel)); }
57+
}
58+
59+
/// <summary>
60+
/// Gets a value indicating whether this instance can cancel.
61+
/// </summary>
62+
public bool CanCancel => _isLoading || _isExecuting;
63+
64+
65+
/// <summary>
66+
/// Load the upscale pipeline
67+
/// </summary>
68+
/// <param name="config">The configuration.</param>
69+
public async Task LoadAsync(TextModel model, Device device)
70+
{
71+
try
72+
{
73+
IsLoaded = false;
74+
IsLoading = true;
75+
using (_cancellationTokenSource = new CancellationTokenSource())
76+
{
77+
var cancellationToken = _cancellationTokenSource.Token;
78+
if (_currentPipeline != null)
79+
await _currentPipeline.UnloadAsync(cancellationToken);
80+
81+
var provider = device.GetProvider();
82+
_currentPipeline = SupertonicPipeline.Create(model.Path, provider);
83+
await Task.Run(() => _currentPipeline.LoadAsync(cancellationToken), cancellationToken);
84+
85+
}
86+
}
87+
catch (OperationCanceledException)
88+
{
89+
_currentPipeline?.Dispose();
90+
_currentPipeline = null;
91+
throw;
92+
}
93+
finally
94+
{
95+
IsLoaded = true;
96+
IsLoading = false;
97+
}
98+
}
99+
100+
101+
/// <summary>
102+
/// Execute the pipeline.
103+
/// </summary>
104+
/// <param name="options">The options.</param>
105+
public async Task<AudioTensor> ExecuteAsync(SupertonicRequest options)
106+
{
107+
try
108+
{
109+
IsExecuting = true;
110+
using (_cancellationTokenSource = new CancellationTokenSource())
111+
{
112+
var pipeline = _currentPipeline as IPipeline<AudioTensor, SupertonicOptions, GenerateProgress>;
113+
var pipelineOptions = new SupertonicOptions
114+
{
115+
TextInput = options.InputText,
116+
VoiceStyle = options.VoiceStyle,
117+
Steps = options.Steps,
118+
Speed = options.Speed,
119+
SilenceDuration = options.SilenceDuration,
120+
Seed = options.Seed,
121+
};
122+
123+
return await pipeline.RunAsync(pipelineOptions, cancellationToken: _cancellationTokenSource.Token);
124+
}
125+
}
126+
finally
127+
{
128+
IsExecuting = false;
129+
}
130+
}
131+
132+
133+
/// <summary>
134+
/// Cancel the running task (Load or Execute)
135+
/// </summary>
136+
public async Task CancelAsync()
137+
{
138+
await _cancellationTokenSource.SafeCancelAsync();
139+
}
140+
141+
142+
/// <summary>
143+
/// Unload the pipeline
144+
/// </summary>
145+
public async Task UnloadAsync()
146+
{
147+
if (_currentPipeline != null)
148+
{
149+
await _cancellationTokenSource.SafeCancelAsync();
150+
await _currentPipeline.UnloadAsync();
151+
_currentPipeline.Dispose();
152+
_currentPipeline = null;
153+
}
154+
155+
IsLoaded = false;
156+
IsLoading = false;
157+
IsExecuting = false;
158+
}
159+
}
160+
161+
162+
public interface ISupertonicService
163+
{
164+
bool IsLoaded { get; }
165+
bool IsLoading { get; }
166+
bool IsExecuting { get; }
167+
bool CanCancel { get; }
168+
Task LoadAsync(TextModel model, Device device);
169+
Task UnloadAsync();
170+
Task CancelAsync();
171+
Task<AudioTensor> ExecuteAsync(SupertonicRequest options);
172+
}
173+
174+
175+
public record SupertonicRequest
176+
{
177+
public string InputText { get; set; }
178+
public string VoiceStyle { get; set; }
179+
public int Steps { get; set; } = 5;
180+
public float Speed { get; set; } = 1f;
181+
public float SilenceDuration { get; set; } = 0.3f;
182+
public int Seed { get; set; }
183+
}
184+
185+
}

0 commit comments

Comments
 (0)