Update app.py
Browse files
app.py
CHANGED
|
@@ -38,13 +38,13 @@ def make_conversation_html(segments):
|
|
| 38 |
fg, bg = color_map[seg.speaker]
|
| 39 |
align = "flex-end" if speaker_list.index(seg.speaker) % 2 == 1 else "flex-start"
|
| 40 |
radius = "4px 16px 16px 16px" if align == "flex-start" else "16px 4px 16px 16px"
|
| 41 |
-
|
| 42 |
bubbles += (
|
| 43 |
f"<div style='display:flex;justify-content:{align};margin:6px 12px'>"
|
| 44 |
f"<div style='max-width:75%'>"
|
| 45 |
-
f"<div style='font-size:11px;color:#6b7280;margin-bottom:3px;{
|
| 46 |
f"<span style='font-weight:600;color:{fg}'>Speaker {seg.speaker}</span>"
|
| 47 |
-
f"&
|
| 48 |
f"<div style='background:{bg};border:1px solid {fg}30;color:#111827;"
|
| 49 |
f"padding:10px 14px;border-radius:{radius};font-size:14px;line-height:1.5'>"
|
| 50 |
f"{seg.text}</div></div></div>"
|
|
@@ -78,10 +78,10 @@ def make_table_html(segments):
|
|
| 78 |
f"font-family:system-ui,sans-serif'>"
|
| 79 |
f"<table style='width:100%;border-collapse:collapse'>"
|
| 80 |
f"<thead><tr style='background:#1e3a5f;color:white'>"
|
| 81 |
-
f"<th style='padding:10px 12px;text-align:left
|
| 82 |
-
f"<th style='padding:10px 12px;text-align:left
|
| 83 |
-
f"<th style='padding:10px 12px;text-align:left
|
| 84 |
-
f"<th style='padding:10px 12px;text-align:left
|
| 85 |
f"</tr></thead><tbody>{rows}</tbody></table></div>"
|
| 86 |
)
|
| 87 |
|
|
@@ -99,19 +99,16 @@ def process_audio(audio_path, num_speakers):
|
|
| 99 |
return "No speech detected.", "", ""
|
| 100 |
_last_segments = segments
|
| 101 |
unique = len(set(s.speaker for s in segments))
|
| 102 |
-
|
| 103 |
-
return status, make_conversation_html(segments), make_table_html(segments)
|
| 104 |
|
| 105 |
def export_json():
|
| 106 |
-
if not _last_segments:
|
| 107 |
-
return None
|
| 108 |
out = str(UPLOAD_DIR / "annotation.json")
|
| 109 |
to_json(_last_segments, out)
|
| 110 |
return out
|
| 111 |
|
| 112 |
def export_csv():
|
| 113 |
-
if not _last_segments:
|
| 114 |
-
return None
|
| 115 |
out = str(UPLOAD_DIR / "annotation.csv")
|
| 116 |
to_csv(_last_segments, out)
|
| 117 |
return out
|
|
@@ -132,7 +129,7 @@ with gr.Blocks(title="Speech Annotation Pipeline") as demo:
|
|
| 132 |
csv_file = gr.File(label="CSV Download")
|
| 133 |
with gr.Column(scale=2):
|
| 134 |
gr.Markdown("### Conversation View")
|
| 135 |
-
conversation_html = gr.HTML(value="<div style='height:480px;border:1px solid #e5e7eb;border-radius:12px;display:flex;align-items:center;justify-content:center;color:#9ca3af
|
| 136 |
gr.Markdown("### Segment Table")
|
| 137 |
table_html = gr.HTML(value="")
|
| 138 |
|
|
|
|
| 38 |
fg, bg = color_map[seg.speaker]
|
| 39 |
align = "flex-end" if speaker_list.index(seg.speaker) % 2 == 1 else "flex-start"
|
| 40 |
radius = "4px 16px 16px 16px" if align == "flex-start" else "16px 4px 16px 16px"
|
| 41 |
+
ta = "text-align:right;" if align == "flex-end" else ""
|
| 42 |
bubbles += (
|
| 43 |
f"<div style='display:flex;justify-content:{align};margin:6px 12px'>"
|
| 44 |
f"<div style='max-width:75%'>"
|
| 45 |
+
f"<div style='font-size:11px;color:#6b7280;margin-bottom:3px;{ta}'>"
|
| 46 |
f"<span style='font-weight:600;color:{fg}'>Speaker {seg.speaker}</span>"
|
| 47 |
+
f" · {seg.start_fmt} → {seg.end_fmt}</div>"
|
| 48 |
f"<div style='background:{bg};border:1px solid {fg}30;color:#111827;"
|
| 49 |
f"padding:10px 14px;border-radius:{radius};font-size:14px;line-height:1.5'>"
|
| 50 |
f"{seg.text}</div></div></div>"
|
|
|
|
| 78 |
f"font-family:system-ui,sans-serif'>"
|
| 79 |
f"<table style='width:100%;border-collapse:collapse'>"
|
| 80 |
f"<thead><tr style='background:#1e3a5f;color:white'>"
|
| 81 |
+
f"<th style='padding:10px 12px;text-align:left'>Speaker</th>"
|
| 82 |
+
f"<th style='padding:10px 12px;text-align:left'>Start</th>"
|
| 83 |
+
f"<th style='padding:10px 12px;text-align:left'>End</th>"
|
| 84 |
+
f"<th style='padding:10px 12px;text-align:left'>Transcript</th>"
|
| 85 |
f"</tr></thead><tbody>{rows}</tbody></table></div>"
|
| 86 |
)
|
| 87 |
|
|
|
|
| 99 |
return "No speech detected.", "", ""
|
| 100 |
_last_segments = segments
|
| 101 |
unique = len(set(s.speaker for s in segments))
|
| 102 |
+
return f"Done - {len(segments)} segments, {unique} speaker(s) detected", make_conversation_html(segments), make_table_html(segments)
|
|
|
|
| 103 |
|
| 104 |
def export_json():
|
| 105 |
+
if not _last_segments: return None
|
|
|
|
| 106 |
out = str(UPLOAD_DIR / "annotation.json")
|
| 107 |
to_json(_last_segments, out)
|
| 108 |
return out
|
| 109 |
|
| 110 |
def export_csv():
|
| 111 |
+
if not _last_segments: return None
|
|
|
|
| 112 |
out = str(UPLOAD_DIR / "annotation.csv")
|
| 113 |
to_csv(_last_segments, out)
|
| 114 |
return out
|
|
|
|
| 129 |
csv_file = gr.File(label="CSV Download")
|
| 130 |
with gr.Column(scale=2):
|
| 131 |
gr.Markdown("### Conversation View")
|
| 132 |
+
conversation_html = gr.HTML(value="<div style='height:480px;border:1px solid #e5e7eb;border-radius:12px;display:flex;align-items:center;justify-content:center;color:#9ca3af'>Transcript will appear here after processing</div>")
|
| 133 |
gr.Markdown("### Segment Table")
|
| 134 |
table_html = gr.HTML(value="")
|
| 135 |
|