File size: 2,773 Bytes
1516356
 
51bd837
1516356
 
 
 
 
 
 
 
 
 
 
 
 
 
cb55ee8
1516356
 
 
 
 
 
 
 
 
 
 
 
0f812cd
1516356
 
 
 
 
 
 
 
 
 
bafaaa2
1516356
 
 
 
 
 
 
 
 
 
 
0f812cd
1516356
6b02d37
1516356
 
 
0f812cd
1516356
 
9eaa4c3
1516356
 
0f812cd
1516356
 
 
0f812cd
1516356
 
 
9eaa4c3
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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.")