Commit
•
3748deb
1
Parent(s):
5505ef0
refactor: Move code search into TranscriptionTextComponent
Browse files
lib/medical_transcription/transcription.ex
CHANGED
@@ -1,18 +1,8 @@
|
|
1 |
defmodule MedicalTranscription.Transcription do
|
2 |
@moduledoc """
|
3 |
-
Takes a path to an audio file and transcribes it to text.
|
4 |
-
context to look for possible matching codes.
|
5 |
"""
|
6 |
|
7 |
-
alias MedicalTranscription.Coding
|
8 |
-
|
9 |
-
defp get_tags_and_send_result(chunk, index, live_view_pid) do
|
10 |
-
tags = Coding.process_chunk(chunk.text)
|
11 |
-
result = build_result(index, chunk, tags)
|
12 |
-
|
13 |
-
send(live_view_pid, {:transcription_row, result})
|
14 |
-
end
|
15 |
-
|
16 |
# Ideas for future exploration:
|
17 |
# - Instead of storing the long description vectors in a binary file on disk, we could store them within a vector DB
|
18 |
# (such as pgvector or Pinecone.io)
|
@@ -25,7 +15,7 @@ defmodule MedicalTranscription.Transcription do
|
|
25 |
audio_file_path
|
26 |
|> stream_transcription()
|
27 |
|> Enum.reduce("", fn {chunk, index}, acc ->
|
28 |
-
|
29 |
|
30 |
acc <> chunk.text
|
31 |
end)
|
@@ -36,7 +26,7 @@ defmodule MedicalTranscription.Transcription do
|
|
36 |
end_timestamp_seconds: nil
|
37 |
}
|
38 |
|
39 |
-
|
40 |
end
|
41 |
|
42 |
defp stream_transcription(audio_file_path) do
|
@@ -45,14 +35,15 @@ defmodule MedicalTranscription.Transcription do
|
|
45 |
|> Stream.with_index()
|
46 |
end
|
47 |
|
48 |
-
defp
|
49 |
-
%{
|
50 |
id: index,
|
51 |
start_mark: format_timestamp(chunk.start_timestamp_seconds),
|
52 |
end_mark: format_timestamp(chunk.end_timestamp_seconds),
|
53 |
-
text: chunk.text
|
54 |
-
tags: tags
|
55 |
}
|
|
|
|
|
56 |
end
|
57 |
|
58 |
defp format_timestamp(seconds) when is_nil(seconds), do: nil
|
|
|
1 |
defmodule MedicalTranscription.Transcription do
|
2 |
@moduledoc """
|
3 |
+
Takes a path to an audio file and transcribes it to text.
|
|
|
4 |
"""
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Ideas for future exploration:
|
7 |
# - Instead of storing the long description vectors in a binary file on disk, we could store them within a vector DB
|
8 |
# (such as pgvector or Pinecone.io)
|
|
|
15 |
audio_file_path
|
16 |
|> stream_transcription()
|
17 |
|> Enum.reduce("", fn {chunk, index}, acc ->
|
18 |
+
send_result(chunk, index + 1, live_view_pid)
|
19 |
|
20 |
acc <> chunk.text
|
21 |
end)
|
|
|
26 |
end_timestamp_seconds: nil
|
27 |
}
|
28 |
|
29 |
+
send_result(summary_chunk, 0, live_view_pid)
|
30 |
end
|
31 |
|
32 |
defp stream_transcription(audio_file_path) do
|
|
|
35 |
|> Stream.with_index()
|
36 |
end
|
37 |
|
38 |
+
defp send_result(chunk, index, live_view_pid) do
|
39 |
+
result = %{
|
40 |
id: index,
|
41 |
start_mark: format_timestamp(chunk.start_timestamp_seconds),
|
42 |
end_mark: format_timestamp(chunk.end_timestamp_seconds),
|
43 |
+
text: chunk.text
|
|
|
44 |
}
|
45 |
+
|
46 |
+
send(live_view_pid, {:transcription_row, result})
|
47 |
end
|
48 |
|
49 |
defp format_timestamp(seconds) when is_nil(seconds), do: nil
|
lib/medical_transcription_web/components/components.ex
CHANGED
@@ -149,7 +149,6 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
149 |
start_mark={row.start_mark}
|
150 |
end_mark={row.end_mark}
|
151 |
text={row.text}
|
152 |
-
tags={%Phoenix.LiveView.AsyncResult{ok?: true, result: row.tags}}
|
153 |
/>
|
154 |
<% end %>
|
155 |
</div>
|
|
|
149 |
start_mark={row.start_mark}
|
150 |
end_mark={row.end_mark}
|
151 |
text={row.text}
|
|
|
152 |
/>
|
153 |
<% end %>
|
154 |
</div>
|
lib/medical_transcription_web/components/transcription_text_component.ex
CHANGED
@@ -1,13 +1,16 @@
|
|
1 |
defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
2 |
@moduledoc """
|
3 |
-
Represents a portion of transcribed text
|
4 |
-
"""
|
5 |
|
6 |
-
|
|
|
7 |
use MedicalTranscriptionWeb, :live_component
|
|
|
8 |
import MedicalTranscriptionWeb.Components
|
9 |
import MedicalTranscriptionWeb.Components.KeywordHighlighter
|
|
|
10 |
alias AudioTagger.KeywordFinder
|
|
|
11 |
alias MedicalTranscription.Coding.CodeVectorMatch
|
12 |
|
13 |
@impl Phoenix.LiveComponent
|
@@ -17,22 +20,19 @@ defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
|
17 |
{:ok, socket}
|
18 |
end
|
19 |
|
20 |
-
defp assign_initial_state(
|
21 |
-
%{start_mark: start_mark, end_mark: end_mark, text: text, tags: tags},
|
22 |
-
socket
|
23 |
-
) do
|
24 |
self_pid = self()
|
25 |
|
26 |
initial_state = %{
|
27 |
start_mark: start_mark,
|
28 |
end_mark: end_mark,
|
29 |
text: text,
|
30 |
-
tags: tags,
|
31 |
editing: false
|
32 |
}
|
33 |
|
34 |
socket
|
35 |
|> assign(initial_state)
|
|
|
36 |
|> assign_async(:keywords, fn -> find_keywords(self_pid, text) end)
|
37 |
end
|
38 |
|
|
|
1 |
defmodule MedicalTranscriptionWeb.Components.TranscriptionTextComponent do
|
2 |
@moduledoc """
|
3 |
+
Represents a portion of transcribed text.
|
|
|
4 |
|
5 |
+
Once rendered, starts tasks to find relevant codes and keywords for the text.
|
6 |
+
"""
|
7 |
use MedicalTranscriptionWeb, :live_component
|
8 |
+
|
9 |
import MedicalTranscriptionWeb.Components
|
10 |
import MedicalTranscriptionWeb.Components.KeywordHighlighter
|
11 |
+
|
12 |
alias AudioTagger.KeywordFinder
|
13 |
+
alias MedicalTranscription.Coding
|
14 |
alias MedicalTranscription.Coding.CodeVectorMatch
|
15 |
|
16 |
@impl Phoenix.LiveComponent
|
|
|
20 |
{:ok, socket}
|
21 |
end
|
22 |
|
23 |
+
defp assign_initial_state(%{start_mark: start_mark, end_mark: end_mark, text: text}, socket) do
|
|
|
|
|
|
|
24 |
self_pid = self()
|
25 |
|
26 |
initial_state = %{
|
27 |
start_mark: start_mark,
|
28 |
end_mark: end_mark,
|
29 |
text: text,
|
|
|
30 |
editing: false
|
31 |
}
|
32 |
|
33 |
socket
|
34 |
|> assign(initial_state)
|
35 |
+
|> assign_async(:tags, fn -> classify_text(text) end)
|
36 |
|> assign_async(:keywords, fn -> find_keywords(self_pid, text) end)
|
37 |
end
|
38 |
|