Update NEW_TESTING_app.py
Browse files- NEW_TESTING_app.py +48 -0
NEW_TESTING_app.py
CHANGED
@@ -1,3 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Global variables for dropdown and checkbox
|
2 |
character_accent = None
|
3 |
use_narrator_voice_y_n = None
|
@@ -10,6 +17,9 @@ def process_ebook(ebook_file, character_accent, use_narrator_voice_y_n, state):
|
|
10 |
if not ebook_file:
|
11 |
return "No file uploaded.", state
|
12 |
|
|
|
|
|
|
|
13 |
# Pre-download the xtts TOS agreed file
|
14 |
import download_tos_agreed_file
|
15 |
|
@@ -74,6 +84,44 @@ def run_subprocess(input_file_path, character_accent, use_narrator_voice_y_n, st
|
|
74 |
with state["lock"]:
|
75 |
state["output"] += f"\nError: {str(e)}"
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# Gradio Interface
|
78 |
with gr.Blocks() as gui:
|
79 |
gr.Markdown("### Ebook to Audiobook Converter")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import shutil
|
4 |
+
import subprocess
|
5 |
+
import threading
|
6 |
+
import time
|
7 |
+
|
8 |
# Global variables for dropdown and checkbox
|
9 |
character_accent = None
|
10 |
use_narrator_voice_y_n = None
|
|
|
17 |
if not ebook_file:
|
18 |
return "No file uploaded.", state
|
19 |
|
20 |
+
# Convert selected accent to its index +1
|
21 |
+
character_accent = str(languages.index(character_accent) + 1)
|
22 |
+
|
23 |
# Pre-download the xtts TOS agreed file
|
24 |
import download_tos_agreed_file
|
25 |
|
|
|
84 |
with state["lock"]:
|
85 |
state["output"] += f"\nError: {str(e)}"
|
86 |
|
87 |
+
# Function to send user input to the subprocess
|
88 |
+
def send_input(user_input, state):
|
89 |
+
if not state or "process" not in state or state["process"] is None:
|
90 |
+
return "Process is not running."
|
91 |
+
|
92 |
+
process = state["process"]
|
93 |
+
if process.poll() is not None:
|
94 |
+
return "Process has already finished."
|
95 |
+
|
96 |
+
try:
|
97 |
+
# Send the input followed by a newline
|
98 |
+
process.stdin.write(user_input + "\n")
|
99 |
+
process.stdin.flush()
|
100 |
+
return "Input sent successfully."
|
101 |
+
except Exception as e:
|
102 |
+
return f"Failed to send input: {str(e)}"
|
103 |
+
|
104 |
+
# Function to update the output display
|
105 |
+
def get_output(state):
|
106 |
+
if not state:
|
107 |
+
return "No process started."
|
108 |
+
|
109 |
+
with state["lock"]:
|
110 |
+
return state["output"]
|
111 |
+
|
112 |
+
# Function to list output files for downloading
|
113 |
+
def list_output_files():
|
114 |
+
# List all files in the output directory for downloading
|
115 |
+
output_dir = "output_audiobooks"
|
116 |
+
if os.path.exists(output_dir):
|
117 |
+
files = [
|
118 |
+
os.path.join(output_dir, f)
|
119 |
+
for f in os.listdir(output_dir)
|
120 |
+
if os.path.isfile(os.path.join(output_dir, f))
|
121 |
+
]
|
122 |
+
return files
|
123 |
+
return []
|
124 |
+
|
125 |
# Gradio Interface
|
126 |
with gr.Blocks() as gui:
|
127 |
gr.Markdown("### Ebook to Audiobook Converter")
|