From c1a7c9df44740746f6afdc57d1cb2131b7888705 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 19 Jan 2026 15:24:29 +0000 Subject: [PATCH] Include record embedding text on collection show page --- lib/music_library/records/similarity.ex | 7 +++++++ .../components/core_components.ex | 14 +++++++++++++- lib/music_library_web/live/collection_live/show.ex | 7 +++++++ .../live/collection_live/show.html.heex | 1 + priv/gettext/default.pot | 10 ++++++++++ priv/gettext/en/LC_MESSAGES/default.po | 10 ++++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/music_library/records/similarity.ex b/lib/music_library/records/similarity.ex index 37ec5b3c..76b8ed8e 100644 --- a/lib/music_library/records/similarity.ex +++ b/lib/music_library/records/similarity.ex @@ -132,6 +132,13 @@ defmodule MusicLibrary.Records.Similarity do end end + def get_embedding_text(record_id) do + case Repo.get_by(RecordEmbedding, record_id: record_id) do + nil -> {:error, :not_found} + embedding -> {:ok, embedding.text_representation} + end + end + @doc """ Stores an embedding for a record. """ diff --git a/lib/music_library_web/components/core_components.ex b/lib/music_library_web/components/core_components.ex index 7d87b561..5787ef4e 100644 --- a/lib/music_library_web/components/core_components.ex +++ b/lib/music_library_web/components/core_components.ex @@ -111,7 +111,19 @@ defmodule MusicLibraryWeb.CoreComponents do ~H"""
{@title} -
<%= Jason.encode!(@data, pretty: true) %>
+
{Jason.encode!(@data, pretty: true)}
+
+ """ + end + + attr :title, :string, required: true + attr :data, :string, required: true + + def text_viewer(assigns) do + ~H""" +
+ {@title} + {@data}
""" end diff --git a/lib/music_library_web/live/collection_live/show.ex b/lib/music_library_web/live/collection_live/show.ex index fc8e110b..ebe78d8d 100644 --- a/lib/music_library_web/live/collection_live/show.ex +++ b/lib/music_library_web/live/collection_live/show.ex @@ -38,6 +38,12 @@ defmodule MusicLibraryWeb.CollectionLive.Show do last_listened_track = Records.get_last_listened_track(record) play_count = Records.play_count(record) || 0 + embedding_text = + case Similarity.get_embedding_text(id) do + {:ok, text} -> text + {:error, _reason} -> gettext("Not available") + end + socket = if record.selected_release_id do socket @@ -49,6 +55,7 @@ defmodule MusicLibraryWeb.CollectionLive.Show do socket |> assign(:page_title, page_title(socket.assigns.live_action, record)) |> assign(:record, record) + |> assign(:embedding_text, embedding_text) |> assign(:last_listened_track, last_listened_track) |> assign(:play_count, play_count) |> assign_similar_records()} 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 f8870672..e4e29f70 100644 --- a/lib/music_library_web/live/collection_live/show.html.heex +++ b/lib/music_library_web/live/collection_live/show.html.heex @@ -355,6 +355,7 @@ /> <.json_viewer title={gettext("MusicBrainz data")} data={@record.musicbrainz_data} /> + <.text_viewer title={gettext("Record Embedding")} data={@embedding_text} /> <.live_component id="release-with-tracks" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index cf0bf470..fd7bee2b 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -1680,3 +1680,13 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Running optimize..." msgstr "" + +#: lib/music_library_web/live/collection_live/show.html.heex +#, elixir-autogen, elixir-format +msgid "Record Embedding" +msgstr "" + +#: lib/music_library_web/live/collection_live/show.ex +#, elixir-autogen, elixir-format +msgid "Not available" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 2b35dcdd..47b39a53 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -1680,3 +1680,13 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Running optimize..." msgstr "" + +#: lib/music_library_web/live/collection_live/show.html.heex +#, elixir-autogen, elixir-format +msgid "Record Embedding" +msgstr "" + +#: lib/music_library_web/live/collection_live/show.ex +#, elixir-autogen, elixir-format, fuzzy +msgid "Not available" +msgstr ""