Vishal Patil commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,12 +16,11 @@ def process_audio(audio_path, num_speakers, min_speakers, max_speakers):
|
|
| 16 |
|
| 17 |
try:
|
| 18 |
pipeline = get_pipeline()
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
| 25 |
except Exception as e:
|
| 26 |
return f"❌ Error: {e}\n{traceback.format_exc()}", "", ""
|
| 27 |
|
|
@@ -45,8 +44,8 @@ def process_audio(audio_path, num_speakers, min_speakers, max_speakers):
|
|
| 45 |
<th style='text-align:left;padding:8px'>Transcript</th></tr>
|
| 46 |
</thead><tbody>{rows}</tbody></table>"""
|
| 47 |
|
| 48 |
-
|
| 49 |
-
return f"✅ Done — {len(segments)} segments, {
|
| 50 |
|
| 51 |
|
| 52 |
def export_json():
|
|
@@ -70,26 +69,12 @@ with gr.Blocks(title="Speech Annotation Pipeline") as demo:
|
|
| 70 |
|
| 71 |
with gr.Row():
|
| 72 |
with gr.Column():
|
| 73 |
-
audio_input = gr.Audio(
|
| 74 |
-
label="Upload Audio (.wav/.mp3/.flac)",
|
| 75 |
-
type="filepath"
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
gr.Markdown("### 🎯 Speaker Settings")
|
| 79 |
-
gr.
|
| 80 |
-
|
| 81 |
-
num_speakers = gr.Number(
|
| 82 |
-
label="Exact number of speakers (0 = auto-detect)",
|
| 83 |
-
value=0, precision=0
|
| 84 |
-
)
|
| 85 |
-
with gr.Row():
|
| 86 |
-
min_speakers = gr.Number(label="Min speakers", value=None, precision=0)
|
| 87 |
-
max_speakers = gr.Number(label="Max speakers", value=None, precision=0)
|
| 88 |
-
|
| 89 |
run_btn = gr.Button("▶ Run Annotation", variant="primary")
|
| 90 |
status_box = gr.Textbox(label="Status", interactive=False)
|
| 91 |
-
|
| 92 |
-
gr.Markdown("### 📥 Export Results")
|
| 93 |
with gr.Row():
|
| 94 |
json_btn = gr.Button("Export JSON")
|
| 95 |
csv_btn = gr.Button("Export CSV")
|
|
@@ -97,16 +82,14 @@ with gr.Blocks(title="Speech Annotation Pipeline") as demo:
|
|
| 97 |
csv_file = gr.File(label="CSV")
|
| 98 |
|
| 99 |
with gr.Column():
|
| 100 |
-
abab_box = gr.Textbox(
|
| 101 |
-
|
| 102 |
-
lines=20,
|
| 103 |
-
placeholder="Annotations will appear here..."
|
| 104 |
-
)
|
| 105 |
table_html = gr.HTML(label="Segment Table")
|
| 106 |
|
| 107 |
run_btn.click(
|
| 108 |
fn=process_audio,
|
| 109 |
-
inputs=[audio_input, num_speakers,
|
|
|
|
| 110 |
outputs=[status_box, abab_box, table_html]
|
| 111 |
)
|
| 112 |
json_btn.click(fn=export_json, inputs=[], outputs=[json_file])
|
|
|
|
| 16 |
|
| 17 |
try:
|
| 18 |
pipeline = get_pipeline()
|
| 19 |
+
n = int(num_speakers) if num_speakers and int(num_speakers) > 0 else 0
|
| 20 |
+
mn = int(min_speakers) if min_speakers and int(min_speakers) > 0 else None
|
| 21 |
+
mx = int(max_speakers) if max_speakers and int(max_speakers) > 0 else None
|
| 22 |
+
segments = pipeline.process(audio_path, num_speakers=n,
|
| 23 |
+
min_speakers=mn, max_speakers=mx)
|
|
|
|
| 24 |
except Exception as e:
|
| 25 |
return f"❌ Error: {e}\n{traceback.format_exc()}", "", ""
|
| 26 |
|
|
|
|
| 44 |
<th style='text-align:left;padding:8px'>Transcript</th></tr>
|
| 45 |
</thead><tbody>{rows}</tbody></table>"""
|
| 46 |
|
| 47 |
+
unique = len(set(s.speaker for s in segments))
|
| 48 |
+
return f"✅ Done — {len(segments)} segments, {unique} speaker(s) detected", abab, table
|
| 49 |
|
| 50 |
|
| 51 |
def export_json():
|
|
|
|
| 69 |
|
| 70 |
with gr.Row():
|
| 71 |
with gr.Column():
|
| 72 |
+
audio_input = gr.Audio(label="Upload Audio (.wav/.mp3/.flac)", type="filepath")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
gr.Markdown("### 🎯 Speaker Settings")
|
| 74 |
+
num_speakers = gr.Slider(minimum=0, maximum=10, step=1, value=0,
|
| 75 |
+
label="Number of speakers (0 = auto-detect)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
run_btn = gr.Button("▶ Run Annotation", variant="primary")
|
| 77 |
status_box = gr.Textbox(label="Status", interactive=False)
|
|
|
|
|
|
|
| 78 |
with gr.Row():
|
| 79 |
json_btn = gr.Button("Export JSON")
|
| 80 |
csv_btn = gr.Button("Export CSV")
|
|
|
|
| 82 |
csv_file = gr.File(label="CSV")
|
| 83 |
|
| 84 |
with gr.Column():
|
| 85 |
+
abab_box = gr.Textbox(label="Editable Transcript (ABAB)", lines=20,
|
| 86 |
+
placeholder="Annotations will appear here...")
|
|
|
|
|
|
|
|
|
|
| 87 |
table_html = gr.HTML(label="Segment Table")
|
| 88 |
|
| 89 |
run_btn.click(
|
| 90 |
fn=process_audio,
|
| 91 |
+
inputs=[audio_input, num_speakers,
|
| 92 |
+
gr.State(0), gr.State(0)],
|
| 93 |
outputs=[status_box, abab_box, table_html]
|
| 94 |
)
|
| 95 |
json_btn.click(fn=export_json, inputs=[], outputs=[json_file])
|