Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
152 changes: 82 additions & 70 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="DownloadableModelSelectionItemsView"
Grid.Row="2"
IsTabStop="False"
ItemsSource="{x:Bind DownloadableModels, Mode=OneWay}">
<ItemsRepeater.Layout>
ItemsSource="{x:Bind DownloadableModels, Mode=OneWay}"
SelectionChanged="DownloadableModelSelectionItemsView_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
MaxWidth="268"
VerticalAlignment="Center"
Text="{x:Bind ModelDetails.Name}"
TextTrimming="CharacterEllipsis"
ToolTipService.ToolTip="{x:Bind ModelDetails.Name}" />
<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
<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
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
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 @@ -131,6 +131,11 @@ private void ResetAndLoadModelList()
}
}
}

if (Selected != null)
{
SelectModel(Selected);
}
}

private void CacheStore_ModelsChanged(ModelCacheStore sender)
Expand All @@ -143,6 +148,16 @@ private void ModelSelectionItemsView_SelectionChanged(ItemsView sender, ItemsVie
if (sender.SelectedItem is AvailableModel model)
{
OnSelectedModelChanged(this, model.ModelDetails);
DispatcherQueue.TryEnqueue(() => DownloadableModelSelectionItemsView.DeselectAll());
}
}

private void DownloadableModelSelectionItemsView_SelectionChanged(ItemsView sender, ItemsViewSelectionChangedEventArgs args)
{
if (sender.SelectedItem is DownloadableModel model)
{
OnSelectedModelChanged(this, model.GetModelDetails());
DispatcherQueue.TryEnqueue(() => ModelSelectionItemsView.DeselectAll());
}
}

Expand All @@ -159,6 +174,16 @@ public override void SelectModel(ModelDetails? modelDetails)
{
DispatcherQueue.TryEnqueue(() => ModelSelectionItemsView.DeselectAll());
}

var downloadableModel = DownloadableModels.FirstOrDefault(m => m.ModelDetails.Id == modelDetails.Id);
if (downloadableModel != null)
{
DispatcherQueue.TryEnqueue(() => DownloadableModelSelectionItemsView.Select(DownloadableModels.IndexOf(downloadableModel)));
}
else
{
DispatcherQueue.TryEnqueue(() => DownloadableModelSelectionItemsView.DeselectAll());
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion AIDevGallery/Controls/SampleContainer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
IsClosable="False"
IsIconVisible="False"
IsOpen="True"
Message="To enable this sample, download the required models."
Message="To enable this sample, please go to the selection window to download the required models."
Severity="Informational"
Visibility="Collapsed" />
<StackPanel
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
Loading
Loading