Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
DrewThomasson authored Sep 4, 2024
1 parent a5f7416 commit 7371c41
Showing 1 changed file with 258 additions and 0 deletions.
258 changes: 258 additions & 0 deletions notebooks/Colab_Headless_VoxNovel.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
{
"cells": [
{
"cell_type": "code",
"source": [
"# @title Install Pt1 Requirments, Restart when prompted after this code block has run to install tts\n",
"!sudo apt-get install ffmpeg\n",
"!git clone https://github.com/DrewThomasson/VoxNovel.git\n",
"\n",
"\n",
"# Change the working directory\n",
"#%mkdir /content/VoxNovel/Working_files/temp_ebook\n",
"import os\n",
"os.chdir(\"/content/VoxNovel\")\n",
"#%run /content/VoxNovel/headless_voxnovel.py\n",
"\n",
"!pip install bs4\n",
"!pip install styletts2\n",
"!pip install ebooklib\n",
"!pip install epub2txt\n",
"\n",
"\n",
"# @title After running this code block you will have to restart to install tts, after you restart you will run the next block\n",
"!pip install tts==0.21.3\n",
"#now restart"
],
"metadata": {
"cellView": "form",
"id": "7woywFFjGGoA"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title now Continue Pt2 installation now that you have restarted\n",
"!pip install booknlp==1.0.7.1\n",
"!python -m spacy download en_core_web_sm\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"#make sure that calibre is up and running with a test\n",
"\n",
"!apt-get update\n",
"!apt-get install -y libxcb-cursor0 # Install the missing library\n",
"\n",
"# Re-run the Calibre installation\n",
"!wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sh /dev/stdin\n",
"import os\n",
"os.environ['PATH'] += \":/opt/calibre\" # Adjust PATH to include the Calibre installation\n",
"'''\n",
"import subprocess\n",
"\n",
"def convert_to_epub(input_path, output_path):\n",
" # Convert the ebook to EPUB format using Calibre's ebook-convert\n",
" try:\n",
" subprocess.run(['ebook-convert', input_path, output_path], check=True)\n",
" except subprocess.CalledProcessError as e:\n",
" print(f\"An error occurred while converting the eBook: {e}\")\n",
" return False\n",
" except Exception as e:\n",
" print(f\"An unexpected error occurred: {e}\")\n",
" return False\n",
" return True\n",
"\n",
"input_path = \"/content/VoxNovel/linux_requirements.txt\"\n",
"output_path = \"/content/linux_requirements.epub\"\n",
"\n",
"# Call the function to convert the file\n",
"if convert_to_epub(input_path, output_path):\n",
" print(\"Conversion successful!\")\n",
"else:\n",
" print(\"Conversion failed.\")\n",
"'''\n",
"#!python /content/calibre_test.py\n",
"#!python /content/VoxNovel/headless_voxnovel.py\n",
"\n",
"!apt install espeak-ng\n",
"\n",
"!pip install styletts2\n",
"!pip install booknlp==1.0.7.1\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"# Part 1: Pre-download the tos_agreed.txt file, This way you won't have to accept the user agreement for xtts coqui when downloading the xtts model\n",
"import os\n",
"import requests\n",
"\n",
"# Set the destination directory and file URL\n",
"DEST_DIR = \"/root/.local/share/tts/tts_models--multilingual--multi-dataset--xtts_v2\"\n",
"FILE_URL = \"https://github.com/DrewThomasson/VoxNovel/raw/main/readme_files/tos_agreed.txt\"\n",
"\n",
"# Create the destination directory if it doesn't exist\n",
"os.makedirs(DEST_DIR, exist_ok=True)\n",
"\n",
"# Download the file to the destination directory\n",
"response = requests.get(FILE_URL)\n",
"with open(os.path.join(DEST_DIR, \"tos_agreed.txt\"), \"wb\") as file:\n",
" file.write(response.content)\n",
"\n",
"print(f\"File has been saved to {os.path.join(DEST_DIR, 'tos_agreed.txt')}\")\n",
"print(\"The tos_agreed.txt file is so that you don't have to tell coqio tts yes when downloading the xtts_v2 model.\")\n",
"\n",
"# Part 2: Install wget and unzip, then replace the nltk folder with the backup\n",
"!sudo apt-get install -y wget\n",
"!sudo apt-get install -y unzip\n",
"\n",
"import shutil\n",
"import zipfile\n",
"import tempfile\n",
"\n",
"# Variables\n",
"ZIP_URL = \"https://github.com/DrewThomasson/VoxNovel/blob/main/readme_files/nltk.zip?raw=true\"\n",
"TARGET_DIR = \"/usr/local/lib/python3.10/dist-packages\"\n",
"\n",
"# Create a temporary directory\n",
"TEMP_DIR = tempfile.mkdtemp()\n",
"\n",
"# Download the zip file\n",
"print(\"Downloading zip file...\")\n",
"wget_command = f\"wget -q -O {os.path.join(TEMP_DIR, 'nltk.zip')} {ZIP_URL}\"\n",
"os.system(wget_command)\n",
"\n",
"# Extract the zip file\n",
"print(\"Extracting zip file...\")\n",
"with zipfile.ZipFile(os.path.join(TEMP_DIR, 'nltk.zip'), 'r') as zip_ref:\n",
" zip_ref.extractall(TEMP_DIR)\n",
"\n",
"# Replace contents\n",
"print(\"Replacing contents...\")\n",
"shutil.rmtree(os.path.join(TARGET_DIR, 'nltk'))\n",
"shutil.move(os.path.join(TEMP_DIR, 'nltk'), os.path.join(TARGET_DIR, 'nltk'))\n",
"\n",
"# Clean up\n",
"print(\"Cleaning up...\")\n",
"shutil.rmtree(TEMP_DIR)\n",
"\n",
"print(\"NLTK Files Replacement complete.\")\n",
"print(\"Done! Ready to run VoxNovel!\")"
],
"metadata": {
"id": "hqe3nOq9G5cE",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title Run the headless VoxNovel Program! it will walk you though asking for your input in each step in the terminal.\n",
"\n",
"#!run /content/VoxNovel/headless_voxnovel.py\n",
"import os\n",
"os.chdir(\"/content/VoxNovel\")\n",
"!python /content/VoxNovel/headless_voxnovel.py\n",
"\n",
"!yes | rm -rf /content/VoxNovel/Working_files"
],
"metadata": {
"cellView": "form",
"id": "5a2Z9CnHSliw"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title This will download all the output audiobook files you have generated so far\n",
"\n",
"import os\n",
"from google.colab import files\n",
"\n",
"# Specify the directory you want to download\n",
"folder_path = '/content/VoxNovel/output_audiobooks'\n",
"zip_path = '/content/VoxNovel/output_audiobooks.zip'\n",
"\n",
"# Compress the entire folder into a ZIP file\n",
"!zip -r {zip_path} {folder_path}\n",
"\n",
"# Download the zip file\n",
"files.download(zip_path)\n"
],
"metadata": {
"cellView": "form",
"id": "NG1xsiSsXjOo"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title These are extra scripts such as extracting the test ebook files, and a way to view a mp4 file without downloading it\n",
"#This will unzip the examples working files so you have a ebook file to test it on\n",
"!unzip /content/VoxNovel/Example_Working_files.zip\n",
"\n",
"\n",
"#This can be used to play a mp4 or wav file to see what they sound like\n",
"from IPython.display import Audio\n",
"\n",
"# Assuming 'your_audio_file.m4b' is the filename of your uploaded mp4 or wav file\n",
"audio_file = '/content/VoxNovel/tortoise/voices/emma.F/1.wav'\n",
"Audio(audio_file)\n"
],
"metadata": {
"cellView": "form",
"id": "TUUfPhmDWEUc"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title After running this code block you will have to restart to install tts, after you restart you will run the next block\n",
"!pip install tts==0.21.3\n",
"#now restart"
],
"metadata": {
"cellView": "form",
"id": "r0X2zjUYG1Du"
},
"execution_count": null,
"outputs": []
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"gpuType": "T4",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

1 comment on commit 7371c41

@DrewThomasson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved headless Google Colab Notebook file into notebooks folder, and removed the terminal outputs embedded In it to save on size.

Please sign in to comment.