reach-vb HF Staff sanchit-gandhi commited on
Commit
4b2e949
·
1 Parent(s): 0e268b1

Update app.py (#5)

Browse files

- Update app.py (75634697925a2f539634e0b6807b4d5ec1957e8b)


Co-authored-by: Sanchit Gandhi <[email protected]>

Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -1,7 +1,9 @@
1
  import torch
 
2
  import gradio as gr
3
- from transformers import pipeline
4
  import pytube as pt
 
 
5
 
6
  MODEL_NAME = "openai/whisper-small"
7
 
@@ -22,7 +24,6 @@ def transcribe(microphone, file_upload):
22
  "WARNING: You've uploaded an audio file and used the microphone. "
23
  "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
24
  )
25
- file = microphone
26
 
27
  elif (microphone is None) and (file_upload is None):
28
  return "ERROR: You have to either use the microphone or upload an audio file"
@@ -37,15 +38,13 @@ def transcribe(microphone, file_upload):
37
  def _return_yt_html_embed(yt_url):
38
  video_id = yt_url.split("?v=")[-1]
39
  HTML_str = (
40
- '<center><iframe width="500" height="320" src="https://www.youtube.com/embed/'
41
- + video_id
42
- + '"></iframe></center>'
43
  )
44
  return HTML_str
45
 
46
 
47
  def yt_transcribe(yt_url):
48
-
49
  yt = pt.YouTube(yt_url)
50
  html_embed_str = _return_yt_html_embed(yt_url)
51
  stream = yt.streams.filter(only_audio=True)[0]
@@ -67,29 +66,31 @@ mf_transcribe = gr.Interface(
67
  outputs="text",
68
  layout="horizontal",
69
  theme="huggingface",
70
- title="Whisper Audio Transcribe",
71
- description="Transcribe long audio/ microphone input (powered by 🤗transformers) with a click of a button!",
 
 
 
 
72
  allow_flagging="never",
73
  )
74
 
75
  yt_transcribe = gr.Interface(
76
  fn=yt_transcribe,
77
- inputs=[
78
- gr.inputs.Textbox(
79
- lines=1, placeholder="Paste a URL to YT video here", label="yt_url"
80
- )
81
- ],
82
  outputs=["html", "text"],
83
  layout="horizontal",
84
  theme="huggingface",
85
- title="Whisper YT Transcribe",
86
- description="Transcribe long YouTube videos (powered by 🤗transformers) with a click of a button!",
 
 
 
 
87
  allow_flagging="never",
88
  )
89
 
90
  with demo:
91
- gr.TabbedInterface(
92
- [mf_transcribe, yt_transcribe], ["Audio Transcribe", "YouTube Transcribe"]
93
- )
94
 
95
  demo.launch(enable_queue=True)
 
1
  import torch
2
+
3
  import gradio as gr
 
4
  import pytube as pt
5
+ from transformers import pipeline
6
+
7
 
8
  MODEL_NAME = "openai/whisper-small"
9
 
 
24
  "WARNING: You've uploaded an audio file and used the microphone. "
25
  "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
26
  )
 
27
 
28
  elif (microphone is None) and (file_upload is None):
29
  return "ERROR: You have to either use the microphone or upload an audio file"
 
38
  def _return_yt_html_embed(yt_url):
39
  video_id = yt_url.split("?v=")[-1]
40
  HTML_str = (
41
+ f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
42
+ " </center>"
 
43
  )
44
  return HTML_str
45
 
46
 
47
  def yt_transcribe(yt_url):
 
48
  yt = pt.YouTube(yt_url)
49
  html_embed_str = _return_yt_html_embed(yt_url)
50
  stream = yt.streams.filter(only_audio=True)[0]
 
66
  outputs="text",
67
  layout="horizontal",
68
  theme="huggingface",
69
+ title="Whisper Demo: Transcribe Audio",
70
+ description=(
71
+ "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the the fine-tuned"
72
+ f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
73
+ " of arbitrary length."
74
+ ),
75
  allow_flagging="never",
76
  )
77
 
78
  yt_transcribe = gr.Interface(
79
  fn=yt_transcribe,
80
+ inputs=[gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL")],
 
 
 
 
81
  outputs=["html", "text"],
82
  layout="horizontal",
83
  theme="huggingface",
84
+ title="Whisper Demo: Transcribe YouTube",
85
+ description=(
86
+ "Transcribe long-form YouTube videos with the click of a button! Demo uses the the fine-tuned checkpoint:"
87
+ f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files of"
88
+ " arbitrary length."
89
+ ),
90
  allow_flagging="never",
91
  )
92
 
93
  with demo:
94
+ gr.TabbedInterface([mf_transcribe, yt_transcribe], ["Transcribe Audio", "Transcribe YouTube"])
 
 
95
 
96
  demo.launch(enable_queue=True)