Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AIDevGallery/Controls/ModelPicker/ModelOrApiPicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
Style="{StaticResource AccentButtonStyle}">
<StackPanel Orientation="Vertical" Spacing="4">
<FontIcon FontSize="14" Glyph="&#xE72A;" />
<TextBlock Text="Run sample" />
<TextBlock Text="Select Model" />
</StackPanel>
</Button>
</Grid>
Expand Down
136 changes: 74 additions & 62 deletions AIDevGallery/Controls/ModelPicker/ModelPickerViews/OnnxPickerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,82 +224,93 @@
</DropDownButton.Flyout>
</DropDownButton>
</Grid>
<ItemsRepeater
<ItemsView
x:Name="DownloadModelSelectionItemsView"
Grid.Row="2"
IsTabStop="False"
ItemsSource="{x:Bind DownloadableModels, Mode=OneWay}">
<ItemsRepeater.Layout>
ItemsSource="{x:Bind DownloadableModels, Mode=OneWay}"
SelectionChanged="DownloadModelSelectionItemsView_SelectionChanged"
SelectionMode="Single">
<ItemsView.Layout>
<StackLayout Spacing="4" />
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
</ItemsView.Layout>
<ItemsView.ItemTemplate>
<DataTemplate x:DataType="vm:DownloadableModel">
<toolkit:SettingsCard
MinHeight="48"
Padding="20,8,16,6"
Background="{ThemeResource CardBackgroundFillColorSecondaryBrush}"
Description="{x:Bind utils:AppUtils.FileSizeToString(ModelDetails.Size)}"
<ItemContainer
CornerRadius="{StaticResource ControlCornerRadius}"
GotFocus="ItemContainer_GotFocus"
PointerEntered="ItemContainer_PointerEntered"
Tag="{x:Bind}">
<toolkit:SettingsCard.Resources>
<Thickness x:Key="SettingsCardHeaderIconMargin">0,0,14,0</Thickness>
<x:Double x:Key="SettingsCardWrapThreshold">286</x:Double>
<x:Double x:Key="SettingsCardHeaderIconMaxSize">18</x:Double>
</toolkit:SettingsCard.Resources>
<toolkit:SettingsCard.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
<ItemContainer.Resources>
<SolidColorBrush x:Key="ItemContainerPointerOverBackground" Color="Transparent" />
<SolidColorBrush x:Key="ItemContainerSelectedPointerOverBackground" Color="Transparent" />
<SolidColorBrush x:Key="ItemContainerPressedBackground" Color="Transparent" />
</ItemContainer.Resources>
<toolkit:SettingsCard
MinHeight="48"
Padding="20,8,16,6"
Background="{ThemeResource CardBackgroundFillColorSecondaryBrush}"
Description="{x:Bind utils:AppUtils.FileSizeToString(ModelDetails.Size)}">
<toolkit:SettingsCard.Resources>
<Thickness x:Key="SettingsCardHeaderIconMargin">0,0,14,0</Thickness>
<x:Double x:Key="SettingsCardWrapThreshold">286</x:Double>
<x:Double x:Key="SettingsCardHeaderIconMaxSize">18</x:Double>
</toolkit:SettingsCard.Resources>
<toolkit:SettingsCard.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
MaxWidth="268"
VerticalAlignment="Center"
Text="{x:Bind ModelDetails.Name}"
TextTrimming="CharacterEllipsis"
ToolTipService.ToolTip="{x:Bind ModelDetails.Name}" />
<ItemsRepeater
<ItemsRepeater
Grid.Column="1"
Margin="4,0,0,0"
ItemsSource="{x:Bind ModelDetails.HardwareAccelerators}">
<ItemsRepeater.Layout>
<StackLayout Orientation="Horizontal" Spacing="4" />
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="models:HardwareAccelerator">
<Button
<ItemsRepeater.Layout>
<StackLayout Orientation="Horizontal" Spacing="4" />
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="models:HardwareAccelerator">
<Button
VerticalAlignment="Center"
AutomationProperties.Name="More info"
Content="{x:Bind utils:AppUtils.GetHardwareAcceleratorString((models:HardwareAccelerator))}"
Style="{StaticResource TertiaryButtonStyle}"
Tapped="StopPropagatingHandler"
ToolTipService.ToolTip="More info">
<Button.Flyout>
<Flyout ShouldConstrainToRootBounds="False">
<TextBlock
<Button.Flyout>
<Flyout ShouldConstrainToRootBounds="False">
<TextBlock
MaxWidth="360"
Text="{x:Bind utils:AppUtils.GetHardwareAcceleratorDescription((models:HardwareAccelerator))}"
TextWrapping="Wrap" />
</Flyout>
</Button.Flyout>
</Button>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</toolkit:SettingsCard.Header>
<toolkit:SettingsCard.HeaderIcon>
<ImageIcon
</Flyout>
</Button.Flyout>
</Button>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</toolkit:SettingsCard.Header>
<toolkit:SettingsCard.HeaderIcon>
<ImageIcon
AutomationProperties.AccessibilityView="Control"
AutomationProperties.Name="Model source icon"
Source="{x:Bind ModelDetails.Icon}" />
</toolkit:SettingsCard.HeaderIcon>
<StackPanel Orientation="Horizontal" Spacing="8">
<Border
</toolkit:SettingsCard.HeaderIcon>
<StackPanel Orientation="Horizontal" Spacing="8">
<Border
Width="28"
Height="28"
Margin="0,0,1,0"
Padding="0">
<Button
<Button
Width="28"
Height="28"
Padding="0"
Expand All @@ -310,24 +321,24 @@
Style="{StaticResource SubtleButtonStyle}"
ToolTipService.ToolTip="More options"
Visibility="{x:Bind OptionsVisible, Mode=OneWay}">
<Button.Flyout>
<MenuFlyout Placement="Bottom">
<MenuFlyoutItem
<Button.Flyout>
<MenuFlyout Placement="Bottom">
<MenuFlyoutItem
Click="ModelCard_Click"
Icon="{ui:FontIcon Glyph=&#xE8A5;}"
Tag="{x:Bind ModelDetails}"
Text="View model card" />
<MenuFlyoutItem
<MenuFlyoutItem
Click="ViewLicense_Click"
Icon="{ui:FontIcon Glyph=&#xE82D;}"
Tag="{x:Bind ModelDetails}"
Text="View model license" />
</MenuFlyout>
</Button.Flyout>
</Button>
</Border>
<Grid>
<Button
</MenuFlyout>
</Button.Flyout>
</Button>
</Border>
<Grid>
<Button
Padding="4"
VerticalAlignment="Center"
AutomationProperties.HelpText="Download model"
Expand All @@ -342,19 +353,20 @@
ToolTipService.ToolTip="Download model"
Visibility="{x:Bind CanDownload, Mode=OneWay}" />

