abidlabs HF staff commited on
Commit
f0a0639
1 Parent(s): 471b1ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -28
app.py CHANGED
@@ -21,50 +21,31 @@ transcribe_token_id = all_special_ids[-5]
21
  translate_token_id = all_special_ids[-6]
22
 
23
 
24
- def transcribe(microphone, task):
25
  file = microphone
26
 
27
  pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id if task=="transcribe" else translate_token_id]]
28
 
29
  text = pipe(file)["text"]
30
 
31
- return warn_output + text
32
 
33
 
34
- def _return_yt_html_embed(yt_url):
35
- video_id = yt_url.split("?v=")[-1]
36
- HTML_str = (
37
- f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
38
- " </center>"
39
- )
40
- return HTML_str
41
-
42
-
43
- def yt_transcribe(yt_url, task):
44
- yt = pt.YouTube(yt_url)
45
- html_embed_str = _return_yt_html_embed(yt_url)
46
- stream = yt.streams.filter(only_audio=True)[0]
47
- stream.download(filename="audio.mp3")
48
-
49
- pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id if task=="transcribe" else translate_token_id]]
50
-
51
- text = pipe("audio.mp3")["text"]
52
-
53
- return html_embed_str, text
54
-
55
-
56
- demo = gr.Blocks()
57
 
58
  mf_transcribe = gr.Interface(
59
  fn=transcribe,
60
  inputs=[
61
  gr.Audio(source="microphone", type="filepath", optional=True),
62
- gr.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
63
  ],
64
- outputs="text",
 
 
 
65
  layout="horizontal",
66
  theme="huggingface",
67
  title="Whisper Large V2: Transcribe Audio",
 
68
  description=(
69
  "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
70
  f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
@@ -76,5 +57,5 @@ mf_transcribe = gr.Interface(
76
 
77
 
78
 
79
- demo.launch(enable_queue=True)
80
 
 
21
  translate_token_id = all_special_ids[-6]
22
 
23
 
24
+ def transcribe(microphone, state, task="transcribe"):
25
  file = microphone
26
 
27
  pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id if task=="transcribe" else translate_token_id]]
28
 
29
  text = pipe(file)["text"]
30
 
31
+ return state + "\n" text, state + "\n" text
32
 
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  mf_transcribe = gr.Interface(
36
  fn=transcribe,
37
  inputs=[
38
  gr.Audio(source="microphone", type="filepath", optional=True),
39
+ gr.State()
40
  ],
41
+ outputs=[
42
+ gr.Textbox(lines=15),
43
+ gr.State()]
44
+ ,
45
  layout="horizontal",
46
  theme="huggingface",
47
  title="Whisper Large V2: Transcribe Audio",
48
+ live=True,
49
  description=(
50
  "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
51
  f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
 
57
 
58
 
59
 
60
+ mf_transcribe.launch(enable_queue=True)
61