Neprox commited on
Commit
cad9f2f
1 Parent(s): f79cbc5

Add basic version of transcribing youtube video

Browse files
Files changed (2) hide show
  1. app.py +25 -4
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,15 +1,36 @@
1
  from transformers import pipeline
2
  import gradio as gr
 
 
3
 
4
- pipe = pipeline(model="Neprox/model") # change to "your-username/the-name-you-picked"
5
 
6
- def transcribe(audio):
7
- text = pipe(audio)["text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  return text
9
 
10
  iface = gr.Interface(
11
  fn=transcribe,
12
- inputs=gr.Audio(source="microphone", type="filepath"),
 
 
 
13
  outputs="text",
14
  title="Whisper Small Swedish",
15
  description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
 
1
  from transformers import pipeline
2
  import gradio as gr
3
+ from pytube import YouTube
4
+ from transformers import Dataset, Audio
5
 
6
+ pipe = pipeline(model="Neprox/model")
7
 
8
+ def transcribe(audio, url):
9
+ if url:
10
+ # Download YouTube video
11
+ streams = YouTube(url).streams.filter(only_audio=True, file_extension='mp4')
12
+ audio_fpath = streams.first().download()
13
+
14
+ # TODO:
15
+ # Process up to 10 minutes by segmenting into 30 second blocks
16
+ # Use pyMovie for selecting time ranges
17
+ # query every block individually
18
+ # Annotate text with timestamps
19
+
20
+ audio_dataset = Dataset.from_dict({"audio": [audio_fpath]}).cast_column("audio", Audio())
21
+ text = pipe(audio_dataset[0]["audio"])
22
+ return text
23
+
24
+ else:
25
+ text = pipe(audio)["text"]
26
  return text
27
 
28
  iface = gr.Interface(
29
  fn=transcribe,
30
+ inputs=[
31
+ gr.Audio(source="microphone", type="filepath")
32
+ gr.Text(max_lines=1, placeholder="Enter YouTube Link with Swedish speech to be transcribed")
33
+ ],
34
  outputs="text",
35
  title="Whisper Small Swedish",
36
  description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
requirements.txt CHANGED
@@ -4,3 +4,4 @@ librosa
4
  jiwer
5
  datasets
6
  torch
 
 
4
  jiwer
5
  datasets
6
  torch
7
+ git+https://github.com/pytube/pytube