import streamlit as st import requests import os # Streamlit code for UI st.set_page_config(page_title="Denoiser App", page_icon="🎵") # Function to add custom CSS styles def local_css(file_name): with open(file_name) as f: st.markdown(f'', unsafe_allow_html=True) local_css("styles.css") # Load custom CSS styles page_bg_img = f""" """ st.markdown(page_bg_img, unsafe_allow_html=True) # Function to display app title with custom styling def app_title(title): st.markdown(f"

{title}

", unsafe_allow_html=True) # Function to display error message with custom styling def error_message(message): st.markdown(f"

{message}

", unsafe_allow_html=True) # File uploader for audio app_title("Let's Denoise!") audio_file = st.file_uploader("Upload audio file", type=["mp3", "wav", "m4a"]) if audio_file is not None: st.audio(audio_file, format='audio/wav') # Text input text_input = st.text_input("Enter text for processing") # Enable the "Generate" button only if both audio file and text are provided if audio_file is not None and text_input: if st.button("Denoise it!", key="generate_button"): # Upload audio file and text to FastAPI server files = {'file': (audio_file.name, audio_file.getvalue(), 'audio/wav')} data = {'text': text_input} response = requests.post('https://arnavghost-audiodenoiseapi.hf.space/upload', files=files, data=data) if response.status_code == 200: st.success("Go Ahead!") processed_audio_file_url = response.json()["processed_audio_file"] # Load and display processed audio st.audio(f'https://arnavghost-audiodenoiseapi.hf.space{processed_audio_file_url}', format='audio/wav') # Add download button for processed audio processed_audio_bytes = requests.get(f'https://arnavghost-audiodenoiseapi.hf.space{processed_audio_file_url}').content st.download_button( label="Download Your Denoised Audio", data=processed_audio_bytes, file_name=os.path.basename(processed_audio_file_url), mime='audio/wav' ) else: error_message("Failed to upload audio file and process.")