Ritesh-hf commited on
Commit
a80b9b2
·
verified ·
1 Parent(s): 93228a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -21,11 +21,16 @@ def format_output_to_list(data):
21
  formatted_list = "\n".join([f"{item['timestamp'][0]}s - {item['timestamp'][1]}s \t : {item['text']}" for item in data])
22
  return formatted_list
23
 
24
- def transcribe(inputs, task):
25
  if inputs is None:
26
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
27
 
28
- output = pipe(inputs, batch_size=BATCH_SIZE, return_timestamps="word", generate_kwargs={"task": task})
 
 
 
 
 
29
  text = output['text']
30
  timestamps = format_output_to_list(output['chunks'])
31
  return [text, timestamps]
@@ -47,24 +52,25 @@ examples = [
47
  ]
48
 
49
  with gr.Blocks(theme=gr.themes.Default()) as demo:
50
- gr.HTML("<h1 style='text-align: center;'>Transcribe Audio with Timestamps using whisper-large-v3</h1>")
51
  gr.Markdown("")
52
  with gr.Row():
53
  with gr.Column():
54
  audio_input = gr.Audio(sources=["upload", 'microphone'], type="filepath", label="Audio file")
55
  task = gr.Radio(["transcribe", "translate"], label="Task")
 
56
  with gr.Row():
57
  clear_button = gr.ClearButton(value="Clear")
58
  submit_button = gr.Button("Submit", variant="primary", )
59
 
60
  with gr.Column():
61
  transcript_output = gr.Text(label="Transcript")
62
- timestamp_output = gr.Text(label="Timestamp")
63
 
64
- examples = gr.Examples(examples, inputs=audio_input, outputs=[transcript_output, timestamp_output], fn=transcribe, examples_per_page=20)
65
 
66
- submit_button.click(fn=transcribe, inputs=audio_input, outputs=[transcript_output, timestamp_output])
67
- clear_button.add([audio_input, transcript_output, timestamp_output])
68
 
69
 
70
  if __name__ == "__main__":
 
21
  formatted_list = "\n".join([f"{item['timestamp'][0]}s - {item['timestamp'][1]}s \t : {item['text']}" for item in data])
22
  return formatted_list
23
 
24
+ def transcribe(inputs, task, timestamp_type):
25
  if inputs is None:
26
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
27
 
28
+ if timestamp_type == "sentence":
29
+ timestamp_type = True
30
+ else:
31
+ timestamp_type = "word"
32
+
33
+ output = pipe(inputs, batch_size=BATCH_SIZE, return_timestamps=timestamp_type, generate_kwargs={"task": task})
34
  text = output['text']
35
  timestamps = format_output_to_list(output['chunks'])
36
  return [text, timestamps]
 
52
  ]
53
 
54
  with gr.Blocks(theme=gr.themes.Default()) as demo:
55
+ gr.HTML("<h2 style='text-align: center;'>Transcribing Audio with Timestamps using whisper-large-v3</h2>")
56
  gr.Markdown("")
57
  with gr.Row():
58
  with gr.Column():
59
  audio_input = gr.Audio(sources=["upload", 'microphone'], type="filepath", label="Audio file")
60
  task = gr.Radio(["transcribe", "translate"], label="Task")
61
+ timestamp_type = gr.Radio(["sentence", "word"], label="Timestamp Type")
62
  with gr.Row():
63
  clear_button = gr.ClearButton(value="Clear")
64
  submit_button = gr.Button("Submit", variant="primary", )
65
 
66
  with gr.Column():
67
  transcript_output = gr.Text(label="Transcript")
68
+ timestamp_output = gr.Text(label="Timestamps")
69
 
70
+ examples = gr.Examples(examples, inputs=[audio_input, task, timestamp_type], outputs=[transcript_output, timestamp_output], fn=transcribe, examples_per_page=20)
71
 
72
+ submit_button.click(fn=transcribe, inputs=[audio_input, task, timestamp_type], outputs=[transcript_output, timestamp_output])
73
+ clear_button.add([audio_input, task, timestamp_type, transcript_output, timestamp_output])
74
 
75
 
76
  if __name__ == "__main__":