noahsettersten commited on
Commit
f059b2f
1 Parent(s): 0249a13

feat: Generate vector embeddings from UI via GenServer

Browse files
Dockerfile CHANGED
@@ -68,7 +68,7 @@ RUN mix release
68
  FROM ${RUNNER_IMAGE}
69
 
70
  RUN apt-get update -y && \
71
- apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
72
  && apt-get clean && rm -f /var/lib/apt/lists/*_*
73
 
74
  # Set the locale
 
68
  FROM ${RUNNER_IMAGE}
69
 
70
  RUN apt-get update -y && \
71
+ apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates curl unzip \
72
  && apt-get clean && rm -f /var/lib/apt/lists/*_*
73
 
74
  # Set the locale
lib/medical_transcription/application.ex CHANGED
@@ -29,7 +29,8 @@ defmodule MedicalTranscription.Application do
29
  # Start a worker by calling: MedicalTranscription.Worker.start_link(arg)
30
  # {MedicalTranscription.Worker, arg},
31
  # Start to serve requests, typically the last entry
32
- MedicalTranscriptionWeb.Endpoint
 
33
  ]
34
 
35
  # See https://hexdocs.pm/elixir/Supervisor.html
 
29
  # Start a worker by calling: MedicalTranscription.Worker.start_link(arg)
30
  # {MedicalTranscription.Worker, arg},
31
  # Start to serve requests, typically the last entry
32
+ MedicalTranscriptionWeb.Endpoint,
33
+ MedicalTranscription.Vectorizer
34
  ]
35
 
36
  # See https://hexdocs.pm/elixir/Supervisor.html
lib/medical_transcription/vectorizer.ex ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ defmodule MedicalTranscription.Vectorizer do
2
+ use GenServer
3
+
4
+ # Client API
5
+ def start_link(_) do
6
+ GenServer.start_link(__MODULE__, :pending, name: MedicalTranscription.Vectorizer)
7
+ end
8
+
9
+ # Server callbacks
10
+ @impl GenServer
11
+ def init(state) do
12
+ IO.inspect(state, label: "Vectorizer GenServer started with state")
13
+
14
+ {:ok, state}
15
+ end
16
+
17
+ @impl GenServer
18
+ def handle_call(:get_status, _from, state) do
19
+ # Return an atom containing the current status
20
+ {:reply, state, state}
21
+ end
22
+
23
+ @impl GenServer
24
+ def handle_cast(:generate, state) do
25
+ if state == :pending do
26
+ send(self(), :generate)
27
+
28
+ {:noreply, :in_process}
29
+ else
30
+ # Do nothing
31
+ {:noreply, state}
32
+ end
33
+ end
34
+
35
+ @impl GenServer
36
+ def handle_info(:generate, _state) do
37
+ # Build the embeddings
38
+ IO.puts("Building vectors embeddings for ICD-9 codelist")
39
+
40
+ cached_download =
41
+ AudioTagger.SampleData.cache_dir()
42
+ |> Path.join("icd9_codelist.csv")
43
+
44
+ unless File.exists?(cached_download) do
45
+ AudioTagger.SampleData.get_icd9_code_list_csv()
46
+ end
47
+
48
+ AudioTagger.Vectors.precalculate(cached_download)
49
+
50
+ {:noreply, :complete}
51
+ end
52
+ end
lib/medical_transcription_web/components/layouts/app.html.heex CHANGED
@@ -9,10 +9,20 @@
9
  </h1>
10
  </div>
11
 
12
- <div class="px-6">
13
  <p class="text-xs leading-normal tracking-[0.2em] font-semibold uppercase">Today</p>
14
  <!-- TODO: Show a history of uploaded files here. -->
15
  </div>
 
 
 
 
 
 
 
 
 
 
16
  </header>
17
 
18
  <main class="flex-1 pl-16 pr-16 pt-[25px]">
 
9
  </h1>
10
  </div>
11
 
12
+ <div class="flex-1 px-6">
13
  <p class="text-xs leading-normal tracking-[0.2em] font-semibold uppercase">Today</p>
14
  <!-- TODO: Show a history of uploaded files here. -->
15
  </div>
16
+
17
+ <div class="flex flex-col items-center">
18
+ <button
19
+ class="px-3 py-2 bg-brand text-white rounded-lg"
20
+ type="button"
21
+ phx-click="build_vector_embeddings"
22
+ >
23
+ Build vector embeddings
24
+ </button>
25
+ </div>
26
  </header>
27
 
28
  <main class="flex-1 pl-16 pr-16 pt-[25px]">
lib/medical_transcription_web/live/home_live/index.ex CHANGED
@@ -110,6 +110,13 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
110
  {:noreply, assign(socket, :status, :pending)}
111
  end
112
 
 
 
 
 
 
 
 
113
  @impl true
114
  def handle_info({:transcription_row, chunk_result}, socket) do
115
  # The processing sends a message as each chunk of text is coded. See here for some background and potential
 
110
  {:noreply, assign(socket, :status, :pending)}
111
  end
112
 
113
+ @impl Phoenix.LiveView
114
+ def handle_event("build_vector_embeddings", _params, socket) do
115
+ GenServer.cast(MedicalTranscription.Vectorizer, :generate)
116
+
117
+ {:noreply, socket}
118
+ end
119
+
120
  @impl true
121
  def handle_info({:transcription_row, chunk_result}, socket) do
122
  # The processing sends a message as each chunk of text is coded. See here for some background and potential
mix.lock CHANGED
@@ -1,5 +1,5 @@
1
  %{
2
- "audio_tagger": {:git, "https://github.com/headwayio/audio_tagger.git", "bf49e4d3cd86e0b7123423595818d23b1967ca69", []},
3
  "aws_signature": {:hex, :aws_signature, "0.3.1", "67f369094cbd55ffa2bbd8cc713ede14b195fcfb45c86665cd7c5ad010276148", [:rebar3], [], "hexpm", "50fc4dc1d1f7c2d0a8c63f455b3c66ecd74c1cf4c915c768a636f9227704a674"},
4
  "axon": {:hex, :axon, "0.6.0", "fd7560079581e4cedebaf0cd5f741d6ac3516d06f204ebaf1283b1093bf66ff6", [:mix], [{:kino, "~> 0.7", [hex: :kino, repo: "hexpm", optional: true]}, {:kino_vega_lite, "~> 0.1.7", [hex: :kino_vega_lite, repo: "hexpm", optional: true]}, {:nx, "~> 0.6.0", [hex: :nx, repo: "hexpm", optional: false]}, {:polaris, "~> 0.1", [hex: :polaris, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1", [hex: :table_rex, repo: "hexpm", optional: true]}], "hexpm", "204e7aeb50d231a30b25456adf17bfbaae33fe7c085e03793357ac3bf62fd853"},
5
  "bimap": {:hex, :bimap, "1.3.0", "3ea4832e58dc83a9b5b407c6731e7bae87458aa618e6d11d8e12114a17afa4b3", [:mix], [], "hexpm", "bf5a2b078528465aa705f405a5c638becd63e41d280ada41e0f77e6d255a10b4"},
 
1
  %{
2
+ "audio_tagger": {:git, "https://github.com/headwayio/audio_tagger.git", "70f8ce8abe45b4f26ddd3876bc935845823c3f8c", []},
3
  "aws_signature": {:hex, :aws_signature, "0.3.1", "67f369094cbd55ffa2bbd8cc713ede14b195fcfb45c86665cd7c5ad010276148", [:rebar3], [], "hexpm", "50fc4dc1d1f7c2d0a8c63f455b3c66ecd74c1cf4c915c768a636f9227704a674"},
4
  "axon": {:hex, :axon, "0.6.0", "fd7560079581e4cedebaf0cd5f741d6ac3516d06f204ebaf1283b1093bf66ff6", [:mix], [{:kino, "~> 0.7", [hex: :kino, repo: "hexpm", optional: true]}, {:kino_vega_lite, "~> 0.1.7", [hex: :kino_vega_lite, repo: "hexpm", optional: true]}, {:nx, "~> 0.6.0", [hex: :nx, repo: "hexpm", optional: false]}, {:polaris, "~> 0.1", [hex: :polaris, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1", [hex: :table_rex, repo: "hexpm", optional: true]}], "hexpm", "204e7aeb50d231a30b25456adf17bfbaae33fe7c085e03793357ac3bf62fd853"},
5
  "bimap": {:hex, :bimap, "1.3.0", "3ea4832e58dc83a9b5b407c6731e7bae87458aa618e6d11d8e12114a17afa4b3", [:mix], [], "hexpm", "bf5a2b078528465aa705f405a5c638becd63e41d280ada41e0f77e6d255a10b4"},