lucamartinelli commited on
Commit
379a259
Β·
1 Parent(s): 727ff34
Files changed (2) hide show
  1. app.py +8 -9
  2. src/vtt_utils.py +8 -8
app.py CHANGED
@@ -73,7 +73,7 @@ def prepare_download(vtt_content: str, audio_filename: str) -> str | None:
73
  with open(download_path, 'w', encoding='utf-8') as f:
74
  f.write(vtt_content)
75
 
76
- return str(download_path)
77
 
78
 
79
  with gr.Blocks(title="Transcription & Diarization") as app:
@@ -132,17 +132,17 @@ with gr.Blocks(title="Transcription & Diarization") as app:
132
 
133
  validation_status = gr.Markdown("βšͺ No content", container=True)
134
 
135
- with gr.Row():
136
- clean_btn = gr.Button("Clean & improve VTT", variant="secondary", interactive=False)
137
- download_file = gr.File(label="Download VTT", visible=False)
138
- download_btn = gr.Button("Download VTT", variant="secondary", interactive=False)
139
-
140
- with gr.Accordion("🎭 Rename speakers", open=False):
141
  with gr.Row():
142
  old_speaker_name = gr.Textbox(label="Current speaker name (e.g., SPEAKER_00)", placeholder="SPEAKER_00", value="SPEAKER_00")
143
  new_speaker_name = gr.Textbox(label="New speaker name", placeholder="Davide")
144
 
145
  rename_btn = gr.Button("Rename")
 
 
 
 
 
146
 
147
  def check_inputs(openai_key: str, hf_key: str, audio) -> gr.Button:
148
  """
@@ -177,7 +177,7 @@ with gr.Blocks(title="Transcription & Diarization") as app:
177
  return (
178
  status,
179
  gr.Button(interactive=is_valid), # clean_btn
180
- gr.Button(interactive=is_valid) # download_btn
181
  )
182
 
183
  # Enable/disable submit button based on API keys and audio input
@@ -230,7 +230,6 @@ with gr.Blocks(title="Transcription & Diarization") as app:
230
  download_btn.click(
231
  fn=prepare_download,
232
  inputs=[output_vtt, audio_filename_state],
233
- outputs=[download_file]
234
  )
235
 
236
  # Speaker renaming
 
73
  with open(download_path, 'w', encoding='utf-8') as f:
74
  f.write(vtt_content)
75
 
76
+ return download_path
77
 
78
 
79
  with gr.Blocks(title="Transcription & Diarization") as app:
 
132
 
133
  validation_status = gr.Markdown("βšͺ No content", container=True)
134
 
135
+ with gr.Accordion("🎭 Rename speakers", open=True):
 
 
 
 
 
136
  with gr.Row():
137
  old_speaker_name = gr.Textbox(label="Current speaker name (e.g., SPEAKER_00)", placeholder="SPEAKER_00", value="SPEAKER_00")
138
  new_speaker_name = gr.Textbox(label="New speaker name", placeholder="Davide")
139
 
140
  rename_btn = gr.Button("Rename")
141
+
142
+ with gr.Row():
143
+ clean_btn = gr.Button("Fix", variant="secondary", interactive=False)
144
+ download_btn = gr.DownloadButton("Download", variant="primary", interactive=False)
145
+
146
 
147
  def check_inputs(openai_key: str, hf_key: str, audio) -> gr.Button:
148
  """
 
177
  return (
178
  status,
179
  gr.Button(interactive=is_valid), # clean_btn
180
+ gr.DownloadButton(interactive=is_valid) # download_btn
181
  )
182
 
183
  # Enable/disable submit button based on API keys and audio input
 
230
  download_btn.click(
231
  fn=prepare_download,
232
  inputs=[output_vtt, audio_filename_state],
 
233
  )
234
 
235
  # Speaker renaming
src/vtt_utils.py CHANGED
@@ -43,7 +43,7 @@ def validate_vtt(vtt_content: str) -> Tuple[str, str]:
43
  try:
44
  # Check if starts with WEBVTT
45
  if not vtt_content.strip().startswith("WEBVTT"):
46
- return "❌ Invalid: Missing WEBVTT header", "error"
47
 
48
  lines = vtt_content.split('\n')
49
  has_timestamps = False
@@ -58,7 +58,7 @@ def validate_vtt(vtt_content: str) -> Tuple[str, str]:
58
  # Validate timestamp format
59
  match = re.match(r'(\d{2}:\d{2}:\d{2}\.\d{3})\s*-->\s*(\d{2}:\d{2}:\d{2}\.\d{3})', line)
60
  if not match:
61
- return "⚠️ Warning: Malformed timestamp found", "warning"
62
 
63
  # Parse and validate timestamps
64
  start_str, end_str = match.groups()
@@ -66,26 +66,26 @@ def validate_vtt(vtt_content: str) -> Tuple[str, str]:
66
  end_ms = parse_timestamp(end_str)
67
 
68
  if start_ms is None or end_ms is None:
69
- return "⚠️ Warning: Invalid timestamp values", "warning"
70
 
71
  if start_ms >= end_ms:
72
- return "⚠️ Warning: Start timestamp >= end timestamp", "warning"
73
 
74
  timestamps.append((start_ms, end_ms))
75
 
76
  if not has_timestamps:
77
- return "❌ Invalid: No timestamps found", "error"
78
 
79
  # Check for overlapping timestamps
80
  for i in range(len(timestamps) - 1):
81
  current_end = timestamps[i][1]
82
  next_start = timestamps[i + 1][0]
83
  if current_end > next_start:
84
- return "⚠️ Warning: Overlapping timestamps detected", "warning"
85
 
86
- return "βœ… Valid VTT format", "success"
87
  except Exception as e:
88
- return f"❌ Validation error: {str(e)}", "error"
89
 
90
 
91
  def clean_vtt(vtt_content: str) -> str:
 
43
  try:
44
  # Check if starts with WEBVTT
45
  if not vtt_content.strip().startswith("WEBVTT"):
46
+ return "πŸ”΄ Invalid: Missing WEBVTT header", "error"
47
 
48
  lines = vtt_content.split('\n')
49
  has_timestamps = False
 
58
  # Validate timestamp format
59
  match = re.match(r'(\d{2}:\d{2}:\d{2}\.\d{3})\s*-->\s*(\d{2}:\d{2}:\d{2}\.\d{3})', line)
60
  if not match:
61
+ return "🟑 Warning: Malformed timestamp found", "warning"
62
 
63
  # Parse and validate timestamps
64
  start_str, end_str = match.groups()
 
66
  end_ms = parse_timestamp(end_str)
67
 
68
  if start_ms is None or end_ms is None:
69
+ return "🟑 Warning: Invalid timestamp values", "warning"
70
 
71
  if start_ms >= end_ms:
72
+ return "🟑 Warning: Start timestamp >= end timestamp", "warning"
73
 
74
  timestamps.append((start_ms, end_ms))
75
 
76
  if not has_timestamps:
77
+ return "πŸ”΄ Invalid: No timestamps found", "error"
78
 
79
  # Check for overlapping timestamps
80
  for i in range(len(timestamps) - 1):
81
  current_end = timestamps[i][1]
82
  next_start = timestamps[i + 1][0]
83
  if current_end > next_start:
84
+ return "🟑 Warning: Overlapping timestamps detected", "warning"
85
 
86
+ return "🟒 Valid", "success"
87
  except Exception as e:
88
+ return f"πŸ”΄ Validation error: {str(e)}", "error"
89
 
90
 
91
  def clean_vtt(vtt_content: str) -> str: