Spaces:
Running
on
Zero
Running
on
Zero
versae
commited on
Commit
•
07ebfb1
0
Parent(s):
Duplicate from NbAiLab/whisper-sami-demo
Browse files- .gitattributes +34 -0
- README.md +15 -0
- app.py +103 -0
- packages.txt +1 -0
- requirements.txt +3 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Whisper Northern Sámi Demo
|
3 |
+
emoji: 🤫
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.9.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
tags:
|
11 |
+
- whisper-event
|
12 |
+
duplicated_from: NbAiLab/whisper-sami-demo
|
13 |
+
---
|
14 |
+
|
15 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import torch
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import pytube as pt
|
7 |
+
from transformers import pipeline
|
8 |
+
from huggingface_hub import model_info
|
9 |
+
|
10 |
+
MODEL_NAME = "NbAiLab/whisper-large-sme" #this always needs to stay in line 8 :D sorry for the hackiness
|
11 |
+
lang = "fi"
|
12 |
+
|
13 |
+
share = (os.environ.get("SHARE", "False")[0].lower() in "ty1") or None
|
14 |
+
auth_token = os.environ.get("AUTH_TOKEN") or True
|
15 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
16 |
+
pipe = pipeline(
|
17 |
+
task="automatic-speech-recognition",
|
18 |
+
model=MODEL_NAME,
|
19 |
+
chunk_length_s=30,
|
20 |
+
device=device,
|
21 |
+
use_auth_token=auth_token,
|
22 |
+
)
|
23 |
+
|
24 |
+
pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
|
25 |
+
|
26 |
+
def transcribe(microphone, file_upload):
|
27 |
+
warn_output = ""
|
28 |
+
if (microphone is not None) and (file_upload is not None):
|
29 |
+
warn_output = (
|
30 |
+
"WARNING: You've uploaded an audio file and used the microphone. "
|
31 |
+
"The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
32 |
+
)
|
33 |
+
|
34 |
+
elif (microphone is None) and (file_upload is None):
|
35 |
+
return "ERROR: You have to either use the microphone or upload an audio file"
|
36 |
+
|
37 |
+
file = microphone if microphone is not None else file_upload
|
38 |
+
|
39 |
+
text = pipe(file)["text"]
|
40 |
+
|
41 |
+
return warn_output + text
|
42 |
+
|
43 |
+
|
44 |
+
def _return_yt_html_embed(yt_url):
|
45 |
+
video_id = yt_url.split("?v=")[-1]
|
46 |
+
HTML_str = (
|
47 |
+
f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
|
48 |
+
" </center>"
|
49 |
+
)
|
50 |
+
return HTML_str
|
51 |
+
|
52 |
+
|
53 |
+
def yt_transcribe(yt_url):
|
54 |
+
yt = pt.YouTube(yt_url)
|
55 |
+
html_embed_str = _return_yt_html_embed(yt_url)
|
56 |
+
stream = yt.streams.filter(only_audio=True)[0]
|
57 |
+
stream.download(filename="audio.mp3")
|
58 |
+
|
59 |
+
text = pipe("audio.mp3")["text"]
|
60 |
+
|
61 |
+
return html_embed_str, text
|
62 |
+
|
63 |
+
|
64 |
+
demo = gr.Blocks()
|
65 |
+
|
66 |
+
mf_transcribe = gr.Interface(
|
67 |
+
fn=transcribe,
|
68 |
+
inputs=[
|
69 |
+
gr.inputs.Audio(source="microphone", type="filepath", optional=True),
|
70 |
+
gr.inputs.Audio(source="upload", type="filepath", optional=True),
|
71 |
+
],
|
72 |
+
outputs="text",
|
73 |
+
layout="horizontal",
|
74 |
+
theme="huggingface",
|
75 |
+
title="Whisper Demo: Transcribe Audio",
|
76 |
+
description=(
|
77 |
+
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the the fine-tuned"
|
78 |
+
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
79 |
+
" of arbitrary length."
|
80 |
+
),
|
81 |
+
allow_flagging="never",
|
82 |
+
)
|
83 |
+
|
84 |
+
yt_transcribe = gr.Interface(
|
85 |
+
fn=yt_transcribe,
|
86 |
+
inputs=[gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL")],
|
87 |
+
examples=[["https://www.youtube.com/watch?v=mukeSSa5GKo"]],
|
88 |
+
outputs=["html", "text"],
|
89 |
+
layout="horizontal",
|
90 |
+
theme="huggingface",
|
91 |
+
title="Whisper Demo: Transcribe YouTube",
|
92 |
+
description=(
|
93 |
+
"Transcribe long-form YouTube videos with the click of a button! Demo uses the the fine-tuned checkpoint:"
|
94 |
+
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files of"
|
95 |
+
" arbitrary length."
|
96 |
+
),
|
97 |
+
allow_flagging="never",
|
98 |
+
)
|
99 |
+
|
100 |
+
with demo:
|
101 |
+
gr.TabbedInterface([mf_transcribe, yt_transcribe], ["Transcribe Audio", "Transcribe YouTube"])
|
102 |
+
|
103 |
+
demo.launch(enable_queue=True, share=True)
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ffmpeg
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/huggingface/transformers
|
2 |
+
torch
|
3 |
+
pytube
|