Update app.py
Browse files
app.py
CHANGED
@@ -26,20 +26,25 @@ if uploaded_file:
|
|
26 |
# Convert audio to tensor
|
27 |
audio_tensor = torch.tensor(audio).float()
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
# Offer a download button for the inverted audio
|
42 |
if st.button("Download Inverted Audio"):
|
43 |
with io.BytesIO() as out_io:
|
44 |
-
sf.write(out_io,
|
45 |
st.download_button("Download Inverted Audio", data=out_io.getvalue(), file_name="inverted_output.wav", mime="audio/wav")
|
|
|
26 |
# Convert audio to tensor
|
27 |
audio_tensor = torch.tensor(audio).float()
|
28 |
|
29 |
+
# Use Streamlit's session state to prevent re-inversion
|
30 |
+
if "inverted_audio" not in st.session_state:
|
31 |
+
with st.spinner("Inverting audio..."):
|
32 |
+
# Invert the audio using the modified function
|
33 |
+
inverted_audio_tensor = invert_audio(model, processor, audio_tensor, sr)
|
34 |
+
|
35 |
+
# Convert tensor back to numpy
|
36 |
+
inverted_audio_np = inverted_audio_tensor.numpy()
|
37 |
+
|
38 |
+
# Store inverted audio in session state
|
39 |
+
st.session_state.inverted_audio = inverted_audio_np
|
40 |
+
|
41 |
+
# Play inverted audio from session state
|
42 |
+
with io.BytesIO() as out_io:
|
43 |
+
sf.write(out_io, st.session_state.inverted_audio, sr, format="wav")
|
44 |
+
st.audio(out_io.getvalue(), format="audio/wav")
|
45 |
|
46 |
# Offer a download button for the inverted audio
|
47 |
if st.button("Download Inverted Audio"):
|
48 |
with io.BytesIO() as out_io:
|
49 |
+
sf.write(out_io, st.session_state.inverted_audio, sr, format="wav")
|
50 |
st.download_button("Download Inverted Audio", data=out_io.getvalue(), file_name="inverted_output.wav", mime="audio/wav")
|