<ProgressRing
<ProgressRing
Width="24"
Height="24"
Background="{ThemeResource ControlStrongStrokeColorDisabledBrush}"
IsIndeterminate="False"
Visibility="{x:Bind vm:DownloadableModel.BoolToVisibilityInverse(CanDownload), Mode=OneWay}"
Value="{x:Bind Progress, Mode=OneWay}" />
</Grid>
</StackPanel>
</toolkit:SettingsCard>
</Grid>
</StackPanel>
</toolkit:SettingsCard>
</ItemContainer>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</ItemsView.ItemTemplate>
</ItemsView>
</Grid>
</ScrollViewer>
<mpControls:AddHFModelView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ private void ModelSelectionItemsView_SelectionChanged(ItemsView sender, ItemsVie
if (sender.SelectedItem is AvailableModel model)
{
OnSelectedModelChanged(this, model.ModelDetails);
DownloadModelSelectionItemsView.Select(-1);
}
}

private void DownloadModelSelectionItemsView_SelectionChanged(ItemsView sender, ItemsViewSelectionChangedEventArgs args)
{
if (sender.SelectedItem is DownloadableModel model)
{
OnSelectedModelChanged(this, model.GetModelDetails());
ModelSelectionItemsView.Select(-1);
}
}

Expand Down
6 changes: 6 additions & 0 deletions AIDevGallery/Controls/SampleContainer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public async Task LoadSampleAsync(Sample? sample, List<ModelDetails>? models, Wi
this.Visibility = Visibility.Visible;
if (!LoadSampleMetadata(sample, models, winMlSampleOptions))
{
VisualStateManager.GoToState(this, "SampleLoaded", true);
return;
}

Expand Down Expand Up @@ -439,6 +440,11 @@ private void UserControl_ActualThemeChanged(FrameworkElement sender, object args
RenderCode();
}

public void SetNoModelStatus()
{
VisualStateManager.GoToState(this, "Disabled", true);
}

public void ShowCode()
{
RenderCodeTabs();
Expand Down
16 changes: 10 additions & 6 deletions AIDevGallery/Helpers/SamplesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,12 @@ string GetValueOrNull(string? value, string ifNull)
var realCachedModel = App.ModelCache.GetCachedModel(selectedModelDetails.Url);
if (realCachedModel == null)
{
return null;
cachedModel = new(selectedModelDetails.Id, "Need Download", selectedModelDetails.Url, selectedModelDetails.Size, selectedModelDetails.HardwareAccelerators.FirstOrDefault(), winMlSampleOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can improve how this looks in the code - Need Download feels awkard. Consider something like path-to-model-files-once-downloaded to make it clear it's a path value that goes there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which of the following do you mean to change?

  • cachedModel = new(selectedModelDetails.Id, "path-to-model-files-once-downloaded",
  • cachedModel = new(selectedModelDetails.Id, "C:\Users\xxx.cache\aigallery\microsoft--Phi-4-mini-instruct-onnx\main\cpu_and_mobile\cpu-int4-rtn-block-32-acc-level-4",
  • cachedModel = new(selectedModelDetails.Id, "", (this code can use "App.ModelCache.IsModelCached(selectedModel.Url)" to check model status)

}
else
{
cachedModel = new(selectedModelDetails.Id, realCachedModel.Path, realCachedModel.Details.Url, realCachedModel.ModelSize, selectedModelDetails.HardwareAccelerators.FirstOrDefault(), winMlSampleOptions);
}

cachedModel = new(selectedModelDetails.Id, realCachedModel.Path, realCachedModel.Details.Url, realCachedModel.ModelSize, selectedModelDetails.HardwareAccelerators.FirstOrDefault(), winMlSampleOptions);
}

var cachedSampleItem = App.FindSampleItemById(cachedModel.Id);
Expand All @@ -374,10 +376,12 @@ string GetValueOrNull(string? value, string ifNull)
var realCachedModel = App.ModelCache.GetCachedModel(selectedModelDetails2.Url);
if (realCachedModel == null)
{
return null;
cachedModel = new(selectedModelDetails2.Id, "Need Download", selectedModelDetails2.Url, selectedModelDetails2.Size, selectedModelDetails2.HardwareAccelerators.FirstOrDefault(), winMlSampleOptions);
}
else
{
cachedModel = new(selectedModelDetails2.Id, realCachedModel.Path, realCachedModel.Url, realCachedModel.ModelSize, selectedModelDetails2.HardwareAccelerators.FirstOrDefault(), winMlSampleOptions);
}

cachedModel = new(selectedModelDetails2.Id, realCachedModel.Path, realCachedModel.Url, realCachedModel.ModelSize, selectedModelDetails2.HardwareAccelerators.FirstOrDefault(), winMlSampleOptions);
}

var model2Type = sample.Model2Types.Any(cachedSampleItem.Contains)
Expand Down
39 changes: 35 additions & 4 deletions AIDevGallery/Pages/Scenarios/ScenarioPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,40 @@
To="0"
Duration="0:0:0.1" />
</animations:ImplicitAnimationSet>

<ContentDialog
x:Name="DownloadDialog"
Title="Download model"
DefaultButton="Primary"
IsPrimaryButtonEnabled="{Binding ElementName=AgreeCheckBox, Path=IsChecked}"
PrimaryButtonText="Download"
SecondaryButtonText="Cancel">
<ContentDialog.Content>
<StackPanel MinWidth="360">
<InfoBar
x:Name="WarningInfoBar"
Title="Model is not recommended"
Margin="0,0,0,16"
IsClosable="False"
IsOpen="False"
Severity="Warning" />
<TextBlock TextWrapping="Wrap">
<Run Text="You are about to download" />
<Run x:Name="ModelNameTxt" FontWeight="SemiBold" />
<Run Text="from" />
<Run x:Name="ModelSourceTxt" FontWeight="SemiBold" />
<LineBreak />
<LineBreak /><Run Text="License:" />
<Hyperlink x:Name="ModelLicenseLink">
<Run x:Name="ModelLicenseLabel" />
</Hyperlink>
</TextBlock>
<CheckBox
x:Name="AgreeCheckBox"
Margin="0,16,0,0"
Content="I have reviewed and agree with the license" />
</StackPanel>
</ContentDialog.Content>
</ContentDialog>
</Page.Resources>
<Grid>
<Grid.RowDefinitions>
Expand Down Expand Up @@ -156,8 +189,6 @@
</Grid>
</StackPanel>
</Button>
<!--<ComboBox x:Name="DeviceEpSelectionDevicePolicyComboBox"
Visibility="Collapsed"></ComboBox>-->
<Button
x:Name="WinMlModelOptionsButton"
Padding="0"
Expand Down Expand Up @@ -472,7 +503,7 @@
Text="Downloading and installing available hardware accelerators for your device. This might take a minute." />
</StackPanel>
</Grid>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="LayoutVisualStates">
<VisualState x:Name="WideLayout" />
Expand Down
Loading
Loading