cmagganas commited on
Commit
e0cc52c
1 Parent(s): e385c7e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # functional app
2
+ from model import load_model, invert_audio
3
+ import os
4
+
5
+ preloaded = {}
6
+ preloaded["model"], preloaded["processor"] = load_model()
7
+
8
+ # Co
9
+ for input_audio_path in data_dir.glob('*.wav'):
10
+ print(os.path.basename(input_audio_path))
11
+ output_audio_path = os.path.join(output_dir, "inverted-" + os.path.basename(input_audio_path))
12
+ output_file = invert_audio(
13
+ preloaded["model"], preloaded["processor"],
14
+ input_audio_path, output_audio_path)
15
+
16
+
17
+ # HuggingFace UI
18
+ import streamlit as st
19
+ import torch
20
+ import julius
21
+
22
+ st.title("Audio Inversion with HuggingFace & Streamlit")
23
+
24
+ uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "flac"])
25
+
26
+ if uploaded_file:
27
+ st.audio(uploaded_file, format="audio/wav")
28
+ with st.spinner("Inverting audio..."):
29
+ output_path = "inverted_output.wav" # Temporary output path. Consider using temp files or dynamic naming in production.
30
+ invert_audio(model, processor, uploaded_file, output_path)
31
+ st.audio(output_path, format="audio/wav")
32
+
33
+ if st.button("Download Inverted Audio"):
34
+ st.download_button("Download Inverted Audio", data=output_path, file_name="inverted_output.wav", mime="audio/wav")