Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
import whisper
|
3 |
import ffmpeg
|
4 |
import os
|
5 |
from transformers import pipeline
|
@@ -7,6 +7,8 @@ from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
|
|
7 |
import numpy as np
|
8 |
SAMPLE_RATE = 16000
|
9 |
|
|
|
|
|
10 |
def load_audio(file: str, sr: int = SAMPLE_RATE):
|
11 |
|
12 |
|
@@ -23,9 +25,10 @@ def load_audio(file: str, sr: int = SAMPLE_RATE):
|
|
23 |
if 'processor' not in locals():
|
24 |
|
25 |
with st.spinner('Wait for it...'):
|
26 |
-
|
27 |
processor = AutoProcessor.from_pretrained("openai/whisper-tiny")
|
28 |
-
model
|
|
|
29 |
|
30 |
|
31 |
|
@@ -42,7 +45,9 @@ if wav_up is not None:
|
|
42 |
with open(wav_up.name,"wb") as f:
|
43 |
f.write(wav_up.getbuffer())
|
44 |
st.success("Saved File")
|
45 |
-
|
|
|
|
|
46 |
st.audio(wav_up.name, format="audio/wav", start_time=0)
|
47 |
if st.button('Processa'):
|
48 |
if wav_up is not None:
|
@@ -57,10 +62,13 @@ if st.button('Processa'):
|
|
57 |
#processado=np.frombuffer(wav_up.getbuffer(), np.int16).flatten().astype(np.float32) / 32768.0
|
58 |
input_features = processor(audio , return_tensors="pt").input_features
|
59 |
forced_decoder_ids = processor.get_decoder_prompt_ids(language = None, task = "transcribe")
|
60 |
-
|
|
|
|
|
|
|
61 |
predicted_ids = model.generate(input_features, forced_decoder_ids = forced_decoder_ids)
|
62 |
|
63 |
-
transcription = processor.batch_decode(predicted_ids, skip_special_tokens = True)
|
64 |
string1=''
|
65 |
# for i, segment in enumerate(transcription, start=1):
|
66 |
# write srt lines
|
|
|
1 |
import streamlit as st
|
2 |
+
import whisper
|
3 |
import ffmpeg
|
4 |
import os
|
5 |
from transformers import pipeline
|
|
|
7 |
import numpy as np
|
8 |
SAMPLE_RATE = 16000
|
9 |
|
10 |
+
|
11 |
+
|
12 |
def load_audio(file: str, sr: int = SAMPLE_RATE):
|
13 |
|
14 |
|
|
|
25 |
if 'processor' not in locals():
|
26 |
|
27 |
with st.spinner('Wait for it...'):
|
28 |
+
|
29 |
processor = AutoProcessor.from_pretrained("openai/whisper-tiny")
|
30 |
+
model=whisper.load_model("tiny")
|
31 |
+
|
32 |
|
33 |
|
34 |
|
|
|
45 |
with open(wav_up.name,"wb") as f:
|
46 |
f.write(wav_up.getbuffer())
|
47 |
st.success("Saved File")
|
48 |
+
audio = whisper.load_audio(wav_up.name)
|
49 |
+
audio = whisper.pad_or_trim(audio)
|
50 |
+
|
51 |
st.audio(wav_up.name, format="audio/wav", start_time=0)
|
52 |
if st.button('Processa'):
|
53 |
if wav_up is not None:
|
|
|
62 |
#processado=np.frombuffer(wav_up.getbuffer(), np.int16).flatten().astype(np.float32) / 32768.0
|
63 |
input_features = processor(audio , return_tensors="pt").input_features
|
64 |
forced_decoder_ids = processor.get_decoder_prompt_ids(language = None, task = "transcribe")
|
65 |
+
transcription=model.transcribe(
|
66 |
+
audio,
|
67 |
+
language = 'pt'
|
68 |
+
)
|
69 |
predicted_ids = model.generate(input_features, forced_decoder_ids = forced_decoder_ids)
|
70 |
|
71 |
+
#transcription = processor.batch_decode(predicted_ids, skip_special_tokens = True)
|
72 |
string1=''
|
73 |
# for i, segment in enumerate(transcription, start=1):
|
74 |
# write srt lines
|