Vishal Patil commited on
Commit
2970b9d
·
verified ·
1 Parent(s): cfd07c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -42
app.py CHANGED
@@ -12,34 +12,21 @@ _last_segments = []
12
  def process_audio(audio_path, num_speakers):
13
  global _last_segments
14
  if audio_path is None:
15
- return "⚠️ Please upload an audio file first.", "", ""
16
  try:
17
  pipeline = get_pipeline()
18
  n = int(num_speakers) if num_speakers and int(num_speakers) > 0 else 0
19
  segments = pipeline.process(audio_path, num_speakers=n)
20
  except Exception as e:
21
- return f"❌ Error: {e}\n{traceback.format_exc()}", "", ""
22
 
23
  if not segments:
24
- return "⚠️ No speech detected.", "", ""
25
 
26
  _last_segments = segments
27
  abab = to_abab_text(segments)
28
- rows = "".join(
29
- f"<tr style='background:{'#f0f4ff' if i%2==0 else 'white'}'>"
30
- f"<td style='padding:6px 8px;font-weight:bold;color:#1e3a5f'>{s.speaker}</td>"
31
- f"<td style='padding:6px 8px'>{s.start_fmt}</td>"
32
- f"<td style='padding:6px 8px'>{s.end_fmt}</td>"
33
- f"<td style='padding:6px 8px'>{s.text}</td></tr>"
34
- for i, s in enumerate(segments)
35
- )
36
- table = f"""<table style='width:100%;border-collapse:collapse;font-size:14px'>
37
- <thead style='background:#1e3a5f;color:white'>
38
- <tr><th style='padding:8px'>Speaker</th><th>Start</th><th>End</th>
39
- <th style='text-align:left;padding:8px'>Transcript</th></tr>
40
- </thead><tbody>{rows}</tbody></table>"""
41
  unique = len(set(s.speaker for s in segments))
42
- return f"✅ Done — {len(segments)} segments, {unique} speaker(s) detected", abab, table
43
 
44
 
45
  def export_json():
@@ -61,36 +48,23 @@ with gr.Blocks(title="Speech Annotation Pipeline") as demo:
61
  gr.Markdown("# 🎙️ Speech Annotation Pipeline")
62
  gr.Markdown("Upload audio → get speaker-labeled transcripts automatically")
63
 
 
 
 
 
 
 
 
64
  with gr.Row():
65
- with gr.Column(scale=1):
66
- audio_input = gr.Audio(
67
- label="Upload Audio (.wav/.mp3/.flac)",
68
- type="filepath"
69
- )
70
- num_speakers = gr.Slider(
71
- minimum=0, maximum=10, step=1, value=0,
72
- label="Number of speakers (0 = auto-detect)"
73
- )
74
- run_btn = gr.Button("▶ Run Annotation", variant="primary")
75
- status_box = gr.Textbox(label="Status", interactive=False)
76
- with gr.Row():
77
- json_btn = gr.Button("Export JSON")
78
- csv_btn = gr.Button("Export CSV")
79
- json_file = gr.File(label="JSON Download")
80
- csv_file = gr.File(label="CSV Download")
81
-
82
- with gr.Column(scale=2):
83
- abab_box = gr.Textbox(
84
- label="Editable Transcript (ABAB)",
85
- lines=20,
86
- placeholder="Annotations will appear here..."
87
- )
88
- table_html = gr.HTML()
89
 
90
  run_btn.click(
91
  fn=process_audio,
92
  inputs=[audio_input, num_speakers],
93
- outputs=[status_box, abab_box, table_html]
94
  )
95
  json_btn.click(fn=export_json, inputs=[], outputs=[json_file])
96
  csv_btn.click(fn=export_csv, inputs=[], outputs=[csv_file])
 
12
  def process_audio(audio_path, num_speakers):
13
  global _last_segments
14
  if audio_path is None:
15
+ return "⚠️ Please upload an audio file first.", ""
16
  try:
17
  pipeline = get_pipeline()
18
  n = int(num_speakers) if num_speakers and int(num_speakers) > 0 else 0
19
  segments = pipeline.process(audio_path, num_speakers=n)
20
  except Exception as e:
21
+ return f"❌ Error: {e}\n{traceback.format_exc()}", ""
22
 
23
  if not segments:
24
+ return "⚠️ No speech detected.", ""
25
 
26
  _last_segments = segments
27
  abab = to_abab_text(segments)
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  unique = len(set(s.speaker for s in segments))
29
+ return f"✅ Done — {len(segments)} segments, {unique} speaker(s) detected", abab
30
 
31
 
32
  def export_json():
 
48
  gr.Markdown("# 🎙️ Speech Annotation Pipeline")
49
  gr.Markdown("Upload audio → get speaker-labeled transcripts automatically")
50
 
51
+ audio_input = gr.Audio(label="Upload Audio (.wav/.mp3/.flac)", type="filepath")
52
+ num_speakers = gr.Slider(minimum=0, maximum=10, step=1, value=0,
53
+ label="Number of speakers (0 = auto-detect)")
54
+ run_btn = gr.Button("▶ Run Annotation", variant="primary")
55
+ status_box = gr.Textbox(label="Status", interactive=False)
56
+ abab_box = gr.Textbox(label="Editable Transcript (ABAB)", lines=20,
57
+ placeholder="Annotations will appear here...")
58
  with gr.Row():
59
+ json_btn = gr.Button("Export JSON")
60
+ csv_btn = gr.Button("Export CSV")
61
+ json_file = gr.File(label="JSON Download")
62
+ csv_file = gr.File(label="CSV Download")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  run_btn.click(
65
  fn=process_audio,
66
  inputs=[audio_input, num_speakers],
67
+ outputs=[status_box, abab_box]
68
  )
69
  json_btn.click(fn=export_json, inputs=[], outputs=[json_file])
70
  csv_btn.click(fn=export_csv, inputs=[], outputs=[csv_file])