Vadym Myroshnyk commited on
Commit ·
dff263a
1
Parent(s): fb9b11c
save
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
from rapidfuzz import fuzz
|
| 5 |
|
|
@@ -37,18 +36,22 @@ with gr.Blocks(theme="soft") as demo:
|
|
| 37 |
</span>
|
| 38 |
""")
|
| 39 |
|
| 40 |
-
|
| 41 |
@gr.render(inputs=[week_dropdown, current_index, dialogue_state])
|
| 42 |
def render_transcription_inputs(week, index, inputs):
|
| 43 |
audio_path = audio_structure[week][0]
|
| 44 |
transcript_path = audio_path.replace(".mp3", ".txt").replace("audio", "transcripts")
|
| 45 |
lines = load_dialogue_lines(transcript_path) if os.path.exists(transcript_path) else []
|
| 46 |
|
|
|
|
| 47 |
if index < len(lines):
|
| 48 |
speaker, _ = lines[index]
|
| 49 |
inputs = [(index, speaker, "")] + inputs
|
| 50 |
index += 1
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
textboxes = []
|
| 53 |
feedback_outputs = []
|
| 54 |
diff_outputs = []
|
|
@@ -62,12 +65,8 @@ with gr.Blocks(theme="soft") as demo:
|
|
| 62 |
diff_outputs.append(diff)
|
| 63 |
feedback_outputs.append(fb)
|
| 64 |
|
| 65 |
-
button_label = "➕ Add next speaker" if index < len(lines) else "✅ Check"
|
| 66 |
-
action_btn = gr.Button(button_label)
|
| 67 |
-
|
| 68 |
def on_add(*user_inputs):
|
| 69 |
-
updated_inputs = [(line_index, speaker, user_inputs[i]) for i, (line_index, speaker, _) in
|
| 70 |
-
enumerate(inputs)]
|
| 71 |
return index, updated_inputs
|
| 72 |
|
| 73 |
def on_check(*user_inputs):
|
|
@@ -100,13 +99,13 @@ with gr.Blocks(theme="soft") as demo:
|
|
| 100 |
|
| 101 |
return highlights + feedback + [average_score_box.update(value=average_html)]
|
| 102 |
|
|
|
|
| 103 |
if index < len(lines):
|
| 104 |
action_btn.click(fn=on_add, inputs=textboxes, outputs=[current_index, dialogue_state])
|
| 105 |
else:
|
| 106 |
action_btn.click(fn=on_check, inputs=textboxes,
|
| 107 |
outputs=diff_outputs + feedback_outputs + [average_score_box])
|
| 108 |
|
| 109 |
-
|
| 110 |
demo.load(lambda: None)
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from rapidfuzz import fuzz
|
| 4 |
|
|
|
|
| 36 |
</span>
|
| 37 |
""")
|
| 38 |
|
|
|
|
| 39 |
@gr.render(inputs=[week_dropdown, current_index, dialogue_state])
|
| 40 |
def render_transcription_inputs(week, index, inputs):
|
| 41 |
audio_path = audio_structure[week][0]
|
| 42 |
transcript_path = audio_path.replace(".mp3", ".txt").replace("audio", "transcripts")
|
| 43 |
lines = load_dialogue_lines(transcript_path) if os.path.exists(transcript_path) else []
|
| 44 |
|
| 45 |
+
# Add new speaker to the top
|
| 46 |
if index < len(lines):
|
| 47 |
speaker, _ = lines[index]
|
| 48 |
inputs = [(index, speaker, "")] + inputs
|
| 49 |
index += 1
|
| 50 |
|
| 51 |
+
# Button at the top before textboxes
|
| 52 |
+
button_label = "➕ Add next speaker" if index < len(lines) else "✅ Check"
|
| 53 |
+
action_btn = gr.Button(button_label)
|
| 54 |
+
|
| 55 |
textboxes = []
|
| 56 |
feedback_outputs = []
|
| 57 |
diff_outputs = []
|
|
|
|
| 65 |
diff_outputs.append(diff)
|
| 66 |
feedback_outputs.append(fb)
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
def on_add(*user_inputs):
|
| 69 |
+
updated_inputs = [(line_index, speaker, user_inputs[i]) for i, (line_index, speaker, _) in enumerate(inputs)]
|
|
|
|
| 70 |
return index, updated_inputs
|
| 71 |
|
| 72 |
def on_check(*user_inputs):
|
|
|
|
| 99 |
|
| 100 |
return highlights + feedback + [average_score_box.update(value=average_html)]
|
| 101 |
|
| 102 |
+
# Action binding
|
| 103 |
if index < len(lines):
|
| 104 |
action_btn.click(fn=on_add, inputs=textboxes, outputs=[current_index, dialogue_state])
|
| 105 |
else:
|
| 106 |
action_btn.click(fn=on_check, inputs=textboxes,
|
| 107 |
outputs=diff_outputs + feedback_outputs + [average_score_box])
|
| 108 |
|
|
|
|
| 109 |
demo.load(lambda: None)
|
| 110 |
|
| 111 |
if __name__ == "__main__":
|