Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,14 +5,27 @@ from pytube import YouTube
|
|
5 |
|
6 |
|
7 |
pipe = pipeline(model="irena/whisper-small-sv-SE")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
|
10 |
-
def yt(link):
|
11 |
-
yt = YouTube(link)
|
12 |
-
stream = yt.streams.filter(only_audio=True)[0]
|
13 |
-
stream.download(filename="audio.mp3")
|
14 |
-
text = pipe("audio.mp3")["text"]
|
15 |
-
return text
|
16 |
|
17 |
def transcribe(audio):
|
18 |
text = pipe(audio)["text"]
|
@@ -29,16 +42,38 @@ iface = gr.Interface(
|
|
29 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model. An audio for recognize.",
|
30 |
)
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
)
|
40 |
|
41 |
with demo:
|
42 |
gr.TabbedInterface([iface, yt], ["Transcribe Audio", "Transcribe YouTube"])
|
43 |
|
44 |
-
demo.launch(enable_queue=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
pipe = pipeline(model="irena/whisper-small-sv-SE")
|
8 |
+
def main_generator(youtube_id:str):
|
9 |
+
YouTubeID = youtube_id.split("https://www.youtube.com/watch?v=") #
|
10 |
+
if len(YouTubeID)>1:
|
11 |
+
YouTubeID = YouTubeID[1]
|
12 |
+
else:
|
13 |
+
YouTubeID ='xOZM-1p-jAk'
|
14 |
+
|
15 |
+
OutputFile = f'test_audio_youtube_{YouTubeID}.m4a'
|
16 |
+
|
17 |
+
os.system(f"youtube-dl -o {OutputFile} {YouTubeID} --extract-audio --restrict-filenames -f 'bestaudio[ext=m4a]'")
|
18 |
+
|
19 |
+
result = model_whisper.transcribe(OutputFile)
|
20 |
+
text = result['text']
|
21 |
+
|
22 |
+
output_list = []
|
23 |
+
|
24 |
+
output_list.append(text)
|
25 |
+
|
26 |
+
return text
|
27 |
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
def transcribe(audio):
|
31 |
text = pipe(audio)["text"]
|
|
|
42 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model. An audio for recognize.",
|
43 |
)
|
44 |
|
45 |
+
inputs = [gr.Textbox(lines=1, placeholder="Link of youtube video here...", label="Input")]
|
46 |
+
outputs = gr.HighlightedText()
|
47 |
+
title="ASR FOR SPANISH MEDICAL RECORDS"
|
48 |
+
description = "This demo uses AI Models to create an AUDIO ANNOTATION FOR MEDICAL RECORDS"
|
49 |
+
examples = ['https://www.youtube.com/watch?v=xOZM-1p-jAk']
|
50 |
+
io = gr.Interface(fn=main_generator, inputs=inputs, outputs=outputs, title=title, description = description, examples = examples,
|
51 |
+
|
52 |
+
css= """.gr-button-primary { background: -webkit-linear-gradient(
|
53 |
+
90deg, #355764 0%, #55a8a1 100% ) !important; background: #355764;
|
54 |
+
background: linear-gradient(
|
55 |
+
90deg, #355764 0%, #55a8a1 100% ) !important;
|
56 |
+
background: -moz-linear-gradient( 90deg, #355764 0%, #55a8a1 100% ) !important;
|
57 |
+
background: -webkit-linear-gradient(
|
58 |
+
90deg, #355764 0%, #55a8a1 100% ) !important;
|
59 |
+
color:white !important}"""
|
60 |
+
)
|
61 |
|
|
|
62 |
|
63 |
with demo:
|
64 |
gr.TabbedInterface([iface, yt], ["Transcribe Audio", "Transcribe YouTube"])
|
65 |
|
66 |
+
demo.launch(enable_queue=True)
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
|