ArnavGhost commited on
Commit
1516356
1 Parent(s): c391638

Upload 2 files

Browse files

API call with frontend

Files changed (2) hide show
  1. app.py +73 -0
  2. styles.css +85 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import os
4
+
5
+ # Streamlit code for UI
6
+ st.set_page_config(page_title="Denoiser App", page_icon="🎵")
7
+
8
+ # Function to add custom CSS styles
9
+ def local_css(file_name):
10
+ with open(file_name) as f:
11
+ st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
12
+
13
+ local_css("styles.css") # Load custom CSS styles
14
+
15
+ page_bg_img = f"""
16
+ <style>
17
+ [data-testid="stAppViewContainer"] > .main {{
18
+ background-image: url("https://i.postimg.cc/4xgNnkfX/Untitled-design.png");
19
+ background-size: cover;
20
+ background-position: center center;
21
+ background-repeat: no-repeat;
22
+ background-attachment: local;
23
+ }}
24
+ [data-testid="stHeader"] {{
25
+ background: rgba(0,0,0,0);
26
+ }}
27
+ </style>
28
+ """
29
+
30
+ st.markdown(page_bg_img, unsafe_allow_html=True)
31
+ # Function to display app title with custom styling
32
+ def app_title(title):
33
+ st.markdown(f"<h1 style='text-align: center; color: #1DB954;'>{title}</h1>", unsafe_allow_html=True)
34
+
35
+ # Function to display error message with custom styling
36
+ def error_message(message):
37
+ st.markdown(f"<p style='text-align: center; color: #ff0000;'>{message}</p>", unsafe_allow_html=True)
38
+
39
+ # File uploader for audio
40
+ app_title("Let's Denoise!")
41
+ audio_file = st.file_uploader("Upload audio file", type=["mp3", "wav"])
42
+
43
+ if audio_file is not None:
44
+ st.audio(audio_file, format='audio/wav')
45
+
46
+ # Text input
47
+ text_input = st.text_input("Enter text for processing")
48
+
49
+ # Enable the "Generate" button only if both audio file and text are provided
50
+ if audio_file is not None and text_input:
51
+ if st.button("Denoise it!", key="generate_button"):
52
+ # Upload audio file and text to FastAPI server
53
+ files = {'file': audio_file.getvalue()}
54
+ data = {'text': text_input}
55
+ response = requests.post('http://localhost:8000/upload', files=files, data=data)
56
+
57
+ if response.status_code == 200:
58
+ st.success("Go Ahead!")
59
+ processed_audio_file_path = response.json()["processed_audio_file"]
60
+
61
+ # Load and display processed audio
62
+ st.audio(processed_audio_file_path, format='audio/wav')
63
+
64
+ # Add download button for processed audio
65
+ processed_audio_bytes = open(processed_audio_file_path, 'rb').read()
66
+ st.download_button(
67
+ label="Download Your Denoised Audio",
68
+ data=processed_audio_bytes,
69
+ file_name=os.path.basename(processed_audio_file_path),
70
+ mime='audio/wav'
71
+ )
72
+ else:
73
+ error_message("Failed to upload audio file and process.")
styles.css ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* stylish_button.css */
2
+
3
+ /* Body styling for dark theme */
4
+ body {
5
+ font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
6
+ background-color: #ffffff;
7
+ color: #ffffff;
8
+ }
9
+
10
+ /* Title styling */
11
+ h1 {
12
+ color: #1DB954;
13
+ text-align: center;
14
+ }
15
+
16
+ /* File uploader styling */
17
+ div.stFileUploader {
18
+ margin-top: 20px;
19
+ color: #ffffff;
20
+ text-align: center;
21
+ }
22
+
23
+ /* Text input styling */
24
+ div.stTextInput {
25
+ margin-top: 20px;
26
+ }
27
+
28
+
29
+ /* Button styling */
30
+ div.stButton>button {
31
+ background-color: #4CAF50 !important; /* Darker green */
32
+ color: #ffffff !important;
33
+ border-radius: 5px !important;
34
+ padding: 10px 20px !important;
35
+ font-size: 16px !important;
36
+ border: none;
37
+ cursor: pointer;
38
+ transition: background-color 0.3s;
39
+ text-align: center;
40
+ }
41
+
42
+ /* Download button text styling */
43
+ div.stButton>button>span {
44
+ font-weight: bold !important;
45
+ }
46
+
47
+ /* Download button hover effect */
48
+ div.stButton>button:hover {
49
+ background-color: #45a049 !important; /* Darker green on hover */
50
+ }
51
+
52
+
53
+ /* Error message styling */
54
+ p.errorMessage {
55
+ color: #ff0000;
56
+ text-align: center;
57
+ }
58
+
59
+ /* Audio player styling */
60
+ div.stAudio {
61
+ margin-top: 20px;
62
+ }
63
+
64
+ /* Download button styling */
65
+ div.stDownloadButton>button {
66
+ background-color: #4CAF50 !important; /* Darker green */
67
+ color: #ffffff !important;
68
+ border-radius: 5px !important;
69
+ padding: 10px 20px !important;
70
+ font-size: 16px !important;
71
+ border: none;
72
+ cursor: pointer;
73
+ transition: background-color 0.3s;
74
+ text-align: center;
75
+ }
76
+
77
+ /* Download button text styling */
78
+ div.stDownloadButton>button>span {
79
+ font-weight: bold !important;
80
+ }
81
+
82
+ /* Download button hover effect */
83
+ div.stDownloadButton>button:hover {
84
+ background-color: #45a049 !important; /* Darker green on hover */
85
+ }