Eyðun Nielsen commited on
Commit
a2270aa
1 Parent(s): 266358f

Add new input: m3u8 URL | E.g.: from kvf.fo or logting.fo

Browse files
Files changed (2) hide show
  1. app.py +20 -4
  2. requirements.txt +3 -0
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import time
3
  from transformers import pipeline
4
  import torch
 
5
 
6
  # Check if GPU is available
7
  use_gpu = torch.cuda.is_available()
@@ -14,13 +15,27 @@ if use_gpu:
14
  else:
15
  p = pipeline("automatic-speech-recognition",
16
  model="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h")
17
-
18
 
19
- def transcribe(audio, state="", uploaded_audio=None):
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  if uploaded_audio is not None:
21
  audio = uploaded_audio
 
22
  if not audio:
23
  return state, state # Return a meaningful message
 
24
  try:
25
  time.sleep(3)
26
  text = p(audio, chunk_length_s= 50)["text"]
@@ -40,10 +55,11 @@ demo = gr.Interface(
40
  inputs=[
41
  gr.components.Audio(source="microphone", type="filepath"),
42
  'state',
43
- gr.components.Audio(label="Upload Audio File", type="filepath", source="upload")
 
44
  ],
45
  outputs=[
46
- "textbox",
47
  "state"
48
  ],
49
 
 
2
  import time
3
  from transformers import pipeline
4
  import torch
5
+ import ffmpeg # Make sure it's ffmpeg-python
6
 
7
  # Check if GPU is available
8
  use_gpu = torch.cuda.is_available()
 
15
  else:
16
  p = pipeline("automatic-speech-recognition",
17
  model="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h")
 
18
 
19
+
20
+ def extract_audio_from_m3u8(url):
21
+ try:
22
+ output_file = "output_audio.aac"
23
+ ffmpeg.input(url).output(output_file).run(overwrite_output=True)
24
+ return output_file
25
+ except Exception as e:
26
+ return f"An error occurred: {e}"
27
+
28
+
29
+ def transcribe(audio, state="", uploaded_audio=None, m3u8_url=""):
30
+ if m3u8_url:
31
+ audio = extract_audio_from_m3u8(m3u8_url)
32
+
33
  if uploaded_audio is not None:
34
  audio = uploaded_audio
35
+
36
  if not audio:
37
  return state, state # Return a meaningful message
38
+
39
  try:
40
  time.sleep(3)
41
  text = p(audio, chunk_length_s= 50)["text"]
 
55
  inputs=[
56
  gr.components.Audio(source="microphone", type="filepath"),
57
  'state',
58
+ gr.components.Audio(label="Upload Audio File", type="filepath", source="upload"),
59
+ gr.components.Textbox(label="m3u8 URL | E.g.: from kvf.fo or logting.fo")
60
  ],
61
  outputs=[
62
+ gr.components.Textbox(type="text"),
63
  "state"
64
  ],
65
 
requirements.txt CHANGED
@@ -1,2 +1,5 @@
1
  torch
2
  transformers
 
 
 
 
1
  torch
2
  transformers
3
+ gradio
4
+ ffmpeg-python
5
+ ffmpeg