drewThomasson commited on
Commit
d069ecb
1 Parent(s): f98361b

fixed model not loading on cpu, and fixed local

Browse files
Files changed (1) hide show
  1. app.py +40 -2
app.py CHANGED
@@ -20,6 +20,7 @@ import gradio as gr
20
  from gradio import Progress
21
  import urllib.request
22
  import zipfile
 
23
  #import MeCab
24
  #import unidic
25
 
@@ -28,6 +29,9 @@ nltk.download('punkt_tab')
28
  # Pre-download the xtts TOS agreed file
29
  import download_tos_agreed_file
30
 
 
 
 
31
  # Download UniDic if it's not already installed
32
  #unidic.download()
33
 
@@ -395,6 +399,21 @@ from pydub import AudioSegment
395
 
396
  default_target_voice_path = "default_voice.wav" # Ensure this is a valid path
397
  default_language_code = "en"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
  def combine_wav_files(input_directory, output_directory, file_name):
399
  # Ensure that the output directory exists, create it if necessary
400
  os.makedirs(output_directory, exist_ok=True)
@@ -468,7 +487,7 @@ def convert_chapters_to_audio_custom_model(chapters_dir, output_audio_dir, targe
468
  config.load_json(custom_model['config'])
469
  model = Xtts.init_from_config(config)
470
  model.load_checkpoint(config, checkpoint_path=custom_model['model'], vocab_path=custom_model['vocab'], use_deepspeed=False)
471
- model.device
472
  print("Computing speaker latents...")
473
  gpt_cond_latent, speaker_embedding = model.get_conditioning_latents(audio_path=[target_voice_path])
474
  else:
@@ -585,6 +604,11 @@ def convert_ebook_to_audio(ebook_file, target_voice_file, language, use_custom_m
585
  print(f"Received custom model URL: {custom_model_url}")
586
  download_dir = os.path.join(".", "Working_files", "custom_model")
587
  download_and_extract_zip(custom_model_url, download_dir)
 
 
 
 
 
588
  custom_model = {
589
  'model': os.path.join(download_dir, 'model.pth'),
590
  'config': os.path.join(download_dir, 'config.json'),
@@ -709,5 +733,19 @@ with gr.Blocks(theme=theme) as demo:
709
  outputs=[download_files]
710
  )
711
 
 
 
 
712
  #demo.launch(share=True)
713
- demo.launch() # Removing share = True for Gradio Interface
 
 
 
 
 
 
 
 
 
 
 
 
20
  from gradio import Progress
21
  import urllib.request
22
  import zipfile
23
+ import socket
24
  #import MeCab
25
  #import unidic
26
 
 
29
  # Pre-download the xtts TOS agreed file
30
  import download_tos_agreed_file
31
 
32
+ # Import the locally stored Xtts default model
33
+ import import_locally_stored_tts_model_files
34
+
35
  # Download UniDic if it's not already installed
36
  #unidic.download()
37
 
 
399
 
400
  default_target_voice_path = "default_voice.wav" # Ensure this is a valid path
401
  default_language_code = "en"
402
+
403
+
404
+ # Function to check if vocab.json exists and rename it
405
+ def rename_vocab_file_if_exists(directory):
406
+ vocab_path = os.path.join(directory, 'vocab.json')
407
+ new_vocab_path = os.path.join(directory, 'vocab.json_')
408
+
409
+ # Check if vocab.json exists
410
+ if os.path.exists(vocab_path):
411
+ # Rename the file
412
+ os.rename(vocab_path, new_vocab_path)
413
+ print(f"Renamed {vocab_path} to {new_vocab_path}")
414
+ return True # Return True if the file was found and renamed
415
+
416
+
417
  def combine_wav_files(input_directory, output_directory, file_name):
418
  # Ensure that the output directory exists, create it if necessary
419
  os.makedirs(output_directory, exist_ok=True)
 
487
  config.load_json(custom_model['config'])
488
  model = Xtts.init_from_config(config)
489
  model.load_checkpoint(config, checkpoint_path=custom_model['model'], vocab_path=custom_model['vocab'], use_deepspeed=False)
490
+ model.to(device)
491
  print("Computing speaker latents...")
492
  gpt_cond_latent, speaker_embedding = model.get_conditioning_latents(audio_path=[target_voice_path])
493
  else:
 
604
  print(f"Received custom model URL: {custom_model_url}")
605
  download_dir = os.path.join(".", "Working_files", "custom_model")
606
  download_and_extract_zip(custom_model_url, download_dir)
607
+
608
+ # Check if vocab.json exists and rename it
609
+ if rename_vocab_file_if_exists(download_dir):
610
+ print("vocab.json file was found and renamed.")
611
+
612
  custom_model = {
613
  'model': os.path.join(download_dir, 'model.pth'),
614
  'config': os.path.join(download_dir, 'config.json'),
 
733
  outputs=[download_files]
734
  )
735
 
736
+
737
+
738
+
739
  #demo.launch(share=True)
740
+ #demo.launch() # Removing share = True for Gradio Interface
741
+
742
+ # Get the correct local IP or localhost
743
+ hostname = socket.gethostname()
744
+ local_ip = socket.gethostbyname(hostname)
745
+
746
+ # Ensure Gradio runs and prints the correct local IP
747
+ print(f"Running on local URL: http://{local_ip}:7860")
748
+ print(f"Running on local URL: http://localhost:7860")
749
+
750
+ # Your Gradio launch command
751
+ demo.launch(server_name="0.0.0.0", server_port=7860)