Jaman commited on
Commit
e3017a6
·
verified ·
1 Parent(s): 7c5d14c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -18
app.py CHANGED
@@ -12,6 +12,10 @@ def ensure_directory_exists(directory):
12
  if not os.path.exists(directory):
13
  os.makedirs(directory)
14
 
 
 
 
 
15
  # Function to process the audio
16
  def process_audio(file_path):
17
  # Ensure to navigate to the home directory first
@@ -75,21 +79,24 @@ if uploaded_file is not None:
75
 
76
  # Display and download each generated audio
77
  for file in output_files:
78
- file_name = os.path.basename(file)
79
- if 'vocals.wav' in file_name:
80
- st.write('Vocal')
81
- elif 'bass.wav' in file_name:
82
- st.write('Bass')
83
- elif 'drums.wav' in file_name:
84
- st.write('Drums')
85
- elif 'accompaniment.wav' in file_name:
86
- st.write('Music')
87
-
88
- st.audio(file)
89
- with open(file, 'rb') as f:
90
- st.download_button(
91
- label=f'Download {file_name}',
92
- data=f,
93
- file_name=file_name,
94
- mime='audio/wav'
95
- )
 
 
 
 
12
  if not os.path.exists(directory):
13
  os.makedirs(directory)
14
 
15
+ # Function to check if the file exists
16
+ def file_exists(file_path):
17
+ return os.path.isfile(file_path)
18
+
19
  # Function to process the audio
20
  def process_audio(file_path):
21
  # Ensure to navigate to the home directory first
 
79
 
80
  # Display and download each generated audio
81
  for file in output_files:
82
+ if file_exists(file):
83
+ file_name = os.path.basename(file)
84
+ if 'vocals.wav' in file_name:
85
+ st.write('Vocal')
86
+ elif 'bass.wav' in file_name:
87
+ st.write('Bass')
88
+ elif 'drums.wav' in file_name:
89
+ st.write('Drums')
90
+ elif 'accompaniment.wav' in file_name:
91
+ st.write('Music')
92
+
93
+ st.audio(file)
94
+ with open(file, 'rb') as f:
95
+ st.download_button(
96
+ label=f'Download {file_name}',
97
+ data=f,
98
+ file_name=file_name,
99
+ mime='audio/wav'
100
+ )
101
+ else:
102
+ st.error(f"Error: {file} not found.")