Spaces:
Running
Running
Update app.py
Browse fileschanged to gr.Interface()
app.py
CHANGED
@@ -7,13 +7,15 @@ import ffmpeg # Make sure it's ffmpeg-python
|
|
7 |
# Check if GPU is available
|
8 |
use_gpu = torch.cuda.is_available()
|
9 |
|
|
|
10 |
# Configure the pipeline to use the GPU if available
|
11 |
if use_gpu:
|
12 |
p = pipeline("automatic-speech-recognition",
|
13 |
-
|
14 |
else:
|
15 |
p = pipeline("automatic-speech-recognition",
|
16 |
-
|
|
|
17 |
|
18 |
def extract_audio_from_m3u8(url):
|
19 |
try:
|
@@ -23,7 +25,8 @@ def extract_audio_from_m3u8(url):
|
|
23 |
except Exception as e:
|
24 |
return f"An error occurred: {e}"
|
25 |
|
26 |
-
|
|
|
27 |
if m3u8_url:
|
28 |
audio = extract_audio_from_m3u8(m3u8_url)
|
29 |
|
@@ -31,48 +34,36 @@ def transcribe_function(audio, state, uploaded_audio, m3u8_url):
|
|
31 |
audio = uploaded_audio
|
32 |
|
33 |
if not audio:
|
34 |
-
return
|
35 |
|
36 |
try:
|
37 |
time.sleep(3)
|
38 |
text = p(audio, chunk_length_s= 50)["text"]
|
39 |
state += text + "\n"
|
40 |
-
return
|
41 |
except Exception as e:
|
42 |
-
return
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
transcribe_function,
|
68 |
-
[microphone, state_var, uploaded_audio, m3u8_url],
|
69 |
-
[transcription_var, state_var]
|
70 |
-
)
|
71 |
-
|
72 |
-
reset_button.click(
|
73 |
-
reset_output,
|
74 |
-
[transcription_var, state_var],
|
75 |
-
[transcription_var, state_var]
|
76 |
-
)
|
77 |
-
|
78 |
-
demo.launch()
|
|
|
7 |
# Check if GPU is available
|
8 |
use_gpu = torch.cuda.is_available()
|
9 |
|
10 |
+
|
11 |
# Configure the pipeline to use the GPU if available
|
12 |
if use_gpu:
|
13 |
p = pipeline("automatic-speech-recognition",
|
14 |
+
model="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h", device=0)
|
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:
|
|
|
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 |
|
|
|
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"]
|
42 |
state += text + "\n"
|
43 |
+
return state, state
|
44 |
except Exception as e:
|
45 |
+
return "An error occurred during transcription.", state # Handle other exceptions
|
46 |
+
|
47 |
+
|
48 |
+
def reset(state):
|
49 |
+
state = ''
|
50 |
+
return state
|
51 |
+
|
52 |
+
|
53 |
+
demo = gr.Interface(
|
54 |
+
fn=transcribe,
|
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 |
+
|
66 |
+
live=True)
|
67 |
+
|
68 |
+
|
69 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|