Skip to content

Commit

Permalink
Merge pull request #16 from bmachek/7-feature-improve-ai-photo-captio…
Browse files Browse the repository at this point in the history
…ns-with-optional-context-input-or-metadata

7 feature improve ai photo captions with optional context input or metadata
  • Loading branch information
bmachek authored Jan 1, 2025
2 parents 53ccb40 + 581ef71 commit 8208f7d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lrc-ai-assistant.lrplugin/AiModelAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ function AiModelAPI:new()
return instance
end

function AiModelAPI:analyzeImage(filePath)
return self.usedApi:analyzeImage(filePath)
function AiModelAPI:analyzeImage(filePath, metadata)
return self.usedApi:analyzeImage(filePath, metadata)
end
14 changes: 12 additions & 2 deletions lrc-ai-assistant.lrplugin/GeminiAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,18 @@ function GeminiAPI:doRequest(filePath, task, systemInstruction, generationConfig
end


function GeminiAPI:analyzeImage(filePath)
local success, result, inputTokenCount, outputTokenCount = GeminiAPI:doRequest(filePath, Defaults.defaultTask, Defaults.defaultSystemInstruction, Defaults.getDefaultGenerationConfig())
function GeminiAPI:analyzeImage(filePath, metadata)
local task = Defaults.defaultTask
if metadata ~= nil then
if metadata.gps ~= nil then
task = task .. " " .. LOC "$$$/lrc-ai-assistant/GeminiAPI/gpsAddon=This photo was taken at the following coordinates:" .. metadata.gps.latitude .. ", " .. metadata.gps.longitude
end
if metadata.keywords ~= nil then
task = task .. " " .. LOC "$$$/lrc-ai-assistant/GeminiAPI/keywordAddon=Some keywords are:" .. metadata.keywords
end
end

local success, result, inputTokenCount, outputTokenCount = GeminiAPI:doRequest(filePath, task, Defaults.defaultSystemInstruction, Defaults.getDefaultGenerationConfig())
if success and result ~= nil then
result = string.gsub(result, Defaults.geminiKeywordsGarbageAtStart, '')
result = string.gsub(result, Defaults.geminiKeywordsGarbageAtEnd, '')
Expand Down
9 changes: 7 additions & 2 deletions lrc-ai-assistant.lrplugin/GenerateImageInfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ local function exportAndAnalyzePhoto(photo, progressScope)
LR_size_units = 'pixels',
LR_collisionHandling = 'rename',
LR_includeVideoFiles = false,
LR_removeLocationMetadata = false,
LR_removeLocationMetadata = true,
LR_embeddedMetadataOption = "all",
}

Expand All @@ -188,8 +188,13 @@ local function exportAndAnalyzePhoto(photo, progressScope)

for _, rendition in exportSession:renditions() do
local success, path = rendition:waitForRender()
local metadata = {}

metadata.gps = photo:getRawMetadata("gps")
metadata.keywords = photo:getFormattedMetadata("keywordTagsForExport")

if success then
local analyzeSuccess, result, inputTokens, outputTokens = ai:analyzeImage(path)
local analyzeSuccess, result, inputTokens, outputTokens = ai:analyzeImage(path, metadata)

if result == 'RATE_LIMIT_EXHAUSTED' then
LrDialogs.showError(LOC "$$$/lrc-ai-assistant/GenerateImageInfo/rateLimit=Quota exhausted, set up pay as you go at Google, or wait for some hours.")
Expand Down
4 changes: 3 additions & 1 deletion lrc-ai-assistant.lrplugin/TranslatedStrings_de.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"$$$/lrc-ai-assistant/Defaults/defaultSystemInstruction=Du analysierst Bilder für Photo Management. Sei spezifisch und exakt. Generiere maximal 25 einzigartige Stichwörter."
"$$$/lrc-ai-assistant/Defaults/defaultTask=Beschreibe den Bildinhalt inklusive aller erkannten Gegenstände"
"$$$/lrc-ai-assistant/GeminiAPI/NoAPIkey=Kein Gemini API key eingetragen im Zusatzmodul-Manager."
"$$$/lrc-ai-assistant/GeminiAPI/gpsAddon=Dieses Foto wurde an den folgenden Koordinaten aufgenommen: "
"$$$/lrc-ai-assistant/GeminiAPI/keywordAddon=Einige Stichwörter sind:"
"$$$/lrc-ai-assistant/GenerateImageInfo/SkipFromHere=Die folgenden ohne Überprüfung speichern."
"$$$/lrc-ai-assistant/GenerateImageInfo/UsedTokenDialog/GeneratedCosts=Erzeugte Kosten"
"$$$/lrc-ai-assistant/GenerateImageInfo/UsedTokenDialog/Title=Verursachte Kosten"
Expand All @@ -44,4 +46,4 @@
"$$$/lrc-ai-assistant/PluginInfoDialogSections/keywords=Stichwörter"
"$$$/lrc-ai-assistant/PluginInfoDialogSections/showCosts=Kosten anzeigen (Ohne jegliche Garantie!!!)"
"$$$/lrc-ai-assistant/PluginInfoDialogSections/title=Titel"
"$$$/lrc-ai-assistant/PluginInfoDialogSections/validateBeforeSaving=Vor dem Speichern überprüfen","
"$$$/lrc-ai-assistant/PluginInfoDialogSections/validateBeforeSaving=Vor dem Speichern überprüfen"
4 changes: 3 additions & 1 deletion lrc-ai-assistant.lrplugin/TranslatedStrings_en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"$$$/lrc-ai-assistant/Defaults/defaultSystemInstruction=You are classifying images for photo management. Be very specific an detailed. Do not return more than 25 unique keywords."
"$$$/lrc-ai-assistant/Defaults/defaultTask=Describe the image contents, including all recognized objects."
"$$$/lrc-ai-assistant/GeminiAPI/NoAPIkey=No Gemini API key configured in add-ons manager."
"$$$/lrc-ai-assistant/GeminiAPI/gpsAddon=This photo was taken at the following coordinates: "
"$$$/lrc-ai-assistant/GeminiAPI/keywordAddon=Some keywords are:"
"$$$/lrc-ai-assistant/GenerateImageInfo/SkipFromHere=Save following without reviewing."
"$$$/lrc-ai-assistant/GenerateImageInfo/UsedTokenDialog/GeneratedCosts=Generated costs"
"$$$/lrc-ai-assistant/GenerateImageInfo/UsedTokenDialog/Title=Generation costs"
Expand All @@ -44,4 +46,4 @@
"$$$/lrc-ai-assistant/PluginInfoDialogSections/keywords=Keywords"
"$$$/lrc-ai-assistant/PluginInfoDialogSections/showCosts=Show costs (without any warranty!!!)"
"$$$/lrc-ai-assistant/PluginInfoDialogSections/title=Title"
"$$$/lrc-ai-assistant/PluginInfoDialogSections/validateBeforeSaving=Validate before saving"
"$$$/lrc-ai-assistant/PluginInfoDialogSections/validateBeforeSaving=Validate before saving"

0 comments on commit 8208f7d

Please sign in to comment.