Tanel commited on
Commit
29f2174
·
verified ·
1 Parent(s): 6f149e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -9,7 +9,7 @@ from transformers.pipelines.audio_utils import ffmpeg_read
9
  import tempfile
10
  import os
11
 
12
- MODEL_NAME = "openai/whisper-large-v3-turbo"
13
  BATCH_SIZE = 8
14
  FILE_LIMIT_MB = 1000
15
  YT_LENGTH_LIMIT_S = 3600 # limit to 1 hour YouTube files
@@ -25,11 +25,11 @@ pipe = pipeline(
25
 
26
 
27
  @spaces.GPU
28
- def transcribe(inputs, task):
29
  if inputs is None:
30
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
31
 
32
- text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
33
  return text
34
 
35
 
@@ -73,7 +73,7 @@ def download_yt_audio(yt_url, filename):
73
  raise gr.Error(str(err))
74
 
75
  @spaces.GPU
76
- def yt_transcribe(yt_url, task, max_filesize=75.0):
77
  html_embed_str = _return_yt_html_embed(yt_url)
78
 
79
  with tempfile.TemporaryDirectory() as tmpdirname:
@@ -85,7 +85,7 @@ def yt_transcribe(yt_url, task, max_filesize=75.0):
85
  inputs = ffmpeg_read(inputs, pipe.feature_extractor.sampling_rate)
86
  inputs = {"array": inputs, "sampling_rate": pipe.feature_extractor.sampling_rate}
87
 
88
- text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
89
 
90
  return html_embed_str, text
91
 
@@ -95,11 +95,10 @@ demo = gr.Blocks(theme=gr.themes.Ocean())
95
  mf_transcribe = gr.Interface(
96
  fn=transcribe,
97
  inputs=[
98
- gr.Audio(sources="microphone", type="filepath"),
99
- gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
100
  ],
101
  outputs="text",
102
- title="Whisper Large V3 Turbo: Transcribe Audio",
103
  description=(
104
  "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
105
  f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
@@ -111,11 +110,10 @@ mf_transcribe = gr.Interface(
111
  file_transcribe = gr.Interface(
112
  fn=transcribe,
113
  inputs=[
114
- gr.Audio(sources="upload", type="filepath", label="Audio file"),
115
- gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
116
  ],
117
  outputs="text",
118
- title="Whisper Large V3: Transcribe Audio",
119
  description=(
120
  "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
121
  f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
@@ -127,11 +125,10 @@ file_transcribe = gr.Interface(
127
  yt_transcribe = gr.Interface(
128
  fn=yt_transcribe,
129
  inputs=[
130
- gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
131
- gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
132
  ],
133
  outputs=["html", "text"],
134
- title="Whisper Large V3: Transcribe YouTube",
135
  description=(
136
  "Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
137
  f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
 
9
  import tempfile
10
  import os
11
 
12
+ MODEL_NAME = "TalTechNLP/whisper-large-v3-et-subs"
13
  BATCH_SIZE = 8
14
  FILE_LIMIT_MB = 1000
15
  YT_LENGTH_LIMIT_S = 3600 # limit to 1 hour YouTube files
 
25
 
26
 
27
  @spaces.GPU
28
+ def transcribe(inputs):
29
  if inputs is None:
30
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
31
 
32
+ text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": "transcribe", "language": "et"}, return_timestamps=True)["text"]
33
  return text
34
 
35
 
 
73
  raise gr.Error(str(err))
74
 
75
  @spaces.GPU
76
+ def yt_transcribe(yt_url, max_filesize=75.0):
77
  html_embed_str = _return_yt_html_embed(yt_url)
78
 
79
  with tempfile.TemporaryDirectory() as tmpdirname:
 
85
  inputs = ffmpeg_read(inputs, pipe.feature_extractor.sampling_rate)
86
  inputs = {"array": inputs, "sampling_rate": pipe.feature_extractor.sampling_rate}
87
 
88
+ text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": "transcribe", "language": "et"}, return_timestamps=True)["text"]
89
 
90
  return html_embed_str, text
91
 
 
95
  mf_transcribe = gr.Interface(
96
  fn=transcribe,
97
  inputs=[
98
+ gr.Audio(sources="microphone", type="filepath")
 
99
  ],
100
  outputs="text",
101
+ title="Generate Estonian subtitles",
102
  description=(
103
  "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
104
  f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
 
110
  file_transcribe = gr.Interface(
111
  fn=transcribe,
112
  inputs=[
113
+ gr.Audio(sources="upload", type="filepath", label="Audio file")
 
114
  ],
115
  outputs="text",
116
+ title="Generate Estonian subtitles",
117
  description=(
118
  "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
119
  f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
 
125
  yt_transcribe = gr.Interface(
126
  fn=yt_transcribe,
127
  inputs=[
128
+ gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL")
 
129
  ],
130
  outputs=["html", "text"],
131
+ title="Generate Estonian subtitles",
132
  description=(
133
  "Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
134
  f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"