Skip to content

Commit

Permalink
Merge pull request #231 from microsoft/nmetulev/wcr-fixes
Browse files Browse the repository at this point in the history
fixes in wcrmodeldownloader, apipage, and textrecognition
  • Loading branch information
azchohfi authored Feb 21, 2025
2 parents 4892f01 + 62ac215 commit f91c398
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 6 additions & 2 deletions AIDevGallery/Pages/APIs/APIPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal sealed partial class APIPage : Page
{
public ModelFamily? ModelFamily { get; set; }
private ModelType? modelFamilyType;
private ModelDetails? modelDetails;

public APIPage()
{
Expand All @@ -38,6 +39,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
{
modelFamilyType = modelType;
ModelFamily = modelFamilyDetails;
ModelTypeHelpers.ModelDetails.TryGetValue(modelType, out modelDetails);
}
else if (e.Parameter is ModelDetails details)
{
Expand All @@ -48,11 +50,13 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
ReadmeUrl = details.ReadmeUrl ?? string.Empty,
Name = details.Name
};
modelDetails = details;
}
else if (e.Parameter is ModelType apiType && ModelTypeHelpers.ApiDefinitionDetails.TryGetValue(apiType, out var apiDefinition))
{
// API
modelFamilyType = apiType;
modelDetails = ModelDetailsHelper.GetModelDetailsFromApiDefinition(apiType, apiDefinition);

ModelFamily = new ModelFamily
{
Expand All @@ -67,7 +71,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
var sample = SampleDetails.Samples.FirstOrDefault(s => s.Id == apiDefinition.SampleIdToShowInDocs);
if (sample != null)
{
_ = sampleContainer.LoadSampleAsync(sample, [ModelDetailsHelper.GetModelDetailsFromApiDefinition(apiType, apiDefinition)]);
_ = sampleContainer.LoadSampleAsync(sample, [modelDetails]);
}
}
else
Expand Down Expand Up @@ -163,7 +167,7 @@ private void SampleList_ItemInvoked(ItemsView sender, ItemsViewItemInvokedEventA
{
if (args.InvokedItem is Sample sample)
{
App.MainWindow.Navigate("Samples", new SampleNavigationArgs(sample));
App.MainWindow.Navigate("Samples", new SampleNavigationArgs(sample, modelDetails));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid>
<Grid Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" CornerRadius="4">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
Expand Down
18 changes: 16 additions & 2 deletions AIDevGallery/Samples/WCRAPIs/TextRecognition.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,29 @@ protected override async Task LoadModelAsync(SampleNavigationParameters samplePa
_ = WcrModelDownloader.SetDownloadOperation(ModelType.TextRecognitionOCR, sampleParams.SampleId, TextRecognizer.MakeAvailableAsync); // <exclude-line>
}

await SetImage(System.IO.Path.Join(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Assets", "OCR.png"));
// <exclude>
else
{
await SetImage(System.IO.Path.Join(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Assets", "OCR.png"));
}

// </exclude>
sampleParams.NotifyCompletion();
}

private async void WcrModelDownloader_DownloadClicked(object sender, EventArgs e)
{
var operation = TextRecognizer.MakeAvailableAsync();

await WcrModelDownloader.SetDownloadOperation(operation);
var success = await WcrModelDownloader.SetDownloadOperation(operation);

// <exclude>
if (success)
{
await SetImage(System.IO.Path.Join(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Assets", "OCR.png"));
}

// </exclude>
}

private async void LoadImage_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit f91c398

Please sign in to comment.