Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -636,13 +636,23 @@ def convert_ebook_to_audio(ebook_file, target_voice_file, language, use_custom_m
|
|
| 636 |
remove_folder_with_contents(full_folder_working_files)
|
| 637 |
remove_folder_with_contents(output_audio_directory)
|
| 638 |
|
|
|
|
|
|
|
|
|
|
| 639 |
if use_custom_model and custom_model_file and custom_config_file and custom_vocab_file:
|
| 640 |
custom_model = {
|
| 641 |
'model': custom_model_file.name,
|
| 642 |
'config': custom_config_file.name,
|
| 643 |
'vocab': custom_vocab_file.name
|
| 644 |
}
|
| 645 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 646 |
print(f"Received custom model URL: {custom_model_url}")
|
| 647 |
download_dir = os.path.join(".", "Working_files", "custom_model")
|
| 648 |
download_and_extract_zip(custom_model_url, download_dir)
|
|
@@ -791,6 +801,9 @@ def run_gradio_interface():
|
|
| 791 |
|
| 792 |
# Check if running in headless mode
|
| 793 |
if args.headless:
|
|
|
|
|
|
|
|
|
|
| 794 |
if not args.ebook:
|
| 795 |
print("Error: In headless mode, you must specify an ebook file using --ebook.")
|
| 796 |
exit(1)
|
|
@@ -800,14 +813,28 @@ if args.headless:
|
|
| 800 |
custom_model = None
|
| 801 |
|
| 802 |
if args.use_custom_model:
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
|
| 809 |
# Example headless execution
|
| 810 |
-
convert_ebook_to_audio(ebook_file_path, target_voice, args.language, args.use_custom_model, args.custom_model, args.custom_config, args.custom_vocab)
|
| 811 |
|
| 812 |
else:
|
| 813 |
# Launch Gradio UI
|
|
|
|
| 636 |
remove_folder_with_contents(full_folder_working_files)
|
| 637 |
remove_folder_with_contents(output_audio_directory)
|
| 638 |
|
| 639 |
+
# If the language argument is set use it instead
|
| 640 |
+
language = args.language if args.language else language
|
| 641 |
+
|
| 642 |
if use_custom_model and custom_model_file and custom_config_file and custom_vocab_file:
|
| 643 |
custom_model = {
|
| 644 |
'model': custom_model_file.name,
|
| 645 |
'config': custom_config_file.name,
|
| 646 |
'vocab': custom_vocab_file.name
|
| 647 |
}
|
| 648 |
+
# If headless is used with the custom model arguments
|
| 649 |
+
if args.use_custom_model and args.custom_model and args.custom_config and args.custom_vocab:
|
| 650 |
+
custom_model = {
|
| 651 |
+
'model': args.custom_model,
|
| 652 |
+
'config': args.custom_config,
|
| 653 |
+
'vocab': args.custom_vocab
|
| 654 |
+
}
|
| 655 |
+
if (use_custom_model and custom_model_url) or (args.use_custom_model and custom_model_url):
|
| 656 |
print(f"Received custom model URL: {custom_model_url}")
|
| 657 |
download_dir = os.path.join(".", "Working_files", "custom_model")
|
| 658 |
download_and_extract_zip(custom_model_url, download_dir)
|
|
|
|
| 801 |
|
| 802 |
# Check if running in headless mode
|
| 803 |
if args.headless:
|
| 804 |
+
# If the arg.custom_model_url exists then use it as the custom_model_url lol
|
| 805 |
+
custom_model_url = args.custom_model_url if args.custom_model_url else None
|
| 806 |
+
|
| 807 |
if not args.ebook:
|
| 808 |
print("Error: In headless mode, you must specify an ebook file using --ebook.")
|
| 809 |
exit(1)
|
|
|
|
| 813 |
custom_model = None
|
| 814 |
|
| 815 |
if args.use_custom_model:
|
| 816 |
+
# Check if custom_model_url is provided
|
| 817 |
+
if args.custom_model_url:
|
| 818 |
+
# Download the custom model from the provided URL
|
| 819 |
+
custom_model_url = args.custom_model_url
|
| 820 |
+
else:
|
| 821 |
+
# If no URL is provided, ensure all custom model files are provided
|
| 822 |
+
if not args.custom_model or not args.custom_config or not args.custom_vocab:
|
| 823 |
+
print("Error: You must provide either a --custom_model_url or all of the following arguments:")
|
| 824 |
+
print("--custom_model, --custom_config, and --custom_vocab")
|
| 825 |
+
exit(1)
|
| 826 |
+
else:
|
| 827 |
+
# Assign the custom model files
|
| 828 |
+
custom_model = {
|
| 829 |
+
'model': args.custom_model,
|
| 830 |
+
'config': args.custom_config,
|
| 831 |
+
'vocab': args.custom_vocab
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
|
| 835 |
|
| 836 |
# Example headless execution
|
| 837 |
+
convert_ebook_to_audio(ebook_file_path, target_voice, args.language, args.use_custom_model, args.custom_model, args.custom_config, args.custom_vocab, custom_model_url)
|
| 838 |
|
| 839 |
else:
|
| 840 |
# Launch Gradio UI
|