Skip to content

Commit 4d69a5d

Browse files
committed
Fixed all the app without correct appmanifest setting
1 parent 09b5ec3 commit 4d69a5d

File tree

16 files changed

+244
-326
lines changed

16 files changed

+244
-326
lines changed

Samples/WindowsAIFoundry/cpp-console-sparse/AppxManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
88
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
99
xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10"
10-
IgnorableNamespaces="uap uap2 uap3 rescap desktop uap10">
10+
xmlns:systemai="http://schemas.microsoft.com/appx/manifest/systemai/windows10"
11+
IgnorableNamespaces="uap uap2 uap3 rescap desktop uap10 systemai">
1112

1213
<Identity
1314
Name="WindowsAISampleForCppCMakeSparse"
@@ -25,7 +26,7 @@
2526
<Resource Language="en-us" />
2627
</Resources>
2728
<Dependencies>
28-
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.19000.0" MaxVersionTested="10.0.19000.0" />
29+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.19000.0" MaxVersionTested="10.0.26226.0" />
2930
<PackageDependency
3031
Name="Microsoft.WindowsAppRuntime.1.8-experimental2"
3132
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
@@ -34,6 +35,7 @@
3435
<Capabilities>
3536
<rescap:Capability Name="runFullTrust" />
3637
<rescap:Capability Name="unvirtualizedResources"/>
38+
<systemai:Capability Name="systemAIModels"/>
3739
</Capabilities>
3840
<Applications>
3941
<Application Id="WindowsAISampleForCppCMakeSparsePkg" Executable="cmake-ai-generator.exe" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="win32App">

Samples/WindowsAIFoundry/cs-maui/MauiWindowsAISample/Platforms/Windows/Package.appxmanifest

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
55
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
66
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
7-
IgnorableNamespaces="uap rescap">
7+
xmlns:systemai="http://schemas.microsoft.com/appx/manifest/systemai/windows10"
8+
IgnorableNamespaces="uap rescap systemai">
89

910
<Identity Name="maui-package-name-placeholder" Publisher="CN=User Name" Version="0.0.0.0" />
1011

@@ -17,8 +18,8 @@
1718
</Properties>
1819

1920
<Dependencies>
20-
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
21-
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
21+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.26226.0" />
22+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.26226.0" />
2223
</Dependencies>
2324

2425
<Resources>
@@ -41,6 +42,7 @@
4142

4243
<Capabilities>
4344
<rescap:Capability Name="runFullTrust" />
45+
<systemai:Capability Name="systemAIModels"/>
4446
</Capabilities>
4547

4648
</Package>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.100",
4+
"allowPrerelease": true,
5+
"rollForward": "latestMajor"
6+
},
7+
"msbuild-sdks": {
8+
"Microsoft.Build.NoTargets": "3.7.0"
9+
}
10+
}

Samples/WindowsAIFoundry/cs-winforms-pckg/Packaged/Package.appxmanifest

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
55
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
66
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
7-
IgnorableNamespaces="uap rescap">
7+
xmlns:systemai="http://schemas.microsoft.com/appx/manifest/systemai/windows10"
8+
IgnorableNamespaces="uap rescap systemai">
89

910
<Identity
1011
Name="52bfb940-2388-40a6-8a8b-15e8bb397ead"
@@ -18,8 +19,7 @@
1819
</Properties>
1920

2021
<Dependencies>
21-
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
22-
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
22+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.26226.0" />
2323
</Dependencies>
2424

2525
<Resources>
@@ -45,5 +45,6 @@
4545
<Capabilities>
4646
<Capability Name="internetClient" />
4747
<rescap:Capability Name="runFullTrust" />
48+
<systemai:Capability Name="systemAIModels"/>
4849
</Capabilities>
4950
</Package>

Samples/WindowsAIFoundry/cs-winforms-pckg/Packaged/Packaged.wapproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
5858
<NoWarn>$(NoWarn);NU1702</NoWarn>
5959
<EntryPointProjectUniqueName>..\WindowsAISampleForWinForms\WindowsAISample.csproj</EntryPointProjectUniqueName>
60+
<AppxOSMinVersionReplaceManifestVersion>false</AppxOSMinVersionReplaceManifestVersion>
61+
<AppxOSMaxVersionTestedReplaceManifestVersion>false</AppxOSMaxVersionTestedReplaceManifestVersion>
6062
</PropertyGroup>
6163
<ItemGroup>
6264
<AppxManifest Include="Package.appxmanifest">

Samples/WindowsAIFoundry/cs-winforms-pckg/WindowsAISampleForWinForms/MainForm.cs

