Spaces:
Sleeping
Sleeping
Mongar28
commited on
Commit
路
9276da4
1
Parent(s):
17ae025
Se hicieron mejoras en las estructura del codigo
Browse files- app.py +18 -6
- documents/__pycache__/docs.cpython-312.pyc +0 -0
- documents/docs/nota_de_voz.docx +0 -0
- openai_models/whisper.py +4 -4
- streamlit_tools/tools.py +1 -1
app.py
CHANGED
@@ -6,29 +6,41 @@ from documents.docs import generate_docx
|
|
6 |
import os
|
7 |
|
8 |
|
9 |
-
|
|
|
|
|
|
|
10 |
audio_full_path: str = load_audio_file()
|
11 |
-
if
|
|
|
|
|
|
|
12 |
with st.spinner("Transcribiendo..."):
|
13 |
-
transcription =
|
|
|
14 |
|
15 |
def transcription_generator():
|
16 |
for word in transcription["text"].split(' '):
|
17 |
time.sleep(0.2)
|
18 |
yield word + ' '
|
19 |
st.write_stream(transcription_generator(), )
|
|
|
|
|
20 |
# st.write(transcription)
|
21 |
-
|
22 |
generate_docx(transcription["text"])
|
|
|
23 |
|
24 |
-
if os.path.exists(st.session_state.full_path_docx):
|
25 |
with open(st.session_state.full_path_docx, "rb") as file:
|
26 |
btn = st.download_button(
|
27 |
label="Download docx",
|
28 |
data=file,
|
29 |
file_name=st.session_state.full_path_docx,
|
30 |
)
|
|
|
|
|
31 |
|
32 |
|
33 |
if __name__ == "__main__":
|
34 |
-
main()
|
|
|
6 |
import os
|
7 |
|
8 |
|
9 |
+
pipe = whisper_os()
|
10 |
+
|
11 |
+
|
12 |
+
def main(pipe):
|
13 |
audio_full_path: str = load_audio_file()
|
14 |
+
if "validador" not in st.session_state.keys():
|
15 |
+
st.session_state.validador = True
|
16 |
+
|
17 |
+
if st.session_state.validador == True and audio_full_path:
|
18 |
with st.spinner("Transcribiendo..."):
|
19 |
+
transcription = pipe(audio_full_path, return_timestamps=True,
|
20 |
+
generate_kwargs={"language": "spanish"})
|
21 |
|
22 |
def transcription_generator():
|
23 |
for word in transcription["text"].split(' '):
|
24 |
time.sleep(0.2)
|
25 |
yield word + ' '
|
26 |
st.write_stream(transcription_generator(), )
|
27 |
+
if "transcription" not in st.session_state.keys():
|
28 |
+
st.session_state.transcription = transcription["text"]
|
29 |
# st.write(transcription)
|
30 |
+
|
31 |
generate_docx(transcription["text"])
|
32 |
+
st.session_state.validador = False
|
33 |
|
34 |
+
if audio_full_path and os.path.exists(st.session_state.full_path_docx):
|
35 |
with open(st.session_state.full_path_docx, "rb") as file:
|
36 |
btn = st.download_button(
|
37 |
label="Download docx",
|
38 |
data=file,
|
39 |
file_name=st.session_state.full_path_docx,
|
40 |
)
|
41 |
+
if btn:
|
42 |
+
st.write(st.session_state.transcription)
|
43 |
|
44 |
|
45 |
if __name__ == "__main__":
|
46 |
+
main(pipe)
|
documents/__pycache__/docs.cpython-312.pyc
CHANGED
Binary files a/documents/__pycache__/docs.cpython-312.pyc and b/documents/__pycache__/docs.cpython-312.pyc differ
|
|
documents/docs/nota_de_voz.docx
ADDED
Binary file (36.7 kB). View file
|
|
openai_models/whisper.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
from transformers import pipeline, AutoModelForCausalLM, AutoModelForSpeechSeq2Seq, AutoProcessor
|
2 |
import torch
|
|
|
3 |
|
4 |
|
5 |
-
|
|
|
6 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
7 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
8 |
|
@@ -32,6 +34,4 @@ def whisper_os(audio_full_path: str):
|
|
32 |
device=device,
|
33 |
)
|
34 |
|
35 |
-
|
36 |
-
generate_kwargs={"language": "spanish"})
|
37 |
-
return result
|
|
|
1 |
from transformers import pipeline, AutoModelForCausalLM, AutoModelForSpeechSeq2Seq, AutoProcessor
|
2 |
import torch
|
3 |
+
import streamlit as st
|
4 |
|
5 |
|
6 |
+
@st.cache_resource
|
7 |
+
def whisper_os():
|
8 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
9 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
10 |
|
|
|
34 |
device=device,
|
35 |
)
|
36 |
|
37 |
+
return pipe
|
|
|
|
streamlit_tools/tools.py
CHANGED
@@ -13,7 +13,7 @@ def load_audio_file() -> str:
|
|
13 |
Returns:
|
14 |
str
|
15 |
"""
|
16 |
-
st.markdown('# **
|
17 |
st.markdown('### *Transcripci贸n de audio a texto*')
|
18 |
audio_file = st.file_uploader("Drag your audio file", type=[
|
19 |
'.mp3', '.m4a', '.ogg', '.aac'])
|
|
|
13 |
Returns:
|
14 |
str
|
15 |
"""
|
16 |
+
st.markdown('# **D铆ctamelo**')
|
17 |
st.markdown('### *Transcripci贸n de audio a texto*')
|
18 |
audio_file = st.file_uploader("Drag your audio file", type=[
|
19 |
'.mp3', '.m4a', '.ogg', '.aac'])
|