Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,13 @@ import datetime
|
|
| 4 |
import numpy as np
|
| 5 |
import hashlib
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
# Function to save audio with label and speaker name
|
| 8 |
def save_audio(audio, dropdown_label, custom_label, speaker_name):
|
|
|
|
|
|
|
| 9 |
# Determine the final label
|
| 10 |
label = custom_label if dropdown_label == "Custom" else dropdown_label
|
| 11 |
|
|
@@ -27,8 +32,11 @@ def save_audio(audio, dropdown_label, custom_label, speaker_name):
|
|
| 27 |
# Save the audio file in wav format
|
| 28 |
sf.write(filename, audio_data, sample_rate)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Interface design using gr.Blocks
|
| 34 |
def create_interface():
|
|
@@ -48,10 +56,13 @@ def create_interface():
|
|
| 48 |
|
| 49 |
submit_button = gr.Button("Submit")
|
| 50 |
|
|
|
|
|
|
|
|
|
|
| 51 |
submit_button.click(
|
| 52 |
fn=save_audio,
|
| 53 |
inputs=[audio, label_dropdown, custom_label, speaker_name],
|
| 54 |
-
outputs=
|
| 55 |
)
|
| 56 |
|
| 57 |
return demo
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import hashlib
|
| 6 |
|
| 7 |
+
# Initialize a list to store file paths
|
| 8 |
+
uploaded_files = []
|
| 9 |
+
|
| 10 |
# Function to save audio with label and speaker name
|
| 11 |
def save_audio(audio, dropdown_label, custom_label, speaker_name):
|
| 12 |
+
global uploaded_files
|
| 13 |
+
|
| 14 |
# Determine the final label
|
| 15 |
label = custom_label if dropdown_label == "Custom" else dropdown_label
|
| 16 |
|
|
|
|
| 32 |
# Save the audio file in wav format
|
| 33 |
sf.write(filename, audio_data, sample_rate)
|
| 34 |
|
| 35 |
+
# Add the new file path to the list of uploaded files
|
| 36 |
+
uploaded_files.append(filename)
|
| 37 |
+
|
| 38 |
+
# Return the list of all file paths for download
|
| 39 |
+
return uploaded_files
|
| 40 |
|
| 41 |
# Interface design using gr.Blocks
|
| 42 |
def create_interface():
|
|
|
|
| 56 |
|
| 57 |
submit_button = gr.Button("Submit")
|
| 58 |
|
| 59 |
+
# Create a list to display all uploaded files
|
| 60 |
+
file_list = gr.Files(label="Download your recordings")
|
| 61 |
+
|
| 62 |
submit_button.click(
|
| 63 |
fn=save_audio,
|
| 64 |
inputs=[audio, label_dropdown, custom_label, speaker_name],
|
| 65 |
+
outputs=file_list,
|
| 66 |
)
|
| 67 |
|
| 68 |
return demo
|