Spaces:
Runtime error
Runtime error
nahue-passano
commited on
Commit
•
7fc9bd4
1
Parent(s):
d4a3c16
Update app.py
Browse files
app.py
CHANGED
@@ -46,7 +46,20 @@ def get_sentence_data(filename: str, timestamp_dict: dict):
|
|
46 |
|
47 |
|
48 |
def get_word_data(filename: str, timestamp_dict: dict):
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
st.set_page_config(layout="wide")
|
52 |
|
@@ -68,11 +81,11 @@ with lang:
|
|
68 |
with size:
|
69 |
model_size = st.selectbox("Model size", options=list(MODEL_SIZES.keys()))
|
70 |
|
71 |
-
|
72 |
if st.button("Generate Timestamp", use_container_width=True):
|
73 |
with st.spinner("Loading model..."):
|
74 |
model = load_model(model_size)
|
75 |
-
|
76 |
for audio_i in audio_file:
|
77 |
with st.spinner(f"Processing audio: {audio_i.name}"):
|
78 |
tmp_audio = save_temp_file(audio_i)
|
@@ -80,14 +93,17 @@ if st.button("Generate Timestamp", use_container_width=True):
|
|
80 |
timestamp_result = whisper.transcribe(
|
81 |
model, tmp_audio_file, language=LANGUAGES[language]
|
82 |
)
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
85 |
|
86 |
-
st.dataframe(
|
87 |
|
88 |
st.download_button(
|
89 |
"Save timestamps",
|
90 |
-
|
91 |
file_name="timestamps.csv",
|
92 |
mime="text/csv",
|
93 |
use_container_width=True,
|
|
|
46 |
|
47 |
|
48 |
def get_word_data(filename: str, timestamp_dict: dict):
|
49 |
+
word_df = pd.DataFrame(columns=["Audio file", "Word", "Start", "End", "Duration"])
|
50 |
+
for sentence_i in timestamp_dict["segments"]:
|
51 |
+
for word_i in sentence_i["words"]:
|
52 |
+
word_i_df = pd.DataFrame(
|
53 |
+
{
|
54 |
+
"Audio file": [filename],
|
55 |
+
"Word": [str(word_i["text"])],
|
56 |
+
"Start": [word_i["start"]],
|
57 |
+
"End": [word_i["end"]],
|
58 |
+
"Duration": [word_i["end"] - word_i["start"]],
|
59 |
+
}
|
60 |
+
)
|
61 |
+
word_df = pd.concat([word_df, word_i_df], ignore_index=True)
|
62 |
+
return word_df
|
63 |
|
64 |
st.set_page_config(layout="wide")
|
65 |
|
|
|
81 |
with size:
|
82 |
model_size = st.selectbox("Model size", options=list(MODEL_SIZES.keys()))
|
83 |
|
84 |
+
|
85 |
if st.button("Generate Timestamp", use_container_width=True):
|
86 |
with st.spinner("Loading model..."):
|
87 |
model = load_model(model_size)
|
88 |
+
timestamps_df = pd.DataFrame()
|
89 |
for audio_i in audio_file:
|
90 |
with st.spinner(f"Processing audio: {audio_i.name}"):
|
91 |
tmp_audio = save_temp_file(audio_i)
|
|
|
93 |
timestamp_result = whisper.transcribe(
|
94 |
model, tmp_audio_file, language=LANGUAGES[language]
|
95 |
)
|
96 |
+
if timestamp_type == "Sentence-level":
|
97 |
+
audio_i_df = get_sentence_data(audio_i.name, timestamp_result)
|
98 |
+
if timestamp_type == "Word-level":
|
99 |
+
audio_i_df = get_word_data(audio_i.name, timestamp_result)
|
100 |
+
timestamps_df = pd.concat([timestamps_df, audio_i_df], ignore_index=True)
|
101 |
|
102 |
+
st.dataframe(timestamps_df)
|
103 |
|
104 |
st.download_button(
|
105 |
"Save timestamps",
|
106 |
+
timestamps_df.to_csv(index=False),
|
107 |
file_name="timestamps.csv",
|
108 |
mime="text/csv",
|
109 |
use_container_width=True,
|