birgermoell sanchit-gandhi HF staff commited on
Commit
c356543
0 Parent(s):

Duplicate from sanchit-gandhi/whisper-small-sv-bm

Browse files

Co-authored-by: Sanchit Gandhi <sanchit-gandhi@users.noreply.huggingface.co>

Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +59 -0
  4. packages.txt +2 -0
  5. requirements.txt +4 -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,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Whisper Small Sv Bm
3
+ emoji: 🇸🇪
4
+ colorFrom: yellow
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.9.1
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: sanchit-gandhi/whisper-small-sv-bm
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+ import librosa
5
+ import soundfile
6
+
7
+ SAMPLE_RATE = 16000
8
+
9
+ pipe = pipeline(model="birgermoell/whisper-small-sv-bm") # change to "your-username/the-name-you-picked"
10
+
11
+
12
+ def process_audio_file(file):
13
+ data, sr = librosa.load(file)
14
+
15
+ if sr != SAMPLE_RATE:
16
+ data = librosa.resample(data, sr, SAMPLE_RATE)
17
+
18
+ # monochannel
19
+ data = librosa.to_mono(data)
20
+ return data
21
+
22
+
23
+ def transcribe(Microphone, File_Upload):
24
+ warn_output = ""
25
+ if (Microphone is not None) and (File_Upload is not None):
26
+ warn_output = "WARNING: You've uploaded an audio file and used the microphone. " \
27
+ "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
28
+ file = Microphone
29
+
30
+ elif (Microphone is None) and (File_Upload is None):
31
+ return "ERROR: You have to either use the microphone or upload an audio file"
32
+
33
+ elif Microphone is not None:
34
+ file = Microphone
35
+ else:
36
+ file = File_Upload
37
+
38
+ audio_data = process_audio_file(file)
39
+
40
+ text = pipe(audio_data)["text"]
41
+
42
+ return warn_output + text
43
+
44
+
45
+ iface = gr.Interface(
46
+ fn=transcribe,
47
+ inputs=[
48
+ gr.inputs.Audio(source="microphone", type='filepath', optional=True),
49
+ gr.inputs.Audio(source="upload", type='filepath', optional=True),
50
+ ],
51
+ outputs="text",
52
+ layout="horizontal",
53
+ theme="huggingface",
54
+ title="Whisper Small SV",
55
+ description="Demo for Swedish speech recognition using the [Whisper Small SV BM checkpoint](https://huggingface.co/birgermoell/whisper-small-sv-bm).",
56
+ allow_flagging='never',
57
+ )
58
+
59
+ iface.launch(enable_queue=True)
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ffmpeg
2
+ libsndfile1
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ soundfile
3
+ torch
4
+ librosa