Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import librosa
|
|
5 |
import soundfile as sf
|
6 |
import os
|
7 |
import zipfile
|
|
|
8 |
|
9 |
# Function to download audio from YouTube and save it as a WAV file
|
10 |
def download_youtube_audio(url, audio_name):
|
@@ -156,19 +157,37 @@ def zip_directory(directory_path, audio_name):
|
|
156 |
zipf.write(file_path, arcname)
|
157 |
return zip_file
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
# Gradio interface
|
160 |
-
def process_audio(url, audio_name):
|
161 |
file_path = download_youtube_audio(url, audio_name)
|
162 |
dataset_path = slice_audio(file_path, audio_name)
|
163 |
zip_file = zip_directory(dataset_path, audio_name)
|
164 |
-
|
|
|
165 |
|
166 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
167 |
url_input = gr.Textbox(label="YouTube URL")
|
168 |
audio_name_input = gr.Textbox(label="Audio Name")
|
|
|
|
|
169 |
result_output = gr.File(label="Download Sliced Audio Zip")
|
|
|
170 |
|
171 |
run_button = gr.Button("Download and Slice Audio")
|
172 |
-
run_button.click(fn=process_audio, inputs=[url_input, audio_name_input], outputs=result_output)
|
173 |
|
174 |
demo.launch()
|
|
|
5 |
import soundfile as sf
|
6 |
import os
|
7 |
import zipfile
|
8 |
+
from huggingface_hub import HfApi, HfFolder, Repository
|
9 |
|
10 |
# Function to download audio from YouTube and save it as a WAV file
|
11 |
def download_youtube_audio(url, audio_name):
|
|
|
157 |
zipf.write(file_path, arcname)
|
158 |
return zip_file
|
159 |
|
160 |
+
# Function to upload zip file to Hugging Face Hub
|
161 |
+
def upload_to_huggingface(zip_file, repo_id, hf_token):
|
162 |
+
api = HfApi()
|
163 |
+
api.upload_file(
|
164 |
+
path_or_fileobj=zip_file,
|
165 |
+
path_in_repo=os.path.basename(zip_file),
|
166 |
+
repo_id=repo_id,
|
167 |
+
token=hf_token
|
168 |
+
)
|
169 |
+
return f"File uploaded to {repo_id}/{os.path.basename(zip_file)}"
|
170 |
+
|
171 |
# Gradio interface
|
172 |
+
def process_audio(url, audio_name, hf_token, repo_id):
|
173 |
file_path = download_youtube_audio(url, audio_name)
|
174 |
dataset_path = slice_audio(file_path, audio_name)
|
175 |
zip_file = zip_directory(dataset_path, audio_name)
|
176 |
+
upload_message = upload_to_huggingface(zip_file, repo_id, hf_token)
|
177 |
+
return zip_file, upload_message
|
178 |
|
179 |
with gr.Blocks() as demo:
|
180 |
+
with gr.Tabs():
|
181 |
+
with gr.TabItem("make dataset"):
|
182 |
+
with gr.Row():
|
183 |
url_input = gr.Textbox(label="YouTube URL")
|
184 |
audio_name_input = gr.Textbox(label="Audio Name")
|
185 |
+
hf_token_input = gr.Textbox(label="Hugging Face Token", type="password")
|
186 |
+
repo_id_input = gr.Textbox(label="Repository ID")
|
187 |
result_output = gr.File(label="Download Sliced Audio Zip")
|
188 |
+
upload_output = gr.Textbox(label="Hugging Face Upload Status")
|
189 |
|
190 |
run_button = gr.Button("Download and Slice Audio")
|
191 |
+
run_button.click(fn=process_audio, inputs=[url_input, audio_name_input, hf_token_input, repo_id_input], outputs=[result_output, upload_output])
|
192 |
|
193 |
demo.launch()
|