Noah Settersten commited on
Commit ·
8aae8fe
1
Parent(s): abaf246
refactor: Move more of the UI into separate components
Browse files
lib/medical_transcription_web/components/components.ex
CHANGED
|
@@ -4,6 +4,36 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
| 4 |
alias AudioTagger.Classifier.TagResult
|
| 5 |
use MedicalTranscriptionWeb, :verified_routes
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def result_list(assigns) do
|
| 8 |
~H"""
|
| 9 |
<div class="flex flex-col gap-14">
|
|
@@ -31,8 +61,8 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
| 31 |
~H"""
|
| 32 |
<div class="flex items-center gap-4 px-[14px] py-3 text-sm">
|
| 33 |
<div class="flex gap-3">
|
| 34 |
-
<.feedback_button code={@code} text={@text} response="true" />
|
| 35 |
-
<.feedback_button code={@code} text={@text} response="false" class="" />
|
| 36 |
</div>
|
| 37 |
|
| 38 |
<div
|
|
@@ -52,6 +82,7 @@ defmodule MedicalTranscriptionWeb.Components do
|
|
| 52 |
phx-click="add_feedback"
|
| 53 |
phx-value-code={@code}
|
| 54 |
phx-value-text={@text}
|
|
|
|
| 55 |
phx-value-response={@response}
|
| 56 |
type="button"
|
| 57 |
class="p-2 border border-button-deactivated-background rounded-lg hover:bg-slate-200"
|
|
|
|
| 4 |
alias AudioTagger.Classifier.TagResult
|
| 5 |
use MedicalTranscriptionWeb, :verified_routes
|
| 6 |
|
| 7 |
+
def upload_form(assigns) do
|
| 8 |
+
~H"""
|
| 9 |
+
<form id="audio-form" phx-submit="save" phx-change="validate">
|
| 10 |
+
<div class="flex items-center pb-4 border-b border-[#444444]/20">
|
| 11 |
+
<.live_file_input
|
| 12 |
+
class="file:text-sm file:rounded-full file:px-4 file:py-2 file:border-0 file:bg-brand file:hover:bg-brand-active file:text-white"
|
| 13 |
+
upload={@audio_upload}
|
| 14 |
+
/>
|
| 15 |
+
<button
|
| 16 |
+
name="submit-btn"
|
| 17 |
+
class="rounded-full bg-brand hover:bg-brand-active text-white py-2 px-4 font-light text-black"
|
| 18 |
+
>
|
| 19 |
+
Submit <span aria-hidden="true">→</span>
|
| 20 |
+
</button>
|
| 21 |
+
</div>
|
| 22 |
+
</form>
|
| 23 |
+
"""
|
| 24 |
+
end
|
| 25 |
+
|
| 26 |
+
def loading_message(assigns) do
|
| 27 |
+
~H"""
|
| 28 |
+
<%= if @visible do %>
|
| 29 |
+
<div class="flex gap-2 items-center p-2 rounded-md text-slate-800 text-sm bg-slate-200 border border-slate-300">
|
| 30 |
+
<.icon name="hero-arrow-path" class="w-4 h-4 animate-spin" />
|
| 31 |
+
<p>Transcribing and tagging audio file...</p>
|
| 32 |
+
</div>
|
| 33 |
+
<% end %>
|
| 34 |
+
"""
|
| 35 |
+
end
|
| 36 |
+
|
| 37 |
def result_list(assigns) do
|
| 38 |
~H"""
|
| 39 |
<div class="flex flex-col gap-14">
|
|
|
|
| 61 |
~H"""
|
| 62 |
<div class="flex items-center gap-4 px-[14px] py-3 text-sm">
|
| 63 |
<div class="flex gap-3">
|
| 64 |
+
<.feedback_button code={@code} text={@text} label={@label} response="true" />
|
| 65 |
+
<.feedback_button code={@code} text={@text} label={@label} response="false" class="" />
|
| 66 |
</div>
|
| 67 |
|
| 68 |
<div
|
|
|
|
| 82 |
phx-click="add_feedback"
|
| 83 |
phx-value-code={@code}
|
| 84 |
phx-value-text={@text}
|
| 85 |
+
phx-value-long-description={@label}
|
| 86 |
phx-value-response={@response}
|
| 87 |
type="button"
|
| 88 |
class="p-2 border border-button-deactivated-background rounded-lg hover:bg-slate-200"
|
lib/medical_transcription_web/live/home_live/index.ex
CHANGED
|
@@ -15,39 +15,19 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
| 15 |
|
| 16 |
@impl Phoenix.LiveView
|
| 17 |
def render(assigns) do
|
| 18 |
-
#
|
| 19 |
-
#
|
| 20 |
-
#
|
| 21 |
-
#
|
| 22 |
-
#
|
| 23 |
-
#
|
| 24 |
|
| 25 |
~H"""
|
| 26 |
-
<
|
| 27 |
-
<
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
upload={@uploads.audio}
|
| 32 |
-
/>
|
| 33 |
-
<button
|
| 34 |
-
name="submit-btn"
|
| 35 |
-
class="rounded-full bg-brand hover:bg-brand-active text-white py-2 px-4 font-light text-black"
|
| 36 |
-
>
|
| 37 |
-
Submit <span aria-hidden="true">→</span>
|
| 38 |
-
</button>
|
| 39 |
-
</div>
|
| 40 |
-
|
| 41 |
-
<%= if @transcription_in_progress do %>
|
| 42 |
-
<div class="flex gap-2 items-center p-2 rounded-md text-slate-800 text-sm bg-slate-200 border border-slate-300">
|
| 43 |
-
<.icon name="hero-arrow-path" class="w-4 h-4 animate-spin" />
|
| 44 |
-
<p>Transcribing and tagging audio file...</p>
|
| 45 |
-
</div>
|
| 46 |
-
<% end %>
|
| 47 |
-
|
| 48 |
-
<.result_list rows={@streams.transcription_rows} />
|
| 49 |
-
</div>
|
| 50 |
-
</form>
|
| 51 |
"""
|
| 52 |
end
|
| 53 |
|
|
@@ -65,8 +45,6 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
| 65 |
{:ok, dest}
|
| 66 |
end)
|
| 67 |
|
| 68 |
-
# Task async -> Audio Tagger -> get transcribed audio
|
| 69 |
-
|
| 70 |
uploaded_file = Enum.at(uploaded_files, 0)
|
| 71 |
live_view_pid = self()
|
| 72 |
|
|
@@ -114,7 +92,7 @@ defmodule MedicalTranscriptionWeb.HomeLive.Index do
|
|
| 114 |
{:noreply, assign(socket, :transcription_in_progress, false)}
|
| 115 |
end
|
| 116 |
|
| 117 |
-
|
| 118 |
MedicalTranscription.Transcriber.stream_transcription_and_search(
|
| 119 |
live_view_pid,
|
| 120 |
audio_file_path
|
|
|
|
| 15 |
|
| 16 |
@impl Phoenix.LiveView
|
| 17 |
def render(assigns) do
|
| 18 |
+
# Future ideas:
|
| 19 |
+
# - Fine-tune results based on feedback:
|
| 20 |
+
# - Allow users to accept/decline suggested codes.
|
| 21 |
+
# - Train model based on user feedback for suggested codes.
|
| 22 |
+
# - Allow editing the transcription inline to correct mistakes. Then, retag based on the updated transcription.
|
| 23 |
+
# - Stream audio recording instead of uploaded audio.
|
| 24 |
|
| 25 |
~H"""
|
| 26 |
+
<div class="flex flex-col space-y-6">
|
| 27 |
+
<.upload_form audio_upload={@uploads.audio} />
|
| 28 |
+
<.loading_message visible={@transcription_in_progress} />
|
| 29 |
+
<.result_list rows={@streams.transcription_rows} />
|
| 30 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
"""
|
| 32 |
end
|
| 33 |
|
|
|
|
| 45 |
{:ok, dest}
|
| 46 |
end)
|
| 47 |
|
|
|
|
|
|
|
| 48 |
uploaded_file = Enum.at(uploaded_files, 0)
|
| 49 |
live_view_pid = self()
|
| 50 |
|
|
|
|
| 92 |
{:noreply, assign(socket, :transcription_in_progress, false)}
|
| 93 |
end
|
| 94 |
|
| 95 |
+
defp transcribe_and_tag_audio(live_view_pid, audio_file_path) do
|
| 96 |
MedicalTranscription.Transcriber.stream_transcription_and_search(
|
| 97 |
live_view_pid,
|
| 98 |
audio_file_path
|