firzaelbuho
commited on
Commit
•
7ab4173
1
Parent(s):
91e0626
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import os
|
2 |
import glob
|
3 |
import json
|
@@ -422,6 +424,152 @@ def use_microphone(microphone):
|
|
422 |
else:
|
423 |
return gr.Audio.update(source="upload")
|
424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
if __name__ == '__main__':
|
426 |
load_hubert()
|
427 |
categories = load_model()
|
@@ -732,4 +880,17 @@ if __name__ == '__main__':
|
|
732 |
tts_voice
|
733 |
]
|
734 |
)
|
735 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import unicode_literals
|
2 |
+
|
3 |
import os
|
4 |
import glob
|
5 |
import json
|
|
|
424 |
else:
|
425 |
return gr.Audio.update(source="upload")
|
426 |
|
427 |
+
|
428 |
+
|
429 |
+
# Audio Tool Functions
|
430 |
+
|
431 |
+
# cvt audio
|
432 |
+
|
433 |
+
from pydub import AudioSegment
|
434 |
+
def convert_audio(url,title):
|
435 |
+
|
436 |
+
# Mendefinisikan path untuk file audio
|
437 |
+
input_path = url
|
438 |
+
file_name = os.path.basename(input_path)
|
439 |
+
filename = os.path.splitext(file_name)[0]
|
440 |
+
|
441 |
+
|
442 |
+
parent_dir = os.path.dirname(url)
|
443 |
+
new_path = os.path.relpath(parent_dir, "")
|
444 |
+
|
445 |
+
|
446 |
+
|
447 |
+
output_path = f'youtubeaudio/{title}_converted.mp3'
|
448 |
+
|
449 |
+
# Mengkonversi file audio WAV menjadi MP3 menggunakan pydub
|
450 |
+
sound = AudioSegment.from_wav(input_path)
|
451 |
+
sound.export(output_path, format="mp3")
|
452 |
+
|
453 |
+
# Mengecek apakah file audio MP3 sudah tersimpan
|
454 |
+
if os.path.isfile(output_path):
|
455 |
+
# return output_path
|
456 |
+
return "sukses"
|
457 |
+
else:
|
458 |
+
return "Konversi gagal"
|
459 |
+
|
460 |
+
|
461 |
+
# Fungsi play Audio
|
462 |
+
def play_audio(url):
|
463 |
+
|
464 |
+
file_path = url
|
465 |
+
file_name = os.path.basename(file_path)
|
466 |
+
filename = os.path.splitext(file_name)[0]
|
467 |
+
|
468 |
+
original_path = f"/content/youtubeaudio/{filename}.wav"
|
469 |
+
vocal_path = f"/content/separated/htdemucs/{filename}/vocals.wav"
|
470 |
+
instrument_path = f"/content/separated/htdemucs/{filename}/no_vocals.wav"
|
471 |
+
|
472 |
+
return url
|
473 |
+
|
474 |
+
|
475 |
+
|
476 |
+
# Fungsi download audio
|
477 |
+
|
478 |
+
import yt_dlp
|
479 |
+
import ffmpeg
|
480 |
+
import sys
|
481 |
+
|
482 |
+
|
483 |
+
def download_audio(title, url):
|
484 |
+
|
485 |
+
ydl_opts = {
|
486 |
+
'format': 'bestaudio/best',
|
487 |
+
# 'outtmpl': 'output.%(ext)s',
|
488 |
+
'postprocessors': [{
|
489 |
+
'key': 'FFmpegExtractAudio',
|
490 |
+
'preferredcodec': 'wav',
|
491 |
+
}],
|
492 |
+
"outtmpl": f'youtubeaudio/{title}', # this is where you can edit how you'd like the filenames to be formatted
|
493 |
+
}
|
494 |
+
|
495 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
496 |
+
# url = "https://www.youtube.com/watch?v=LCcNtQuhUgg" #@param {type:"string"}
|
497 |
+
ydl.download([url])
|
498 |
+
# return f"/content/youtubeaudio/{title}.wav"
|
499 |
+
# return f"/content/youtubeaudio/adudio.wav"
|
500 |
+
return "sukses"
|
501 |
+
|
502 |
+
#fungsi download video
|
503 |
+
def download_video(url, resolution):
|
504 |
+
|
505 |
+
from pytube import YouTube
|
506 |
+
|
507 |
+
yt = YouTube(url)
|
508 |
+
try:
|
509 |
+
stream_check = yt.streams.filter(res=f"{resolution}p")
|
510 |
+
if len(stream_check) > 0:
|
511 |
+
stream = yt.streams.filter(file_extension='mp4', res=f'{resolution}p').first()
|
512 |
+
else:
|
513 |
+
stream = yt.streams.get_highest_resolution()
|
514 |
+
except Exception as e:
|
515 |
+
return "error"
|
516 |
+
|
517 |
+
|
518 |
+
|
519 |
+
|
520 |
+
folder_path = 'youtubevideo'
|
521 |
+
if not os.path.exists(folder_path):
|
522 |
+
os.makedirs(folder_path)
|
523 |
+
|
524 |
+
file_path = os.path.join(folder_path, stream.default_filename)
|
525 |
+
stream.download(output_path=folder_path, filename=stream.default_filename)
|
526 |
+
|
527 |
+
return "sukses"
|
528 |
+
|
529 |
+
|
530 |
+
# fungsi split audio
|
531 |
+
def split_audio(url):
|
532 |
+
import subprocess
|
533 |
+
|
534 |
+
command = f"demucs --two-stems=vocals {url}"
|
535 |
+
result = subprocess.run(command.split(), stdout=subprocess.PIPE)
|
536 |
+
print(result.stdout.decode())
|
537 |
+
return "sukses"
|
538 |
+
|
539 |
+
|
540 |
+
def aio(title, yt_url):
|
541 |
+
download_status = download_audio(title, yt_url)
|
542 |
+
|
543 |
+
audio_url = f"youtubeaudio/{title}.wav"
|
544 |
+
split_status = split_audio(audio_url)
|
545 |
+
|
546 |
+
vocal_url = f"separated/htdemucs/{title}/vocals.wav"
|
547 |
+
no_vocal_url = f"separated/htdemucs/{title}/no_vocals.wav"
|
548 |
+
|
549 |
+
vocal_convert_status = convert_audio(vocal_url, title+"_vocal")
|
550 |
+
no_vocal_convert_status = convert_audio(no_vocal_url, title+"_instrumen")
|
551 |
+
|
552 |
+
import os
|
553 |
+
|
554 |
+
# specify old file path name
|
555 |
+
# old_vocal_name = f"separated/htdemucs/{title}/vocals_converted.mp3"
|
556 |
+
# old_instrumen_name = f"separated/htdemucs/{title}/no_vocals_converted.mp3"
|
557 |
+
|
558 |
+
|
559 |
+
# Specify the new file path and name
|
560 |
+
# new_vocal_name = f"separated/htdemucs/{title}/{title}_vocal.mp3"
|
561 |
+
# new_instrumen_name = f"separated/htdemucs/{title}/{title}_instrumen.mp3"
|
562 |
+
|
563 |
+
# Rename the file separated
|
564 |
+
# os.rename(old_vocal_name, new_vocal_name)
|
565 |
+
# os.rename(old_instrumen_name, new_instrumen_name)
|
566 |
+
|
567 |
+
|
568 |
+
return "sukses"
|
569 |
+
|
570 |
+
|
571 |
+
|
572 |
+
|
573 |
if __name__ == '__main__':
|
574 |
load_hubert()
|
575 |
categories = load_model()
|
|
|
880 |
tts_voice
|
881 |
]
|
882 |
)
|
883 |
+
# Audio tool
|
884 |
+
|
885 |
+
with gr.Tab("AIO"):
|
886 |
+
with gr.Row():
|
887 |
+
with gr.Column():
|
888 |
+
aio_input = [gr.Textbox(label = "title"), gr.Textbox(label = "Youtube Url")]
|
889 |
+
aio_button = gr.Button("Procces")
|
890 |
+
with gr.Column():
|
891 |
+
aio_output =[gr.Textbox(label = "Status Output")]
|
892 |
+
|
893 |
+
aio_button.click(aio, inputs=aio_input, outputs=aio_output)
|
894 |
+
|
895 |
+
|
896 |
+
app.queue(concurrency_count=5, max_size=50, api_open=config.api).launch(share=config.share, debug=True)
|