Lines changed: 42 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
namespace WindowsAISample
1010
{
1111
// This is a sample application that demonstrates how to use the Windows AI APIs
12-
// to perform text recognition and summarization on an image.
12+
// to perform text recognition and image description on an image.
1313
// To learn more about the Windows AI API usage, visit https://learn.microsoft.com/windows/ai/apis/
1414
public partial class MainForm : Form
1515
{
1616
private string pathToImage = string.Empty;
17-
private LanguageModel? languageModel = null;
17+
private ImageDescriptionGenerator? imageDescriptionGenerator = null;
1818
private TextRecognizer? textRecognizer = null;
1919

2020
public MainForm()
@@ -89,14 +89,14 @@ private async void ProcessButton_Click(object sender, EventArgs e)
8989

9090
try
9191
{
92-
richTextBoxForImageSummary.Text = "Summarizing image text...";
93-
await SummarizeImageText(textInImage);
92+
richTextBoxForImageSummary.Text = "Describing image...";
93+
await DescribeImage();
9494
}
9595
catch (Exception ex)
9696
{
9797
TaskDialog.ShowDialog(this, new TaskDialogPage {
9898
Caption = "Windows AI WinForms Sample Error",
99-
Heading = "An error occurred while summarizing the text in the image",
99+
Heading = "An error occurred while describing the image",
100100
Text = ex.Message,
101101
Icon = TaskDialogIcon.Error,
102102
Buttons = new TaskDialogButtonCollection
@@ -111,52 +111,41 @@ private async void ProcessButton_Click(object sender, EventArgs e)
111111
private async Task LoadAIModels()
112112
{
113113
// Load the AI models needed for image processing
114-
switch (LanguageModel.GetReadyState())
114+
switch (ImageDescriptionGenerator.GetReadyState())
115115
{
116116
case Microsoft.Windows.AI.AIFeatureReadyState.NotReady:
117-
System.Diagnostics.Debug.WriteLine("Ensure LanguageModel is ready");
118-
var op = await LanguageModel.EnsureReadyAsync();
119-
System.Diagnostics.Debug.WriteLine($"LanguageModel.EnsureReadyAsync completed with status: {op.Status}");
120-
if (op.Status != Microsoft.Windows.AI.AIFeatureReadyResultState.Success)
117+
System.Diagnostics.Debug.WriteLine("Ensure ImageDescriptionGenerator is ready");
118+
var opImage = await ImageDescriptionGenerator.EnsureReadyAsync();
119+
System.Diagnostics.Debug.WriteLine($"ImageDescriptionGenerator.EnsureReadyAsync completed with status: {opImage.Status}");
120+
if (opImage.Status != Microsoft.Windows.AI.AIFeatureReadyResultState.Success)
121121
{
122-
richTextBoxForImageSummary.Text = "Language model not ready for use";
123-
throw new Exception("Language model not ready for use");
122+
richTextBoxForImageSummary.Text = "Image description generator not ready for use";
123+
throw new Exception("Image description generator not ready for use");
124124
}
125125
break;
126126
case Microsoft.Windows.AI.AIFeatureReadyState.DisabledByUser:
127-
System.Diagnostics.Debug.WriteLine("Language model disabled by user");
128-
richTextBoxForImageSummary.Text = "Language model disabled by user";
127+
System.Diagnostics.Debug.WriteLine("Image Description Generator disabled by user");
128+
richTextBoxForImageSummary.Text = "Image description generator disabled by user";
129129
return;
130130
case Microsoft.Windows.AI.AIFeatureReadyState.NotSupportedOnCurrentSystem:
131-
System.Diagnostics.Debug.WriteLine("Language model not supported on current system");
132-
richTextBoxForImageSummary.Text = "Language model not supported on current system";
131+
System.Diagnostics.Debug.WriteLine("Image Description Generator not supported on current system");
132+
richTextBoxForImageSummary.Text = "Image description generator not supported on current system";
133133
return;
134134
}
135135

136-
try
136+
imageDescriptionGenerator = await ImageDescriptionGenerator.CreateAsync();
137+
if (imageDescriptionGenerator == null)
137138
{
138-
// There is a bug in 1.8 where the LanguageModel.GetReadyState() is not
139-
// returning the correct state. The call to CreateAsync() will throw
140-
// an exception if the state is not ready.The sample application
141-
// will log the error and continue for now.
142-
languageModel = await LanguageModel.CreateAsync();
143-
if (languageModel == null)
144-
{
145-
throw new Exception("Failed to create LanguageModel instance.");
146-
}
147-
}
148-
catch (Exception ex)
149-
{
150-
System.Diagnostics.Debug.WriteLine($"Error creating LanguageModel: {ex.Message}");
139+
throw new Exception("Failed to create ImageDescriptionGenerator instance.");
151140
}
152141

153142
switch (TextRecognizer.GetReadyState())
154143
{
155144
case Microsoft.Windows.AI.AIFeatureReadyState.NotReady:
156145
System.Diagnostics.Debug.WriteLine("Ensure TextRecognizer is ready");
157-
var op = await TextRecognizer.EnsureReadyAsync();
158-
System.Diagnostics.Debug.WriteLine($"TextRecognizer.EnsureReadyAsync completed with status: {op.Status}");
159-
if (op.Status != Microsoft.Windows.AI.AIFeatureReadyResultState.Success)
146+
var opText = await TextRecognizer.EnsureReadyAsync();
147+
System.Diagnostics.Debug.WriteLine($"TextRecognizer.EnsureReadyAsync completed with status: {opText.Status}");
148+
if (opText.Status != Microsoft.Windows.AI.AIFeatureReadyResultState.Success)
160149
{
161150
richTextBoxForImageText.Text = "Text recognizer not ready for use";
162151
throw new Exception("Text recognizer not ready for use");
@@ -197,6 +186,26 @@ private async Task<string> PerformTextRecognition()
197186
return text;
198187
}
199188

189+
private async Task DescribeImage()
190+
{
191+
ImageBuffer? imageBuffer = await LoadImageBufferFromFileAsync(pathToImage);
192+
193+
if (imageBuffer == null)
194+
{
195+
throw new Exception("Failed to load image buffer.");
196+
}
197+
198+
ContentFilterOptions filterOptions = new();
199+
var result = await imageDescriptionGenerator!.DescribeAsync(imageBuffer, ImageDescriptionKind.BriefDescription, filterOptions);
200+
201+
if (result.Status != ImageDescriptionResultStatus.Complete)
202+
{
203+
throw new Exception($"Image description failed with status: {result.Status}");
204+
}
205+
206+
richTextBoxForImageSummary.Text = result.Description;
207+
}
208+
200209
private async Task<ImageBuffer?> LoadImageBufferFromFileAsync(string filePath)
201210
{
202211
StorageFile file = await StorageFile.GetFileFromPathAsync(filePath);
@@ -208,45 +217,5 @@ private async Task<string> PerformTextRecognition()
208217
return bitmap != null ? ImageBuffer.CreateForSoftwareBitmap(bitmap) : null;
209218
}
210219
}
211-
212-
private async Task SummarizeImageText(string text)
213-
{
214-
string systemPrompt = "You summarize user-provided text to a software developer audience." +
215-
"Respond only with the summary and no additional text.";
216-
217-
// Update the property names to match the correct ones based on the provided type signature.
218-
var promptMaxAllowedSeverityLevel = new TextContentFilterSeverity {
219-
Hate = SeverityLevel.Low,
220-
Sexual = SeverityLevel.Low,
221-
Violent = SeverityLevel.Low,
222-
SelfHarm = SeverityLevel.Low
223-
};
224-
225-
var responseMaxAllowedSeverityLevel = new TextContentFilterSeverity {
226-
Hate = SeverityLevel.Low,
227-
Sexual = SeverityLevel.Low,
228-
Violent = SeverityLevel.Low,
229-
SelfHarm = SeverityLevel.Low
230-
};
231-
232-
var contentFilterOptions = new ContentFilterOptions {
233-
PromptMaxAllowedSeverityLevel = promptMaxAllowedSeverityLevel,
234-
ResponseMaxAllowedSeverityLevel = responseMaxAllowedSeverityLevel
235-
};
236-
237-
if (languageModel != null)
238-
{
239-
// Create a context for the language model
240-
var languageModelContext = languageModel!.CreateContext(systemPrompt, contentFilterOptions);
241-
string prompt = "Summarize the following text: " + text;
242-
var output = await languageModel.GenerateResponseAsync(languageModelContext, prompt, new LanguageModelOptions());
243-
richTextBoxForImageSummary.Text = output.Text;
244-
}
245-
else
246-
{
247-
System.Diagnostics.Debug.WriteLine("Error: LanguageModel is null but should have been created during LoadAIModels()");
248-
richTextBoxForImageSummary.Text = "Error: LanguageModel is null";
249-
}
250-
}
251220
}
252221
}

Samples/WindowsAIFoundry/cs-winforms-sparse/WinForms/AppxManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
88
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
99
xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10"
10-
IgnorableNamespaces="uap uap2 uap3 rescap desktop uap10">
10+
xmlns:systemai="http://schemas.microsoft.com/appx/manifest/systemai/windows10"
11+
IgnorableNamespaces="uap uap2 uap3 rescap desktop uap10 systemai">
1112
<Identity
1213
Name="WindowsAISampleForWinFormsSparse"
1314
Publisher="CN=Fabrikam Corporation, O=Fabrikam Corporation, L=Redmond, S=Washington, C=US"
@@ -24,7 +25,7 @@
2425
<Resource Language="en-us" />
2526
</Resources>
2627
<Dependencies>
27-
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.19000.0" MaxVersionTested="10.0.19000.0" />
28+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.19000.0" MaxVersionTested="10.0.26226.0" />
2829
<PackageDependency
2930
Name="Microsoft.WindowsAppRuntime.1.8-experimental2"
3031
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
@@ -33,6 +34,7 @@
3334
<Capabilities>
3435
<rescap:Capability Name="runFullTrust" />
3536
<rescap:Capability Name="unvirtualizedResources"/>
37+
<systemai:Capability Name="systemAIModels"/>
3638
</Capabilities>
3739
<Applications>
3840
<Application Id="WindowsAISampleForWinFormsSparsePkg" Executable="WindowsAISampleForWinFormsSparse.exe" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="win32App">

0 commit comments

Comments
 (0)