drewThomasson commited on
Commit
40f31ac
1 Parent(s): c75eb9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -78
app.py CHANGED
@@ -1,43 +1,22 @@
1
  import gradio as gr
2
  import os
3
- import shutil
4
  import subprocess
5
 
6
-
 
7
 
8
  def process_ebook(ebook_file):
9
- # Ensure input_files folder exists
10
- input_dir = "input_files"
11
- os.makedirs(input_dir, exist_ok=True)
12
-
13
- # Check if input_files folder is empty
14
- if not os.listdir(input_dir):
15
- raise FileNotFoundError("The folder 'input_files' is empty. Please upload a file.")
16
 
17
- # Get the base name and extension of the uploaded file
18
  ebook_file_name = os.path.basename(ebook_file)
19
- file_name, file_extension = os.path.splitext(ebook_file_name)
20
-
21
- # Define the new file name with "_Audiobook"
22
- new_file_name = f"{file_name}_Audiobook{file_extension}"
23
- new_file_path = os.path.join(input_dir, new_file_name)
24
-
25
- # Copy the uploaded file to the input_files folder with the new name
26
- shutil.copy(ebook_file, new_file_path)
27
-
28
- # print the name of the new file
29
- print (f"File duplicated as: {new_file_name} in 'input_files' folder")
30
 
31
- # Print the list of input files in the terminal
32
- print(f"Files in input_files folder:\n{input_files_str}")
33
-
34
- if not os.listdir("input_files"):
35
- raise FileNotFoundError("The folder 'input_files' is empty.")
36
-
37
- # Call the Auto_VoxNovel.py script and stream its output live
38
  try:
39
  process = subprocess.Popen(
40
- ["python3", "Auto_VoxNovel.py"],
41
  stdout=subprocess.PIPE,
42
  stderr=subprocess.STDOUT,
43
  text=True
@@ -50,58 +29,12 @@ def process_ebook(ebook_file):
50
  process.wait()
51
 
52
  if process.returncode == 0:
53
- return f"Audiobook is ready! You can now download your files below.\n\nInput files:\n{input_files_str}"
54
  else:
55
- return f"Error occurred during audiobook processing.\n\nInput files:\n{input_files_str}"
56
  except Exception as e:
57
- return f"Failed to run audiobook script: {str(e)}\n\nInput files:\n{input_files_str}"
58
-
59
-
60
-
61
 
62
- #def process_ebook(ebook_file):
63
- # # Ensure input_files folder exists
64
- # input_dir = "input_files"
65
- # os.makedirs(input_dir, exist_ok=True)
66
- #
67
- # # Get the base name of the uploaded file
68
- # ebook_file_name = os.path.basename(ebook_file)
69
- # ebook_file_path = os.path.join(input_dir, ebook_file_name)
70
- #
71
- # # Copy the file to the input_files directory if it doesn't already exist there
72
- # if not os.path.exists(ebook_file_path):
73
- # shutil.copy(ebook_file, ebook_file_path)
74
- #
75
- # # List the contents of the input_files folder
76
- # input_files_list = os.listdir(input_dir)
77
- # input_files_str = "\n".join(input_files_list)
78
- #
79
- # # Print the list of input files in the terminal
80
- # print(f"Files in input_files folder:\n{input_files_str}")
81
- # if not os.listdir("input_files"):
82
- # raise FileNotFoundError("The folder 'input_files' is empty.")
83
- #
84
- # # Call the Auto_VoxNovel.py script and stream its output live
85
- # try:
86
- # process = subprocess.Popen(
87
- # ["python3", "Auto_VoxNovel.py"],
88
- # stdout=subprocess.PIPE,
89
- # stderr=subprocess.STDOUT,
90
- # text=True
91
- # )
92
- #
93
- # # Print output in real-time
94
- # for line in process.stdout:
95
- # print(line, end='')
96
- #
97
- # process.wait()
98
- #
99
- # if process.returncode == 0:
100
- # return f"Audiobook is ready! You can now download your files below.\n\nInput files:\n{input_files_str}"
101
- # else:
102
- # return f"Error occurred during audiobook processing.\n\nInput files:\n{input_files_str}"
103
- # except Exception as e:
104
- # return f"Failed to run audiobook script: {str(e)}\n\nInput files:\n{input_files_str}"
105
 
106
  def list_output_files():
107
  # List all files in the output directory for downloading
 
1
  import gradio as gr
2
  import os
 
3
  import subprocess
4
 
5
+ # Declare the global variable
6
+ gradio_input_file = None
7
 
8
  def process_ebook(ebook_file):
9
+ global gradio_input_file # Use the global variable to store the ebook file path
10
+ gradio_input_file = ebook_file # Assign the file path to the global variable
 
 
 
 
 
11
 
12
+ # Print the name of the uploaded file
13
  ebook_file_name = os.path.basename(ebook_file)
14
+ print(f"Uploaded file: {ebook_file_name}")
 
 
 
 
 
 
 
 
 
 
15
 
16
+ # Call the Auto_VoxNovel.py script and pass the file path as an argument
 
 
 
 
 
 
17
  try:
18
  process = subprocess.Popen(
19
+ ["python3", "Auto_VoxNovel.py", gradio_input_file], # Pass gradio_input_file as an argument
20
  stdout=subprocess.PIPE,
21
  stderr=subprocess.STDOUT,
22
  text=True
 
29
  process.wait()
30
 
31
  if process.returncode == 0:
32
+ return f"Audiobook is ready! You can now download your files."
33
  else:
34
+ return "Error occurred during audiobook processing."
35
  except Exception as e:
36
+ return f"Failed to run audiobook script: {str(e)}"
 
 
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  def list_output_files():
40
  # List all files in the output directory for downloading