{ This script will use AI to extract keywords from the Description (dc:description) metadata field and then assign those as AI labels to the image. This makes the script ultimately suitable for users that have descriptions in their images but without assigned keywords. The script will then assign the keywords. Initial date: 7 feb 2025 Initial Author: IDimager Support Version History: Version: 1.0 Author: IDimager Support Date: 7 feb 2025 } procedure ExtractKeywordsFromText(ACatItem: TCatalogItem; AText: WideString); var AAI: TidBaseOpenAI; AResult: TidOpenAIResult; begin AResult := TidOpenAIResult.Create(nil); AAI := Publiccatalog.CreateOpenAIObject; if AAI.QueryKeywordsForText(AText, '', AResult) then begin { Say2( ACatItem.FileName + CrLf2W + AText, AResult.HierarchicalKeywords(CrLfW, '.') ); } PublicCatalog.AIOpenAI_ProcessResult(ACatItem, AResult, DefaultOpenAIResultHandling); end; AAI.Free; AResult.Free; end; procedure HandleItem(ACatItem: TCatalogItem); var AXmp: TXMP; ADescription: TMacroParam; begin AXmp := TXMP.Create(False); PublicCatalog.LoadXMPForItem(ACatItem, AXmp, PublicOptions.CachedXMP); ADescription := AXmp.FindDesignProperty('http://purl.org/dc/elements/1.1/', 'dc:description'); if ADescription <> nil then begin ExtractKeywordsFromText(ACatItem, ADescription.StrContent); end; AXmp.Free; end; procedure HandleImageItem(AImg: TImageItem); var ACatItem: TCatalogItem; begin // find the image in the catalog ACatItem := TCatalogItem.Create(nil); if PublicCatalog.FindItemCombinedByGUID(AImg.GUID, ACatItem) then HandleItem(ACatItem); ACatItem.Free; end; var i: Integer; APro: TxomProgress; begin if Selected.Count = 0 then begin Say('Select at least one thumbnail.'); exit; end; APro := TxomProgress.Create(nil); APro.Max := Selected.Count; APro.Pos := 0; APro.Caption := 'Detect keywords for Description'; for i := 0 to Selected.Count - 1 do begin APro.Pos := i + 1; if APro.Cancel then break; HandleImageItem(Selected.Items[i]); end; APro.Free; end;