AudioDenoiser / app.py
ArnavGhost's picture
Update app.py
cb55ee8 verified
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'<style>{f.read()}</style>', unsafe_allow_html=True)
local_css("styles.css") # Load custom CSS styles
page_bg_img = f"""
<style>
[data-testid="stAppViewContainer"] > .main {{
background-image: url("https://i.postimg.cc/nhkJVTVg/1.gif");
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: local;
}}
[data-testid="stHeader"] {{
background: rgba(0,0,0,0);
}}
</style>
"""
st.markdown(page_bg_img, unsafe_allow_html=True)
# Function to display app title with custom styling
def app_title(title):
st.markdown(f"<h1 style='text-align: center; color: #1DB954;'>{title}</h1>", unsafe_allow_html=True)
# Function to display error message with custom styling
def error_message(message):
st.markdown(f"<p style='text-align: center; color: #ff0000;'>{message}</p>", 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.")