Pijush2023 commited on
Commit
6534ee6
·
verified ·
1 Parent(s): c1a8dbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -84
app.py CHANGED
@@ -585,89 +585,6 @@ def generate_audio_mars5(text):
585
  logging.debug(f"Audio saved to {combined_audio_path}")
586
  return combined_audio_path
587
 
588
- def generate_audio_meta_voice(text):
589
- description = "Thomas's tone is enthusiastic and energetic, with a moderate pace and clear, high-quality delivery."
590
- chunks = chunk_text(preprocess(text))
591
- audio_segments = []
592
-
593
- for chunk in chunks:
594
- prompt = parler_tokenizer(chunk, return_tensors="pt").to(device)
595
- generation = parler_model.generate(prompt_input_ids=prompt.input_ids)
596
- audio_arr = generation.cpu().numpy().squeeze()
597
-
598
- temp_audio_path = os.path.join(tempfile.gettempdir(), f"meta_voice_audio_{len(audio_segments)}.wav")
599
- write_wav(temp_audio_path, SAMPLE_RATE, audio_arr)
600
- audio_segments.append(AudioSegment.from_wav(temp_audio_path))
601
-
602
- combined_audio = sum(audio_segments)
603
- combined_audio_path = os.path.join(tempfile.gettempdir(), "meta_voice_combined_audio.wav")
604
- combined_audio.export(combined_audio_path, format="wav")
605
-
606
- logging.debug(f"Audio saved to {combined_audio_path}")
607
- return combined_audio_path
608
-
609
- # Meta Voice setup script
610
- import subprocess
611
- import os
612
- import shutil
613
- import time
614
- import sys
615
- import platform
616
- import stat
617
-
618
- if platform.system() == 'Windows':
619
- raise SystemError("You are trying to run this demo on **Windows**. Windows is not supported. If you would still like to try, remove lines 2 & 3 in the code to bypass this warning.")
620
-
621
- def setup_virtual_env():
622
- # Create a virtual environment directory
623
- subprocess.run(['python', '-m', 'venv', './venv_ui'])
624
-
625
- # Activate the virtual environment
626
- activate_script = os.path.join('venv_ui', 'bin', 'activate')
627
-
628
- st = os.stat(activate_script)
629
- os.chmod(activate_script, st.st_mode | stat.S_IEXEC)
630
- subprocess.run([activate_script], shell=True)
631
-
632
- # Install required packages
633
- subprocess.run(['pip', 'install', 'gradio', 'requests'])
634
-
635
- def move_files_and_subdirs(source_dir):
636
- # List all files and directories in the source directory
637
- files_and_dirs = os.listdir(source_dir)
638
-
639
- # Move each file and directory to the current working directory
640
- for item in files_and_dirs:
641
- # Get the full path of the item
642
- src_path = os.path.join(source_dir, item)
643
- # Check if it's a file
644
- if os.path.isfile(src_path):
645
- # Move the file to the current working directory
646
- shutil.move(src_path, os.path.join(os.getcwd(), item))
647
- elif os.path.isdir(src_path):
648
- # Move the directory and its contents recursively to the current working directory
649
- shutil.move(src_path, os.path.join(os.getcwd(), item))
650
- else:
651
- print(f"Ignoring: {src_path} as it is neither a file nor a directory")
652
-
653
-
654
- subprocess.run(['git', 'clone', 'https://github.com/fakerybakery/metavoice-src', './mvsrc'])
655
- time.sleep(3)
656
- subprocess.run(['pip', 'uninstall', '-y', 'pydantic', 'spacy'])
657
- subprocess.run(['pip', 'install', '-U', 'fastapi', 'spacy', 'transformers', 'flash-attn'])
658
- move_files_and_subdirs("mvsrc")
659
- time.sleep(3)
660
- serving = subprocess.Popen(['python', 'fam/llm/serving.py', '--huggingface_repo_id', 'metavoiceio/metavoice-1B-v0.1'])
661
- # subprocess.run(['pip', 'install', '-r', 'requirements.txt'])
662
- setup_virtual_env()
663
- subprocess.run(['python', 'fam/ui/app.py'])
664
- # subprocess.run(['deactivate'], shell=True)
665
-
666
- serving.communicate()
667
-
668
-
669
-
670
-
671
  pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2", torch_dtype=torch.float16)
672
  pipe.to(device)
673
 
@@ -701,7 +618,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
701
  gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
702
  chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
703
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
704
- tts_choice = gr.Radio(label="Select TTS System", choices=["Eleven Labs", "Parler-TTS", "MARS5", "Meta Voice"], value="Eleven Labs")
705
  bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
706
  bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
707
  chatbot.like(print_like_dislike, None, None)
 
585
  logging.debug(f"Audio saved to {combined_audio_path}")
586
  return combined_audio_path
587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2", torch_dtype=torch.float16)
589
  pipe.to(device)
590
 
 
618
  gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
619
  chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
620
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
621
+ tts_choice = gr.Radio(label="Select TTS System", choices=["Eleven Labs", "Parler-TTS", "MARS5"], value="Eleven Labs")
622
  bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
623
  bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
624
  chatbot.like(print_like_dislike, None, None)