File size: 1,202 Bytes
e0cc52c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# functional app
from model import load_model, invert_audio
import os

preloaded = {}
preloaded["model"], preloaded["processor"] = load_model()

# Co
for input_audio_path in data_dir.glob('*.wav'):
    print(os.path.basename(input_audio_path))
    output_audio_path = os.path.join(output_dir, "inverted-" + os.path.basename(input_audio_path))
    output_file = invert_audio(
        preloaded["model"], preloaded["processor"],
        input_audio_path, output_audio_path)


# HuggingFace UI
import streamlit as st
import torch
import julius

st.title("Audio Inversion with HuggingFace & Streamlit")

uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "flac"])

if uploaded_file:
    st.audio(uploaded_file, format="audio/wav")
    with st.spinner("Inverting audio..."):
        output_path = "inverted_output.wav" # Temporary output path. Consider using temp files or dynamic naming in production.
        invert_audio(model, processor, uploaded_file, output_path)
        st.audio(output_path, format="audio/wav")

    if st.button("Download Inverted Audio"):
        st.download_button("Download Inverted Audio", data=output_path, file_name="inverted_output.wav", mime="audio/wav")