Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Load model directly
|
2 |
+
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
|
3 |
+
import torchaudio
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
processor = AutoProcessor.from_pretrained("mohammed/whisper-small-arabic-cv-11")
|
7 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained("mohammed/whisper-small-arabic-cv-11")
|
8 |
+
|
9 |
+
st.title("Arabic Whisper model v2")
|
10 |
+
|
11 |
+
audio_file = st.file_uploader("Upload audio", type=["mp3", "wav", "m4a"])
|
12 |
+
|
13 |
+
if st.sidebar.button("Trascribe Audio"):
|
14 |
+
if audio_file is not None:
|
15 |
+
st.sidebar.success("Transcribing audio") # on success audio file
|
16 |
+
|
17 |
+
audio_tensor, sample_rate = torchaudio.load(audio_file)
|
18 |
+
|
19 |
+
if sample_rate != 16000:
|
20 |
+
resampler = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)
|
21 |
+
audio_tensor = resampler(audio_tensor)
|
22 |
+
|
23 |
+
audio_np = audio_tensor.squeeze().numpy()
|
24 |
+
|
25 |
+
# processing audio
|
26 |
+
inputs = processor(audio_np, sample_rate=16000, return_tensors="pt")
|
27 |
+
|
28 |
+
# generating transcript
|
29 |
+
generated_ids = model.generate(inputs["input_features"])
|
30 |
+
|
31 |
+
transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
32 |
+
|
33 |
+
# display transcription
|
34 |
+
st.sidebar.success("Transcription is complete")
|
35 |
+
st.text(transcription[0])
|
36 |
+
|
37 |
+
else:
|
38 |
+
st.sidebar.error("Please upload a valid audio file")
|