|
import gradio as gr |
|
import os |
|
import shutil |
|
import subprocess |
|
|
|
|
|
gradio_input_file = None |
|
|
|
def process_ebook(ebook_file): |
|
|
|
import download_tos_agreed_file |
|
|
|
import nltk |
|
nltk.download('averaged_perceptron_tagger_eng') |
|
nltk.download('punkt_tab') |
|
|
|
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"]) |
|
global gradio_input_file |
|
|
|
|
|
input_dir = "input_files" |
|
if not os.path.exists(input_dir): |
|
os.mkdir(input_dir) |
|
|
|
|
|
input_file_path = os.path.join(input_dir, os.path.basename(ebook_file)) |
|
shutil.copy(ebook_file, input_file_path) |
|
|
|
|
|
gradio_input_file = input_file_path |
|
|
|
|
|
ebook_file_name = os.path.basename(ebook_file) |
|
print(f"Uploaded file: {ebook_file_name}") |
|
|
|
|
|
try: |
|
process = subprocess.Popen( |
|
["python3", "Auto_VoxNovel.py", gradio_input_file], |
|
stdout=subprocess.PIPE, |
|
stderr=subprocess.STDOUT, |
|
text=True |
|
) |
|
|
|
|
|
for line in process.stdout: |
|
print(line, end='') |
|
|
|
process.wait() |
|
|
|
if process.returncode == 0: |
|
return f"Audiobook is ready! You can now download your files." |
|
else: |
|
return "Error occurred during audiobook processing." |
|
except Exception as e: |
|
return f"Failed to run audiobook script: {str(e)}" |
|
|
|
|
|
def list_output_files(): |
|
|
|
output_dir = "output_audiobooks" |
|
if os.path.exists(output_dir): |
|
files = [ |
|
os.path.join(output_dir, f) |
|
for f in os.listdir(output_dir) |
|
if os.path.isfile(os.path.join(output_dir, f)) |
|
] |
|
return files |
|
return [] |
|
|
|
|
|
with gr.Blocks() as gui: |
|
gr.Markdown("### VoxNovel Ebook to Audiobook Converter: Give each character a separate voice. <br>This interface is based on [VoxNovel](https://github.com/DrewThomasson/VoxNovel).<br>This version default uses StyleTTS2 for slightly faster voice cloning than XTTS.<br> This one only works with English txt files sadly. 😔") |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
ebook_input = gr.File( |
|
label="Upload your ebook file (epub, pdf, etc.)", |
|
type='filepath' |
|
) |
|
process_button = gr.Button("Start Processing") |
|
status_output = gr.Textbox(label="Status") |
|
process_button.click(process_ebook, inputs=ebook_input, outputs=status_output) |
|
demo_audio = gr.Audio(label="Play Demo", value="demo.mp3", type="filepath") |
|
|
|
with gr.Column(): |
|
gr.Markdown("### Download Generated Audiobook Files") |
|
download_button = gr.Button("Reload Files") |
|
file_output = gr.Files( |
|
label="Generated Audiobook Files", |
|
type='filepath' |
|
) |
|
|
|
|
|
def update_output_files(): |
|
files = list_output_files() |
|
return files |
|
|
|
download_button.click(fn=update_output_files, inputs=[], outputs=file_output) |
|
|
|
gui.launch() |
|
|