GetmanY1 commited on
Commit
99ef49e
Β·
1 Parent(s): 78b55cc

Initial commit

Browse files
Files changed (3) hide show
  1. README.md +2 -2
  2. app.py +45 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
- title: Finnish Asr
3
  emoji: πŸ†
4
- colorFrom: green
5
  colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 5.23.3
 
1
  ---
2
+ title: Finnish ASR
3
  emoji: πŸ†
4
+ colorFrom: red
5
  colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 5.23.3
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from librosa import resample
4
+ import numpy as np
5
+
6
+ def transcribe(input_audio, model_id):
7
+ pipe = pipeline(
8
+ "automatic-speech-recognition",
9
+ model=model_id,
10
+ device="cpu"
11
+ )
12
+ sr, speech = input_audio
13
+ # Convert to mono if stereo
14
+ if speech.ndim > 1:
15
+ speech = speech.mean(axis=1)
16
+ # Convert to float32 if needed
17
+ if speech.dtype != "float32":
18
+ speech = speech.astype(np.float32)
19
+ # Resample if sampling rate is not 16kHz
20
+ if sr!=16000:
21
+ speech = resample(speech, orig_sr=sr, target_sr=16000)
22
+ output = pipe(speech, chunk_length_s=30, stride_length_s=5)['text']
23
+ return output
24
+
25
+ model_ids_list = [
26
+ "GetmanY1/wav2vec2-base-fi-150k-finetuned",
27
+ "GetmanY1/wav2vec2-large-fi-150k-finetuned",
28
+ "GetmanY1/wav2vec2-xlarge-fi-150k-finetuned"
29
+ ]
30
+
31
+ gradio_app = gr.Interface(
32
+ fn=transcribe,
33
+ inputs=[gr.Audio(sources=["upload","microphone"]), gr.Dropdown(model_ids_list)],
34
+ outputs="text",
35
+ title="Finnish Automatic Speech Recognition"
36
+ description ="Choose a model from the list. Select the Base model for the fastest inference and the XLarge one for the most accurate results."
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ gradio_app.launch()
41
+
42
+
43
+
44
+ # if __name__ == "__main__":
45
+ # gradio_app.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ librosa
4
+ samplerate
5
+ resampy