Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,21 @@ from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
|
|
2 |
import soundfile as sf
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
-
|
6 |
|
7 |
# load model and processor
|
8 |
processor = Wav2Vec2Processor.from_pretrained("maher13/arabic-iti")
|
9 |
model = Wav2Vec2ForCTC.from_pretrained("maher13/arabic-iti").eval()
|
10 |
# define function to read in sound file
|
11 |
def map_to_array(file):
|
12 |
-
speech, sr=
|
13 |
if sr != 16000:
|
14 |
-
transform = torchaudio.transforms.Resample(orig_freq=
|
15 |
new_freq=16000)
|
16 |
-
speech= transform(speech)
|
|
|
|
|
|
|
17 |
return speech
|
18 |
|
19 |
# tokenize
|
@@ -57,4 +60,5 @@ gradio_ui = gr.Interface(
|
|
57 |
gr.outputs.Textbox(label="Auto-Transcript")
|
58 |
],
|
59 |
)
|
|
|
60 |
gradio_ui.launch(share=True)
|
|
|
2 |
import soundfile as sf
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
+
import torchaudio
|
6 |
|
7 |
# load model and processor
|
8 |
processor = Wav2Vec2Processor.from_pretrained("maher13/arabic-iti")
|
9 |
model = Wav2Vec2ForCTC.from_pretrained("maher13/arabic-iti").eval()
|
10 |
# define function to read in sound file
|
11 |
def map_to_array(file):
|
12 |
+
speech, sr = torchaudio.load(file)
|
13 |
if sr != 16000:
|
14 |
+
transform = torchaudio.transforms.Resample(orig_freq=sr,
|
15 |
new_freq=16000)
|
16 |
+
speech= transform(speech)
|
17 |
+
speech = speech[0]
|
18 |
+
speech = speech.numpy()
|
19 |
+
|
20 |
return speech
|
21 |
|
22 |
# tokenize
|
|
|
60 |
gr.outputs.Textbox(label="Auto-Transcript")
|
61 |
],
|
62 |
)
|
63 |
+
|
64 |
gradio_ui.launch(share=True)
|