Spaces:
Build error
Build error
Upload 4 files
Browse files
Notebooks/colab_ebook2audiobook.ipynb
ADDED
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": [],
|
7 |
+
"gpuType": "T4",
|
8 |
+
"include_colab_link": true
|
9 |
+
},
|
10 |
+
"kernelspec": {
|
11 |
+
"name": "python3",
|
12 |
+
"display_name": "Python 3"
|
13 |
+
},
|
14 |
+
"language_info": {
|
15 |
+
"name": "python"
|
16 |
+
},
|
17 |
+
"accelerator": "GPU"
|
18 |
+
},
|
19 |
+
"cells": [
|
20 |
+
{
|
21 |
+
"cell_type": "markdown",
|
22 |
+
"metadata": {
|
23 |
+
"id": "view-in-github",
|
24 |
+
"colab_type": "text"
|
25 |
+
},
|
26 |
+
"source": [
|
27 |
+
"<a href=\"https://colab.research.google.com/github/DrewThomasson/ebook2audiobook/blob/v25/Notebooks/colab_ebook2audiobook.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
28 |
+
]
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"cell_type": "markdown",
|
32 |
+
"source": [
|
33 |
+
"## Welcome to the ebook2audiobook free google colab!\n",
|
34 |
+
"## π Features\n",
|
35 |
+
"\n",
|
36 |
+
"- π Converts eBooks to text format with Calibre.\n",
|
37 |
+
"- π Splits eBook into chapters for organized audio.\n",
|
38 |
+
"- ποΈ High-quality text-to-speech with [Coqui XTTS](https://huggingface.co/coqui/XTTS-v2), [Fairseq](https://github.com/facebookresearch/fairseq), [Bark](https://github.com/suno-ai/bark), [Vits](https://github.com/jaywalnut310/vits), and [Yourtts](https://github.com/Edresson/YourTTS).\n",
|
39 |
+
"- π£οΈ Optional voice cloning with your own voice file or choose from our pre-made fine-tuned models!\n",
|
40 |
+
"- π Supports multiple languages! Arabic (ar), Chinese (zh-cn), Czech (cs), Dutch (nl), English (en), French (fr), German (de), Hindi (hi), Hungarian (hu), Italian (it), Japanese (ja), Korean (ko), Polish (pl), Portuguese (pt), Russian (ru), Spanish (es), Turkish (tr), Vietnamese (vi), [+ 1107 languages via Fairseq](https://dl.fbaipublicfiles.com/mms/tts/all-tts-languages.html)\n",
|
41 |
+
"## Want to run locally for free? β¬\n",
|
42 |
+
"## [Check out the ebook2audiobook github!](https://github.com/DrewThomasson/ebook2audiobook)"
|
43 |
+
],
|
44 |
+
"metadata": {
|
45 |
+
"id": "DKNNnwD-HJwQ"
|
46 |
+
}
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"cell_type": "code",
|
50 |
+
"source": [
|
51 |
+
"# @title π Run ebook2audiobook!\n",
|
52 |
+
"\n",
|
53 |
+
"import os\n",
|
54 |
+
"import re\n",
|
55 |
+
"import subprocess\n",
|
56 |
+
"import time # Import the time module\n",
|
57 |
+
"from IPython.display import HTML, display\n",
|
58 |
+
"import pkg_resources # For checking installed packages\n",
|
59 |
+
"\n",
|
60 |
+
"# Emojis for logs\n",
|
61 |
+
"CHECK_MARK = \"β
\"\n",
|
62 |
+
"CROSS_MARK = \"β\"\n",
|
63 |
+
"\n",
|
64 |
+
"def display_loading_bar(total_steps):\n",
|
65 |
+
" \"\"\"Displays a more visual text-based loading indicator in Colab.\"\"\"\n",
|
66 |
+
" print(\"\\n--- LOADING... Total steps:\", total_steps, \" ---\") # Separator and loading start\n",
|
67 |
+
"\n",
|
68 |
+
"def update_progress(step, total_steps):\n",
|
69 |
+
" \"\"\"Updates the text-based loading indicator with a bar-like style.\"\"\"\n",
|
70 |
+
" bar_length = 20 # Length of the \"bar\"\n",
|
71 |
+
" progress_percent = int((step / total_steps) * 100)\n",
|
72 |
+
" progress_filled = int(bar_length * step / total_steps)\n",
|
73 |
+
" bar = '=' * progress_filled + '>' + ' ' * (bar_length - progress_filled -1 if (bar_length - progress_filled -1) >= 0 else 0) # Handle potential index error\n",
|
74 |
+
" progress_text = f\"[{bar}] {progress_percent}% ({step}/{total_steps})\"\n",
|
75 |
+
" print(f\"--- PROGRESS: {progress_text} ---\") # Separator for progress update\n",
|
76 |
+
"\n",
|
77 |
+
"def run_command_with_log(command, description, step_progress, total_step_commands):\n",
|
78 |
+
" \"\"\"Runs a command and logs its progress and outcome with emojis and duration.\"\"\"\n",
|
79 |
+
" print(f\"\\n{step_progress}/{total_step_commands}: {description}...\")\n",
|
80 |
+
" start_time = time.time() # Record start time\n",
|
81 |
+
" try:\n",
|
82 |
+
" process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
83 |
+
" stdout, stderr = process.communicate()\n",
|
84 |
+
" end_time = time.time() # Record end time\n",
|
85 |
+
" duration = end_time - start_time # Calculate duration\n",
|
86 |
+
" duration_formatted = \"{:.2f}\".format(duration) # Format duration to 2 decimal places\n",
|
87 |
+
"\n",
|
88 |
+
" if process.returncode != 0:\n",
|
89 |
+
" print(f\"{CROSS_MARK} Command failed: {description} (Took {duration_formatted} seconds)\")\n",
|
90 |
+
" print(f\" Command: {command}\")\n",
|
91 |
+
" print(f\" Error Output:\\n{stderr.decode()}\")\n",
|
92 |
+
" return False\n",
|
93 |
+
" else:\n",
|
94 |
+
" update_progress(step_progress, total_step_commands) # Use updated progress function\n",
|
95 |
+
" print(f\"{CHECK_MARK} Command {step_progress}/{total_step_commands} completed: {description} (Took {duration_formatted} seconds)\")\n",
|
96 |
+
" return True\n",
|
97 |
+
"\n",
|
98 |
+
" except Exception as e:\n",
|
99 |
+
" end_time = time.time() # Record end time even if exception occurs\n",
|
100 |
+
" duration = end_time - start_time # Calculate duration\n",
|
101 |
+
" duration_formatted = \"{:.2f}\".format(duration) # Format duration\n",
|
102 |
+
" print(f\"{CROSS_MARK} A general error occurred during command: {description} (Took {duration_formatted} seconds)\")\n",
|
103 |
+
" print(f\" Error: {e}\")\n",
|
104 |
+
" return False\n",
|
105 |
+
"\n",
|
106 |
+
"# --- Step 1: OS-Level Installations ---\n",
|
107 |
+
"os_install_commands = [\n",
|
108 |
+
" (\"sudo apt-get update\", \"Updating software package lists (Takes around 14.14 seconds)\"),\n",
|
109 |
+
" (\"apt-get install -y libxcb-cursor0\", \"Install cursor display library (libxcb-cursor0 - for Calibre) (Takes around 12.99 seconds)\"),\n",
|
110 |
+
" (\"sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin\", \"Download & install Calibre ebook manager(Takes around 29.40 seconds)\"),\n",
|
111 |
+
" (\"apt-get install -y libegl1\", \"Install graphics library (libegl1) (Takes around 4.12 seconds)\"),\n",
|
112 |
+
" (\"apt-get install -y libopengl0\", \"Install graphics library (libopengl0) (Takes around 3.07 seconds)\"),\n",
|
113 |
+
" (\"apt-get install -y ffmpeg\", \"Install ffmpeg (audio/video conversion) (Takes around 3.52 seconds)\"),\n",
|
114 |
+
" (\"apt-get install -y espeak-ng\", \"Install espeak-ng (espeak-ng tts engine) (Takes around 3.52 seconds)\"),\n",
|
115 |
+
" (\"apt-get install -y mecab\", \"Install mecab (Japanese text analysis) (Takes around 14.51 seconds)\"),\n",
|
116 |
+
" (\"apt-get install -y libmecab-dev\", \"Install mecab development files (Takes around 5.72 seconds)\"),\n",
|
117 |
+
" (\"apt-get install -y mecab-ipadic-utf8\", \"Install mecab Japanese dictionary (UTF-8) (Takes around 9.58 seconds)\"),\n",
|
118 |
+
" (\"apt-get install -y nodejs\", \"Install nodejs (Javascript runtime) (Takes around 7.03 seconds)\"),\n",
|
119 |
+
" (\"pip install mecab-python3 unidic-lite\", \"Install mecab-python3 (Takes around 19.80 seconds)\"),\n",
|
120 |
+
" (\"pip install unidic-lite\", \"Install lightweight unidic dictionary (Takes around 2.15 seconds)\"),\n",
|
121 |
+
" (\"pip install unidic\", \"Install full Unidic dictionary (Takes around 4.00 seconds)\"),\n",
|
122 |
+
" (\"python -m unidic download\", \"Download Unidic dictionary data (Takes around 29.05 seconds)\"),\n",
|
123 |
+
"]\n",
|
124 |
+
"os_install_completed = False\n",
|
125 |
+
"\n",
|
126 |
+
"# --- Step 2: Git Clone & Requirements ---\n",
|
127 |
+
"git_requirements_commands = [\n",
|
128 |
+
" (\"git clone https://github.com/DrewThomasson/ebook2audiobook.git\", \"Git clone Ebook2audiobook\"),\n",
|
129 |
+
" (\"pip install -r /content/ebook2audiobook/requirements.txt\", \"Install Python requirements (Takes around 202.4 seconds)\"),\n",
|
130 |
+
"]\n",
|
131 |
+
"git_requirements_completed = False\n",
|
132 |
+
"\n",
|
133 |
+
"# --- Step 3: Run App ---\n",
|
134 |
+
"run_app_completed = False\n",
|
135 |
+
"\n",
|
136 |
+
"\n",
|
137 |
+
"# --- Step 1 Execution ---\n",
|
138 |
+
"if os_install_completed:\n",
|
139 |
+
" print(\"\\nStep 1: OS-Level Installations - Already completed, skipping.\")\n",
|
140 |
+
"else:\n",
|
141 |
+
" print(\"\\n--- Step 1: OS-Level Installations ---\")\n",
|
142 |
+
" print(\"This step installs essential software on the Colab system. (Takes around 3-4 minutes)\")\n",
|
143 |
+
" total_steps_step1 = len(os_install_commands)\n",
|
144 |
+
" display_loading_bar(total_steps_step1) # Start enhanced loading indicator\n",
|
145 |
+
"\n",
|
146 |
+
" step1_success = True\n",
|
147 |
+
" for i, (command, description) in enumerate(os_install_commands):\n",
|
148 |
+
" if not run_command_with_log(command, description, i + 1, total_steps_step1):\n",
|
149 |
+
" step1_success = False\n",
|
150 |
+
" break\n",
|
151 |
+
"\n",
|
152 |
+
" if step1_success:\n",
|
153 |
+
" os_install_completed = True\n",
|
154 |
+
" print(f\"\\n{CHECK_MARK} Step 1: OS-Level Installations - Completed Successfully!\")\n",
|
155 |
+
" else:\n",
|
156 |
+
" print(f\"\\n{CROSS_MARK} Step 1: OS-Level Installations - Failed. See error messages above.\")\n",
|
157 |
+
"\n",
|
158 |
+
"\n",
|
159 |
+
"# --- Step 2 Execution ---\n",
|
160 |
+
"if git_requirements_completed:\n",
|
161 |
+
" print(\"\\nStep 2: Git Clone & Requirements - Already completed, skipping.\")\n",
|
162 |
+
"else:\n",
|
163 |
+
" print(\"\\n--- Step 2: Git Clone & Requirements ---\")\n",
|
164 |
+
" print(\"This step downloads program files and installs Python components. (Takes around 3-4 minutes)\")\n",
|
165 |
+
" total_steps_step2 = len(git_requirements_commands)\n",
|
166 |
+
" display_loading_bar(total_steps_step2) # Start enhanced loading indicator\n",
|
167 |
+
"\n",
|
168 |
+
" step2_success = True\n",
|
169 |
+
" for i, (command, description) in enumerate(git_requirements_commands):\n",
|
170 |
+
" if not run_command_with_log(command, description, i + 1, total_steps_step2):\n",
|
171 |
+
" step2_success = False\n",
|
172 |
+
" break\n",
|
173 |
+
"\n",
|
174 |
+
" if step2_success:\n",
|
175 |
+
" git_requirements_completed = True\n",
|
176 |
+
" print(f\"\\n{CHECK_MARK} Step 2: Git Clone & Requirements - Completed Successfully!\")\n",
|
177 |
+
" else:\n",
|
178 |
+
" print(f\"\\n{CROSS_MARK} Step 2: Git Clone & Requirements - Failed. See error messages above.\")\n",
|
179 |
+
"\n",
|
180 |
+
"\n",
|
181 |
+
"def modify_python_version(filepath, new_version=(3, 11)):\n",
|
182 |
+
" \"\"\"\n",
|
183 |
+
" Modifies the min_python_version in a Python file.\n",
|
184 |
+
" (Function definition - same as before)\n",
|
185 |
+
" \"\"\"\n",
|
186 |
+
" try:\n",
|
187 |
+
" with open(filepath, 'r') as f:\n",
|
188 |
+
" file_content = f.read()\n",
|
189 |
+
" pattern = r\"min_python_version = \\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\"\n",
|
190 |
+
" def replacement(match):\n",
|
191 |
+
" return f\"min_python_version = ({new_version[0]}, {new_version[1]})\"\n",
|
192 |
+
" new_content = re.sub(pattern, replacement, file_content)\n",
|
193 |
+
" if new_content != file_content:\n",
|
194 |
+
" with open(filepath, 'w') as f:\n",
|
195 |
+
" f.write(new_content)\n",
|
196 |
+
" print(f\"Successfully changed min_python_version in {filepath} to {new_version}\")\n",
|
197 |
+
" else:\n",
|
198 |
+
" print(f\"min_python_version in {filepath} was already {new_version} or not found.\")\n",
|
199 |
+
" except FileNotFoundError:\n",
|
200 |
+
" print(f\"Error: File not found: {filepath}\")\n",
|
201 |
+
" except Exception as e:\n",
|
202 |
+
" print(f\"An error occurred: {e}\")\n",
|
203 |
+
"\n",
|
204 |
+
"def fix_functions_py(filepath):\n",
|
205 |
+
" \"\"\"\n",
|
206 |
+
" Scans functions.py and fixes the incorrect f-string issue if found.\n",
|
207 |
+
" \"\"\"\n",
|
208 |
+
" # Define the incorrect pattern (allowing indentation and triple quotes)\n",
|
209 |
+
" incorrect_pattern = r\"msg\\s*=\\s*f'Voice file \\{re\\.sub\\(r'_\\(24000\\|16000\\)\\\\.wav\\$', '', selected_name\\)\\} deleted!'\"\n",
|
210 |
+
"\n",
|
211 |
+
" # Correct replacement (keeping indentation)\n",
|
212 |
+
" correct_replacement = \"\"\" cleaned_name = re.sub(r'_(24000|16000)\\\\.wav$', '', selected_name)\n",
|
213 |
+
" msg = f\"Voice file {cleaned_name} deleted!\" \"\"\"\n",
|
214 |
+
"\n",
|
215 |
+
" try:\n",
|
216 |
+
" # Read the file\n",
|
217 |
+
" with open(filepath, \"r\") as file:\n",
|
218 |
+
" lines = file.readlines()\n",
|
219 |
+
"\n",
|
220 |
+
" # Check and replace the incorrect line\n",
|
221 |
+
" modified_lines = []\n",
|
222 |
+
" fixed = False\n",
|
223 |
+
"\n",
|
224 |
+
" for line in lines:\n",
|
225 |
+
" if re.search(incorrect_pattern, line.strip()): # Use regex search instead of exact match\n",
|
226 |
+
" print(\"π Found incorrect line in functions.py. Fixing it now...\")\n",
|
227 |
+
" modified_lines.append(correct_replacement + \"\\n\") # Add the corrected version\n",
|
228 |
+
" fixed = True\n",
|
229 |
+
" else:\n",
|
230 |
+
" modified_lines.append(line) # Keep other lines unchanged\n",
|
231 |
+
"\n",
|
232 |
+
" # Only overwrite the file if a fix was applied\n",
|
233 |
+
" if fixed:\n",
|
234 |
+
" with open(filepath, \"w\") as file:\n",
|
235 |
+
" file.writelines(modified_lines)\n",
|
236 |
+
" print(\"β
Fix applied successfully!\")\n",
|
237 |
+
" else:\n",
|
238 |
+
" print(\"β
No fix needed. The exact error line was not found.\")\n",
|
239 |
+
"\n",
|
240 |
+
" except FileNotFoundError:\n",
|
241 |
+
" print(f\"β Error: The file {filepath} was not found.\")\n",
|
242 |
+
" except Exception as e:\n",
|
243 |
+
" print(f\"β An error occurred: {e}\")\n",
|
244 |
+
"\n",
|
245 |
+
"# Modify conf.py AFTER git clone (Step 2 ensures clone is done)\n",
|
246 |
+
"filepath = \"/content/ebook2audiobook/lib/conf.py\"\n",
|
247 |
+
"modify_python_version(filepath)\n",
|
248 |
+
"\n",
|
249 |
+
"# Call the function to fix functions.py\n",
|
250 |
+
"filepath = \"/content/ebook2audiobook/lib/functions.py\"\n",
|
251 |
+
"fix_functions_py(filepath)\n",
|
252 |
+
"\n",
|
253 |
+
"\n",
|
254 |
+
"\n",
|
255 |
+
"\n",
|
256 |
+
"# --- Step 3 Execution ---\n",
|
257 |
+
"if run_app_completed:\n",
|
258 |
+
" print(\"\\nStep 3: Run App - Already run (or skipped).\")\n",
|
259 |
+
"else:\n",
|
260 |
+
" print(\"\\n--- Step 3: Run App ---\")\n",
|
261 |
+
" print(\"This step starts the ebook2audiobook web interface.\")\n",
|
262 |
+
" print(\"Starting ebook2audiobook...\")\n",
|
263 |
+
" try:\n",
|
264 |
+
" !cd ebook2audiobook && python app.py --script_mode full_docker --share\n",
|
265 |
+
" run_app_completed = True\n",
|
266 |
+
" except Exception as e:\n",
|
267 |
+
" print(f\"{CROSS_MARK} Error starting app.py: {e}\")\n",
|
268 |
+
" else:\n",
|
269 |
+
" print(f\"\\n{CHECK_MARK} Step 3: Run App - Started! Check the output above for the Gradio link.\")\n",
|
270 |
+
"\n",
|
271 |
+
"\n",
|
272 |
+
"print(\"\\n--- All Steps Initiated (or Skipped if Already Run) ---\")\n",
|
273 |
+
"print(\"Check the output above for details on each step.\")"
|
274 |
+
],
|
275 |
+
"metadata": {
|
276 |
+
"id": "Edxj355K0rUz",
|
277 |
+
"collapsed": true,
|
278 |
+
"cellView": "form"
|
279 |
+
},
|
280 |
+
"execution_count": null,
|
281 |
+
"outputs": []
|
282 |
+
}
|
283 |
+
]
|
284 |
+
}
|
Notebooks/finetune/xtts/colab_xtts_finetune_webui.ipynb
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": [],
|
7 |
+
"gpuType": "T4",
|
8 |
+
"include_colab_link": true
|
9 |
+
},
|
10 |
+
"kernelspec": {
|
11 |
+
"name": "python3",
|
12 |
+
"display_name": "Python 3"
|
13 |
+
},
|
14 |
+
"language_info": {
|
15 |
+
"name": "python"
|
16 |
+
},
|
17 |
+
"accelerator": "GPU"
|
18 |
+
},
|
19 |
+
"cells": [
|
20 |
+
{
|
21 |
+
"cell_type": "markdown",
|
22 |
+
"metadata": {
|
23 |
+
"id": "view-in-github",
|
24 |
+
"colab_type": "text"
|
25 |
+
},
|
26 |
+
"source": [
|
27 |
+
"<a href=\"https://colab.research.google.com/github/DrewThomasson/ebook2audiobook/blob/v25/Notebooks/finetune/xtts/colab_xtts_finetune_webui.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
28 |
+
]
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"cell_type": "markdown",
|
32 |
+
"source": [
|
33 |
+
"## Welcome to the *xtts*-finetune-webui gradio gui!\n",
|
34 |
+
"\n",
|
35 |
+
"This webui is a slightly modified copy of the official webui for finetune xtts.\n",
|
36 |
+
"\n",
|
37 |
+
"If you are looking for an option for normal XTTS use look here https://github.com/daswer123/xtts-webui"
|
38 |
+
],
|
39 |
+
"metadata": {
|
40 |
+
"id": "OVjEG_yGoC2W"
|
41 |
+
}
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"cell_type": "code",
|
45 |
+
"execution_count": null,
|
46 |
+
"metadata": {
|
47 |
+
"id": "44HpAIVRfJve",
|
48 |
+
"collapsed": true,
|
49 |
+
"cellView": "form"
|
50 |
+
},
|
51 |
+
"outputs": [],
|
52 |
+
"source": [
|
53 |
+
"# @title π οΈ Install requirments\n",
|
54 |
+
"#!DEBIAN_FRONTEND=noninteractive\n",
|
55 |
+
"!sudo apt-get update # && sudo apt-get -y upgrade\n",
|
56 |
+
"!sudo apt-get -y install libegl1\n",
|
57 |
+
"!sudo apt-get -y install libopengl0\n",
|
58 |
+
"!sudo apt-get -y install libxcb-cursor0\n",
|
59 |
+
"!pip install -r https://raw.githubusercontent.com/daswer123/xtts-finetune-webui/main/requirements.txt\n",
|
60 |
+
"!pip install gradio==4.44.1\n",
|
61 |
+
"!pip install fastapi==0.103.1\n",
|
62 |
+
"!pip install pydantic==2.3.0\n",
|
63 |
+
"\n",
|
64 |
+
"#More requirements\n",
|
65 |
+
"!nvcc --version #check cuda version if things break\n",
|
66 |
+
"!pip uninstall torch torchvision torchaudio -y\n",
|
67 |
+
"!pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cu121\n"
|
68 |
+
]
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"cell_type": "code",
|
72 |
+
"source": [
|
73 |
+
"# @title π Run interface\n",
|
74 |
+
"%cd /content/\n",
|
75 |
+
"!git clone https://github.com/DrewThomasson/xtts-finetune-webui.git\n",
|
76 |
+
"%cd /content/xtts-finetune-webui\n",
|
77 |
+
"!python xtts_demo.py --share"
|
78 |
+
],
|
79 |
+
"metadata": {
|
80 |
+
"id": "62Da1Q5AgN3W",
|
81 |
+
"cellView": "form"
|
82 |
+
},
|
83 |
+
"execution_count": null,
|
84 |
+
"outputs": []
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"cell_type": "code",
|
88 |
+
"source": [
|
89 |
+
"import shutil\n",
|
90 |
+
"import requests\n",
|
91 |
+
"import os\n",
|
92 |
+
"from tqdm import tqdm # Progress bar library\n",
|
93 |
+
"\n",
|
94 |
+
"# Define the paths\n",
|
95 |
+
"finetune_dir = '/content/xtts-finetune-webui/finetune_models/ready' # @param {type:\"string\"}\n",
|
96 |
+
"dataset_dir = '/content/xtts-finetune-webui/finetune_models/dataset' # @param {type:\"string\"}\n",
|
97 |
+
"\n",
|
98 |
+
"# Create a temporary directory to collect both folders before zipping\n",
|
99 |
+
"temp_dir = \"/content/temp_finetune_dataset\"\n",
|
100 |
+
"os.makedirs(temp_dir, exist_ok=True)\n",
|
101 |
+
"\n",
|
102 |
+
"# Copy both directories into the temporary directory with a progress bar\n",
|
103 |
+
"def copy_with_progress(src, dst):\n",
|
104 |
+
" total_files = sum(len(files) for _, _, files in os.walk(src))\n",
|
105 |
+
" with tqdm(total=total_files, desc=f\"Copying {os.path.basename(src)}\") as pbar:\n",
|
106 |
+
" for root, _, files in os.walk(src):\n",
|
107 |
+
" rel_path = os.path.relpath(root, src)\n",
|
108 |
+
" target_path = os.path.join(dst, rel_path)\n",
|
109 |
+
" os.makedirs(target_path, exist_ok=True)\n",
|
110 |
+
" for file in files:\n",
|
111 |
+
" shutil.copy(os.path.join(root, file), target_path)\n",
|
112 |
+
" pbar.update(1)\n",
|
113 |
+
"\n",
|
114 |
+
"copy_with_progress(finetune_dir, os.path.join(temp_dir, \"ready\"))\n",
|
115 |
+
"copy_with_progress(dataset_dir, os.path.join(temp_dir, \"dataset\"))\n",
|
116 |
+
"\n",
|
117 |
+
"# Create a zip file of the combined directories with progress\n",
|
118 |
+
"zip_filename = \"finetune_and_dataset.zip\"\n",
|
119 |
+
"with tqdm(total=100, desc=\"Zipping files\") as pbar:\n",
|
120 |
+
" shutil.make_archive(\"finetune_and_dataset\", 'zip', root_dir=temp_dir)\n",
|
121 |
+
" pbar.update(100)\n",
|
122 |
+
"\n",
|
123 |
+
"# Define a function to stream the upload with a progress bar\n",
|
124 |
+
"def upload_with_progress(file_path, url):\n",
|
125 |
+
" file_size = os.path.getsize(file_path)\n",
|
126 |
+
" with open(file_path, 'rb') as f, tqdm(\n",
|
127 |
+
" total=file_size, unit='B', unit_scale=True, desc=\"Uploading\"\n",
|
128 |
+
" ) as progress:\n",
|
129 |
+
" response = requests.post(\n",
|
130 |
+
" url,\n",
|
131 |
+
" files={\"file\": (file_path, f)},\n",
|
132 |
+
" stream=True,\n",
|
133 |
+
" headers={\"Connection\": \"keep-alive\"},\n",
|
134 |
+
" )\n",
|
135 |
+
" # Update the progress bar as chunks are sent\n",
|
136 |
+
" for chunk in response.iter_content(chunk_size=4096):\n",
|
137 |
+
" if chunk:\n",
|
138 |
+
" progress.update(len(chunk))\n",
|
139 |
+
" return response\n",
|
140 |
+
"\n",
|
141 |
+
"# Upload the zip file to file.io with a progress bar\n",
|
142 |
+
"response = upload_with_progress(zip_filename, \"https://file.io/?expires=1d\")\n",
|
143 |
+
"\n",
|
144 |
+
"# Parse the response and display the download link\n",
|
145 |
+
"if response.status_code == 200:\n",
|
146 |
+
" download_link = response.json().get('link', 'Error: No link found.')\n",
|
147 |
+
" print(f\"Your file is ready: {download_link}\")\n",
|
148 |
+
"else:\n",
|
149 |
+
" print(f\"Failed to upload: {response.status_code} - {response.text}\")\n"
|
150 |
+
],
|
151 |
+
"metadata": {
|
152 |
+
"id": "MYBWgKevr6S3",
|
153 |
+
"cellView": "form"
|
154 |
+
},
|
155 |
+
"execution_count": null,
|
156 |
+
"outputs": []
|
157 |
+
}
|
158 |
+
]
|
159 |
+
}
|
Notebooks/finetune/xtts/kaggle-xtts-finetune-webui-gradio-gui.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"colab":{"provenance":[],"gpuType":"T4"},"accelerator":"GPU","kaggle":{"accelerator":"gpu","dataSources":[],"dockerImageVersionId":30919,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Welcome to the *xtts*-finetune-webui gradio gui!\n\nThis webui is a slightly modified copy of the official webui for finetune xtts.\n\nIf you are looking for an option for normal XTTS use look here https://github.com/daswer123/xtts-webui","metadata":{"id":"OVjEG_yGoC2W"}},{"cell_type":"markdown","source":"## Disclamer this version should be considered alpha/beta!\n\n### Potential issues\n- float16 is disabled and float32 is used (not sure how to get float16 to work with kaggle)\n- this doesn't use kaggles persistant output directory as its limited to 20gb make sure to download models before ending sessions\n- the main disk is limited to 57 gb (you can go over it, it wont immediatly stop, but kaggle can crash at anytime)","metadata":{}},{"cell_type":"code","source":"# @title π οΈ Install requirments\n#!DEBIAN_FRONTEND=noninteractive\n!sudo apt-get update # && sudo apt-get -y upgrade\n!sudo apt-get -y install libegl1\n!sudo apt-get -y install libopengl0\n!sudo apt-get -y install libxcb-cursor0\n!pip install -r https://raw.githubusercontent.com/daswer123/xtts-finetune-webui/main/requirements.txt\n!pip install gradio==4.44.1\n!pip install fastapi==0.103.1\n!pip install pydantic==2.3.0","metadata":{"cellView":"form","id":"44HpAIVRfJve","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!nvcc --version\n!apt-get install libcudnn9-cuda-12 9.1.0 #fix a dependency issue","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"The code is basically the same as:\n\nhttps://github.com/daswer123/xtts-webui\n\nOnly change to repo is that float16 is changed to float32:\n\nhttps://github.com/Rihcus/xtts-finetune-webui/blob/2345589fb773a32b6f48b8f1aa7f4eca1aab476b/xtts_demo.py#L309","metadata":{}},{"cell_type":"code","source":"# @title π Run interface\n%cd /tmp/ \n!git clone https://github.com/Rihcus/xtts-finetune-webui #float16 is swapped to float32\n%cd /tmp/xtts-finetune-webui\n!python xtts_demo.py --share","metadata":{"cellView":"form","id":"62Da1Q5AgN3W","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"This part was from colab version not using it here","metadata":{}},{"cell_type":"code","source":"# import shutil\n# import requests\n# import os\n# from tqdm import tqdm # Progress bar library\n\n# # Define the paths\n# finetune_dir = '/content/xtts-finetune-webui/finetune_models/ready' # @param {type:\"string\"}\n# dataset_dir = '/content/xtts-finetune-webui/finetune_models/dataset' # @param {type:\"string\"}\n\n# # Create a temporary directory to collect both folders before zipping\n# temp_dir = \"/content/temp_finetune_dataset\"\n# os.makedirs(temp_dir, exist_ok=True)\n\n# # Copy both directories into the temporary directory with a progress bar\n# def copy_with_progress(src, dst):\n# total_files = sum(len(files) for _, _, files in os.walk(src))\n# with tqdm(total=total_files, desc=f\"Copying {os.path.basename(src)}\") as pbar:\n# for root, _, files in os.walk(src):\n# rel_path = os.path.relpath(root, src)\n# target_path = os.path.join(dst, rel_path)\n# os.makedirs(target_path, exist_ok=True)\n# for file in files:\n# shutil.copy(os.path.join(root, file), target_path)\n# pbar.update(1)\n\n# copy_with_progress(finetune_dir, os.path.join(temp_dir, \"ready\"))\n# copy_with_progress(dataset_dir, os.path.join(temp_dir, \"dataset\"))\n\n# # Create a zip file of the combined directories with progress\n# zip_filename = \"finetune_and_dataset.zip\"\n# with tqdm(total=100, desc=\"Zipping files\") as pbar:\n# shutil.make_archive(\"finetune_and_dataset\", 'zip', root_dir=temp_dir)\n# pbar.update(100)\n\n# # Define a function to stream the upload with a progress bar\n# def upload_with_progress(file_path, url):\n# file_size = os.path.getsize(file_path)\n# with open(file_path, 'rb') as f, tqdm(\n# total=file_size, unit='B', unit_scale=True, desc=\"Uploading\"\n# ) as progress:\n# response = requests.post(\n# url,\n# files={\"file\": (file_path, f)},\n# stream=True,\n# headers={\"Connection\": \"keep-alive\"},\n# )\n# # Update the progress bar as chunks are sent\n# for chunk in response.iter_content(chunk_size=4096):\n# if chunk:\n# progress.update(len(chunk))\n# return response\n\n# # Upload the zip file to file.io with a progress bar\n# response = upload_with_progress(zip_filename, \"https://file.io/?expires=1d\")\n\n# # Parse the response and display the download link\n# if response.status_code == 200:\n# download_link = response.json().get('link', 'Error: No link found.')\n# print(f\"Your file is ready: {download_link}\")\n# else:\n# print(f\"Failed to upload: {response.status_code} - {response.text}\")\n","metadata":{"cellView":"form","id":"MYBWgKevr6S3","trusted":true},"outputs":[],"execution_count":null}]}
|
Notebooks/kaggle-ebook2audiobook.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"colab":{"provenance":[],"gpuType":"T4"},"accelerator":"GPU","kaggle":{"accelerator":"gpu","dataSources":[],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Welcome to the ebook2audiobook free kaggle!\n## π Features\n\n- π Converts eBooks to text format with Calibre.\n- π Splits eBook into chapters for organized audio.\n- ποΈ High-quality text-to-speech with [Coqui XTTS](https://huggingface.co/coqui/XTTS-v2), [Fairseq](https://github.com/facebookresearch/fairseq), [Bark](https://github.com/suno-ai/bark), [Vits](https://github.com/jaywalnut310/vits), and [Yourtts](https://github.com/Edresson/YourTTS).\n- π£οΈ Optional voice cloning with your own voice file or choose from our pre-made fine-tuned models!\n- π Supports multiple languages! Arabic (ar), Chinese (zh-cn), Czech (cs), Dutch (nl), English (en), French (fr), German (de), Hindi (hi), Hungarian (hu), Italian (it), Japanese (ja), Korean (ko), Polish (pl), Portuguese (pt), Russian (ru), Spanish (es), Turkish (tr), Vietnamese (vi), [+ 1107 languages via Fairseq](https://dl.fbaipublicfiles.com/mms/tts/all-tts-languages.html)\n## Want to run locally for free? β¬\n## [Check out the ebook2audiobook github!](https://github.com/DrewThomasson/ebook2audiobook)","metadata":{"id":"DKNNnwD-HJwQ"}},{"cell_type":"code","source":"# Update system packages\n!sudo apt-get update -y\n\n# Install prerequisites\n!sudo apt-get install -y software-properties-common\n\n# Add deadsnakes PPA for newer Python versions\n!sudo add-apt-repository -y ppa:deadsnakes/ppa\n!sudo apt-get update -y\n\n# Install Python 3.11 and essentials\n!sudo apt-get install -y python3.11 python3.11-distutils python3.11-venv\n\n# Install pip for Python 3.11\n!wget -q https://bootstrap.pypa.io/get-pip.py\n!python3.11 get-pip.py\n\n# Register Python 3.11 as an alternative\n!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1\n!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2\n\n# Automatically set Python 3.11 as default (no prompt)\n!sudo update-alternatives --set python3 /usr/bin/python3.11\n\n# Verify Python version\n!python3 --version\n\n# Install common packages using pip for Python 3.11\n!python3 -m pip install --upgrade pip\n!python3 -m pip install numpy pandas matplotlib","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!python --version","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# @title π Run ebook2audiobook!\n\nimport os\nimport re\nimport subprocess\nimport time # Import the time module\nfrom IPython.display import HTML, display\nimport pkg_resources # For checking installed packages\n\n# Emojis for logs\nCHECK_MARK = \"β
\"\nCROSS_MARK = \"β\"\n\ndef display_loading_bar(total_steps):\n \"\"\"Displays a more visual text-based loading indicator in Colab.\"\"\"\n print(\"\\n--- LOADING... Total steps:\", total_steps, \" ---\") # Separator and loading start\n\ndef update_progress(step, total_steps):\n \"\"\"Updates the text-based loading indicator with a bar-like style.\"\"\"\n bar_length = 20 # Length of the \"bar\"\n progress_percent = int((step / total_steps) * 100)\n progress_filled = int(bar_length * step / total_steps)\n bar = '=' * progress_filled + '>' + ' ' * (bar_length - progress_filled -1 if (bar_length - progress_filled -1) >= 0 else 0) # Handle potential index error\n progress_text = f\"[{bar}] {progress_percent}% ({step}/{total_steps})\"\n print(f\"--- PROGRESS: {progress_text} ---\") # Separator for progress update\n\ndef run_command_with_log(command, description, step_progress, total_step_commands):\n \"\"\"Runs a command and logs its progress and outcome with emojis and duration.\"\"\"\n print(f\"\\n{step_progress}/{total_step_commands}: {description}...\")\n start_time = time.time() # Record start time\n try:\n process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n stdout, stderr = process.communicate()\n end_time = time.time() # Record end time\n duration = end_time - start_time # Calculate duration\n duration_formatted = \"{:.2f}\".format(duration) # Format duration to 2 decimal places\n\n if process.returncode != 0:\n print(f\"{CROSS_MARK} Command failed: {description} (Took {duration_formatted} seconds)\")\n print(f\" Command: {command}\")\n print(f\" Error Output:\\n{stderr.decode()}\")\n return False\n else:\n update_progress(step_progress, total_step_commands) # Use updated progress function\n print(f\"{CHECK_MARK} Command {step_progress}/{total_step_commands} completed: {description} (Took {duration_formatted} seconds)\")\n return True\n\n except Exception as e:\n end_time = time.time() # Record end time even if exception occurs\n duration = end_time - start_time # Calculate duration\n duration_formatted = \"{:.2f}\".format(duration) # Format duration\n print(f\"{CROSS_MARK} A general error occurred during command: {description} (Took {duration_formatted} seconds)\")\n print(f\" Error: {e}\")\n return False\n\n# --- Step 1: OS-Level Installations ---\nos_install_commands = [\n (\"sudo apt-get update\", \"Updating software package lists (Takes around 14.14 seconds)\"),\n (\"apt-get install -y libxcb-cursor0\", \"Install cursor display library (libxcb-cursor0 - for Calibre) (Takes around 12.99 seconds)\"),\n (\"sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin\", \"Download & install Calibre ebook manager(Takes around 29.40 seconds)\"),\n (\"apt-get install -y libegl1\", \"Install graphics library (libegl1) (Takes around 4.12 seconds)\"),\n (\"apt-get install -y libopengl0\", \"Install graphics library (libopengl0) (Takes around 3.07 seconds)\"),\n (\"apt-get install -y ffmpeg\", \"Install ffmpeg (audio/video conversion) (Takes around 3.52 seconds)\"),\n (\"apt-get install -y espeak-ng\", \"Install espeak-ng (espeak-ng tts engine) (Takes around 3.52 seconds)\"),\n (\"apt-get install -y mecab\", \"Install mecab (Japanese text analysis) (Takes around 14.51 seconds)\"),\n (\"apt-get install -y libmecab-dev\", \"Install mecab development files (Takes around 5.72 seconds)\"),\n (\"apt-get install -y mecab-ipadic-utf8\", \"Install mecab Japanese dictionary (UTF-8) (Takes around 9.58 seconds)\"),\n (\"apt-get install -y nodejs\", \"Install nodejs (Javascript runtime) (Takes around 7.03 seconds)\"),\n (\"pip install mecab-python3 unidic-lite\", \"Install mecab-python3 (Takes around 19.80 seconds)\"),\n (\"pip install unidic-lite\", \"Install lightweight unidic dictionary (Takes around 2.15 seconds)\"),\n (\"pip install unidic\", \"Install full Unidic dictionary (Takes around 4.00 seconds)\"),\n (\"python -m unidic download\", \"Download Unidic dictionary data (Takes around 29.05 seconds)\"),\n]\nos_install_completed = False\n\n# --- Step 2: Git Clone & Requirements ---\ngit_requirements_commands = [\n (\"git clone https://github.com/DrewThomasson/ebook2audiobook.git\", \"Git clone Ebook2audiobook\"),\n# (\"pip install -r /content/ebook2audiobook/requirements.txt\", \"Install Python requirements (Takes around 202.4 seconds)\"),\n (\"pip install -r /kaggle/working/ebook2audiobook/requirements.txt\", \"Install Python requirements (Takes around 202.4 seconds)\"), # modified path for kaggle\n]\ngit_requirements_completed = False\n\n# --- Step 3: Run App ---\nrun_app_completed = False\n\n\n# --- Step 1 Execution ---\nif os_install_completed:\n print(\"\\nStep 1: OS-Level Installations - Already completed, skipping.\")\nelse:\n print(\"\\n--- Step 1: OS-Level Installations ---\")\n print(\"This step installs essential software on the Colab system. (Takes around 3-4 minutes)\")\n total_steps_step1 = len(os_install_commands)\n display_loading_bar(total_steps_step1) # Start enhanced loading indicator\n\n step1_success = True\n for i, (command, description) in enumerate(os_install_commands):\n if not run_command_with_log(command, description, i + 1, total_steps_step1):\n step1_success = False\n break\n\n if step1_success:\n os_install_completed = True\n print(f\"\\n{CHECK_MARK} Step 1: OS-Level Installations - Completed Successfully!\")\n else:\n print(f\"\\n{CROSS_MARK} Step 1: OS-Level Installations - Failed. See error messages above.\")\n\n\n# --- Step 2 Execution ---\nif git_requirements_completed:\n print(\"\\nStep 2: Git Clone & Requirements - Already completed, skipping.\")\nelse:\n print(\"\\n--- Step 2: Git Clone & Requirements ---\")\n print(\"This step downloads program files and installs Python components. (Takes around 3-4 minutes)\")\n total_steps_step2 = len(git_requirements_commands)\n display_loading_bar(total_steps_step2) # Start enhanced loading indicator\n\n step2_success = True\n for i, (command, description) in enumerate(git_requirements_commands):\n if not run_command_with_log(command, description, i + 1, total_steps_step2):\n step2_success = False\n break\n\n if step2_success:\n git_requirements_completed = True\n print(f\"\\n{CHECK_MARK} Step 2: Git Clone & Requirements - Completed Successfully!\")\n else:\n print(f\"\\n{CROSS_MARK} Step 2: Git Clone & Requirements - Failed. See error messages above.\")\n\n\ndef modify_python_version(filepath, new_version=(3, 11)):\n \"\"\"\n Modifies the min_python_version in a Python file.\n (Function definition - same as before)\n \"\"\"\n try:\n with open(filepath, 'r') as f:\n file_content = f.read()\n pattern = r\"min_python_version = \\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\"\n def replacement(match):\n return f\"min_python_version = ({new_version[0]}, {new_version[1]})\"\n new_content = re.sub(pattern, replacement, file_content)\n if new_content != file_content:\n with open(filepath, 'w') as f:\n f.write(new_content)\n print(f\"Successfully changed min_python_version in {filepath} to {new_version}\")\n else:\n print(f\"min_python_version in {filepath} was already {new_version} or not found.\")\n except FileNotFoundError:\n print(f\"Error: File not found: {filepath}\")\n except Exception as e:\n print(f\"An error occurred: {e}\")\n\ndef fix_functions_py(filepath):\n \"\"\"\n Scans functions.py and fixes the incorrect f-string issue if found.\n \"\"\"\n # Define the incorrect pattern (allowing indentation and triple quotes)\n incorrect_pattern = r\"msg\\s*=\\s*f'Voice file \\{re\\.sub\\(r'_\\(24000\\|16000\\)\\\\.wav\\$', '', selected_name\\)\\} deleted!'\"\n\n # Correct replacement (keeping indentation)\n correct_replacement = \"\"\" cleaned_name = re.sub(r'_(24000|16000)\\\\.wav$', '', selected_name)\n msg = f\"Voice file {cleaned_name} deleted!\" \"\"\"\n\n try:\n # Read the file\n with open(filepath, \"r\") as file:\n lines = file.readlines()\n\n # Check and replace the incorrect line\n modified_lines = []\n fixed = False\n\n for line in lines:\n if re.search(incorrect_pattern, line.strip()): # Use regex search instead of exact match\n print(\"π Found incorrect line in functions.py. Fixing it now...\")\n modified_lines.append(correct_replacement + \"\\n\") # Add the corrected version\n fixed = True\n else:\n modified_lines.append(line) # Keep other lines unchanged\n\n # Only overwrite the file if a fix was applied\n if fixed:\n with open(filepath, \"w\") as file:\n file.writelines(modified_lines)\n print(\"β
Fix applied successfully!\")\n else:\n print(\"β
No fix needed. The exact error line was not found.\")\n\n except FileNotFoundError:\n print(f\"β Error: The file {filepath} was not found.\")\n except Exception as e:\n print(f\"β An error occurred: {e}\")\n\n# Modify conf.py AFTER git clone (Step 2 ensures clone is done)\n# filepath = \"/content/ebook2audiobook/lib/conf.py\" \nfilepath = \"/kaggle/working/ebook2audiobook/lib/conf.py\" # kaggle file path change\nmodify_python_version(filepath)\n\n# Call the function to fix functions.py\n# filepath = \"/content/ebook2audiobook/lib/functions.py\"\nfilepath = \"/kaggle/working/ebook2audiobook/lib/functions.py\" # kaggle file path change\nfix_functions_py(filepath)\n\n\n# --- Step 3 Execution ---\nif run_app_completed:\n print(\"\\nStep 3: Run App - Already run (or skipped).\")\nelse:\n print(\"\\n--- Step 3: Run App ---\")\n print(\"This step starts the ebook2audiobook web interface.\")\n print(\"Starting ebook2audiobook...\")\n try:\n !cd ebook2audiobook && python app.py --script_mode full_docker --share\n# !cd ebook2audiobook && python app.py --script_mode full_docker #fix gradio block\n run_app_completed = True\n except Exception as e:\n print(f\"{CROSS_MARK} Error starting app.py: {e}\")\n else:\n print(f\"\\n{CHECK_MARK} Step 3: Run App - Started! Check the output above for the Gradio link.\")\n\n\nprint(\"\\n--- All Steps Initiated (or Skipped if Already Run) ---\")\nprint(\"Check the output above for details on each step.\")","metadata":{"id":"Edxj355K0rUz","cellView":"form","trusted":true},"outputs":[],"execution_count":null}]}
|