diff --git a/lib/music_library_web/live/collection_live/show.ex b/lib/music_library_web/live/collection_live/show.ex index e731b680..69f3c2bc 100644 --- a/lib/music_library_web/live/collection_live/show.ex +++ b/lib/music_library_web/live/collection_live/show.ex @@ -142,6 +142,25 @@ defmodule MusicLibraryWeb.CollectionLive.Show do end end + def handle_event("regenerate_embeddings", %{"id" => id}, socket) do + record = Records.get_record!(id) + + case Similarity.generate_embedding_async(record) do + {:ok, _worker} -> + {:noreply, + socket + |> put_toast(:info, gettext("In progress - record will update automatically"))} + + {:error, reason} -> + {:noreply, + socket + |> put_toast( + :error, + gettext("Error") <> "," <> inspect(reason) + )} + end + end + @impl true def handle_info({MusicLibraryWeb.Components.RecordForm, {:saved, record}}, socket) do {:noreply, diff --git a/lib/music_library_web/live/collection_live/show.html.heex b/lib/music_library_web/live/collection_live/show.html.heex index e4e29f70..a14b0732 100644 --- a/lib/music_library_web/live/collection_live/show.html.heex +++ b/lib/music_library_web/live/collection_live/show.html.heex @@ -104,6 +104,19 @@ {gettext("Populate genres")} + <.dropdown_link + id={"actions-#{@record.id}-regenerate-embeddings"} + phx-click={JS.push("regenerate_embeddings", value: %{id: @record.id})} + > + <.icon + name="hero-sparkles" + class="h-4 w-4 mr-1 phx-click-loading:animate-shake" + aria-hidden="true" + data-slot="icon" + /> + {gettext("Regenerate embeddings")} + + <.dropdown_link id={"actions-#{@record.id}-extract-colors-fast"} phx-click={JS.push("extract_colors", value: %{id: @record.id, method: :fast})} diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index be4a7b81..2e7a7908 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -1682,3 +1682,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Not available" msgstr "" + +#: lib/music_library_web/live/collection_live/show.html.heex +#, elixir-autogen, elixir-format +msgid "Regenerate embeddings" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 40670248..3428a541 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -1682,3 +1682,8 @@ msgstr "" #, elixir-autogen, elixir-format, fuzzy msgid "Not available" msgstr "" + +#: lib/music_library_web/live/collection_live/show.html.heex +#, elixir-autogen, elixir-format, fuzzy +msgid "Regenerate embeddings" +msgstr ""