Compare commits

..
48 Commits
Author SHA1 Message Date
erew123 b32df6ac15 Additional note in finetune re multiple GPU support 2023-12-30 14:45:42 +00:00
erew123 b76dd3561f Merge pull request #34 from erew123/dev
Dev
2023-12-30 14:23:22 +00:00
erew123 60bfbdcabd Update README.md 2023-12-30 14:12:41 +00:00
erew123 c128d0851b Updated Finetune 2023-12-30 14:00:36 +00:00
erew123 2f3b7762e4 Update README.md 2023-12-30 13:31:41 +00:00
erew123 0e594f5098 Update .gitignore 2023-12-30 13:30:16 +00:00
erew123 14151d4dda Update README.md 2023-12-30 11:27:20 +00:00
erew123 94ab21fb15 Update README.md 2023-12-30 11:26:29 +00:00
erew123 1acac3d6c6 Update README.md 2023-12-30 11:23:59 +00:00
erew123 95ec2dc9d2 Merge pull request #32 from erew123/main
merge main to dev
2023-12-30 11:11:11 +00:00
erew123 6b93eb6c1e Update README.md 2023-12-29 23:38:38 +00:00
erew123 838578a042 Update README.md 2023-12-29 23:28:47 +00:00
erew123 2f689f0438 Model loader for Finetuned models
Adds a detection routine and additional loader for a finetuned model. 
Model has to be in /models/trainedmodel/
2023-12-29 23:15:15 +00:00
erew123 022025ded6 Update README.md 2023-12-29 20:57:28 +00:00
erew123 320a7a6aba Update README.md 2023-12-29 20:51:45 +00:00
erew123 fa82870883 Merge pull request #31 from erew123/dev
3x new API endpoints & Play audio at command prompt/terminal
2023-12-29 20:37:20 +00:00
erew123 a094d4f9da Completed autoplay at command line
Added additional requirement.
Lowered the repetition on the start-up warning when its taking a while for the model to load.
2023-12-29 20:31:49 +00:00
erew123 bb028af694 Update README.md 2023-12-29 10:54:02 +00:00
erew123 aeb225ec7c Update README.md 2023-12-29 10:51:06 +00:00
erew123 06a632459e Update README.md 2023-12-29 10:44:39 +00:00
erew123 221efbddb4 Supports playback at the command line prompt
Added sounddevice as its currently well supported. Allows playback at the terminal/command prompt. 
Added speakers_xtts.pth to the modeldownload.json as it will be needed for finetuning in future updates of TTS 0.22.0+
2023-12-29 10:42:35 +00:00
erew123 e81a88938a Completed built-in documentation update
For the new API endpoints
2023-12-29 10:11:01 +00:00
erew123 65e257077c 3x new API endpoints
/api/voices/
/api/previewvoice/
/api/ready/
2023-12-29 09:56:51 +00:00
erew123 95659d5b7a Update README.md 2023-12-29 09:55:23 +00:00
erew123 ff57270286 Update README.md 2023-12-29 09:53:02 +00:00
erew123 4fc61ba99a Merge pull request #30 from erew123/main
merge main to dev
2023-12-29 09:08:07 +00:00
erew123 3cd22081f4 Update script.py 2023-12-28 21:05:59 +00:00
erew123 d20ee95e67 Delete finetune/put-voice-samples-in-here/compact.py 2023-12-28 20:38:33 +00:00
erew123 cd47f6b123 Add files via upload 2023-12-28 20:38:12 +00:00
erew123 53a2d0a65e Update README.md 2023-12-28 19:25:59 +00:00
erew123 13318243e4 Merge pull request #27 from rbruels/patch-1
A few changes/clarifications in the fine-tuning sections
2023-12-28 18:41:06 +00:00
erew123 acc457436a updated narrator splitting function
Improved over what was before. 
Still more work to do in future though.
2023-12-28 18:39:01 +00:00
erew123 8d80151889 New version of Finetune
Simplified the final stages of finetuning.
Added model compaction. 
Added cleaning routines to tidy up after training.
2023-12-28 18:36:51 +00:00
erew123 8b0ade5b9f compact routine - separate to finetune
a mini compact routine for anyone who wants to compact their existing model. This is built into the new version of finetune anyway, but is here just to capture those outlier instances.
2023-12-28 18:34:49 +00:00
Ryan Bruels 9f033e4654 A few changes/clarifications in the fine-tuning sections 2023-12-28 10:28:20 -08:00
erew123 1a2b8571d0 Updated diagnostics to include Path
Now includes both Python and environment variables PATH search locations.
2023-12-28 12:05:46 +00:00
erew123 9ab20be294 Update README.md
updated a screenshot
2023-12-27 06:49:46 +00:00
erew123 a34cbfdd55 Made Settings link more visble
Updated the visibility of the settings & documentation page within Text-gen-webui interface.
Minor built in documentation update.
2023-12-27 06:43:28 +00:00
erew123 94f5b781cc Update Standalone API - race condition fix
Applies the same race condition fix for narrator/character that potentially existed, but for the standalone mode API. Will have zero effect for anyone not using the API
2023-12-27 06:08:10 +00:00
erew123 f83e7c3b4e Update README.md 2023-12-27 06:00:30 +00:00
erew123 607dc89be5 Update README.md
Added a section on Running AllTalk as a standalone
2023-12-27 04:44:44 +00:00
erew123 47758c4aeb Updated diagnostics
Pulls Conda and Python environment details.
2023-12-26 18:58:06 +00:00
erew123 26414d4925 Update README.md 2023-12-26 17:30:40 +00:00
erew123 7ad92e7f5d Update README.md 2023-12-26 17:28:28 +00:00
erew123 e775cef5bd Update README.md 2023-12-26 17:19:21 +00:00
erew123 ac9ce144a0 Update README.md 2023-12-26 16:47:24 +00:00
erew123 f181c06f89 Update README.md
Added a video link to show people how to install AllTalk.
2023-12-26 10:02:17 +00:00
erew123 9fae4692e3 Update README.md 2023-12-26 08:03:24 +00:00
11 changed files with 899 additions and 239 deletions

No files matched your search

+1
View File
@@ -1,6 +1,7 @@
voices/*.* voices/*.*
models/*.* models/*.*
outputs/*.* outputs/*.*
finetune/*.*
config.json config.json
confignew.json confignew.json
models.json models.json
+170 -70
View File
@@ -21,26 +21,24 @@ AllTalk is an updated version of the Coqui_tts extension for Text Generation web
- 🟨 [Help with problems](https://github.com/erew123/alltalk_tts?#-help-with-problems) - 🟨 [Help with problems](https://github.com/erew123/alltalk_tts?#-help-with-problems)
- ⚫ [Finetuning a model](https://github.com/erew123/alltalk_tts?#-finetuning-a-model) - ⚫ [Finetuning a model](https://github.com/erew123/alltalk_tts?#-finetuning-a-model)
- 🔵🟢🟡 [DeepSpeed Installation (Windows & Linux)](https://github.com/erew123/alltalk_tts?#-deepspeed-installation-options) - 🔵🟢🟡 [DeepSpeed Installation (Windows & Linux)](https://github.com/erew123/alltalk_tts?#-deepspeed-installation-options)
- 🟦 [Running AllTalk as a standalone app](https://github.com/erew123/alltalk_tts?#-running-alltalk-as-a-standalone-app)
- 🟠 [API Suite and JSON-CURL](https://github.com/erew123/alltalk_tts?#-api-suite-and-json-curl) - 🟠 [API Suite and JSON-CURL](https://github.com/erew123/alltalk_tts?#-api-suite-and-json-curl)
- 🔴 [Future to-do list & Upcoming updates](https://github.com/erew123/alltalk_tts?#-future-to-do-list) - 🔴 [Future to-do list & Upcoming updates](https://github.com/erew123/alltalk_tts?#-future-to-do-list)
#### Updates ## 🔄 Updates
Dec 25th - Applied a small update to avoid a possible race condition on file naming with small sentences when generating narrator/character speech. Please update if you are experiencing missing small bits of missing audio on narrator/character. Please check the below link to find a list of all recent updates and changes.
####     🔄 **Updates list & bug fixes list** can be found [here](https://github.com/erew123/alltalk_tts/issues/25)
####     🔄 **Minor updates/bug fixes list** can be found [here](https://github.com/erew123/alltalk_tts/issues/25)
The latest build (13 Dec 2023) has had the entire text filtering engine and narration engine rebuilt from scratch. It's highly complicated how its actually working, but the end result it a much clearer TTS output and much better control over the narrator option and how to handle text that isnt within quotes or asterisks. It does however mean you need to ensure your character card is set up correctly if using the narrator function. Details are below in the installation notes.
DeepSpeed **v11.2** can be installed within the **default text-generation-webui Python 3.11 environment**. Installs in custom Python environments are possible, but can be more complicated. Instructions [here](https://github.com/erew123/alltalk_tts##deepspeed-installation-options) (or scroll down).
## 🟩 Installation on Text generation web UI ## 🟩 Installation on Text generation web UI
This has been tested on the current Dec 2023 release of Text generation webUI. If you have not updated it for a while, you may wish to update Text generation webUI, [instructions here](https://github.com/oobabooga/text-generation-webui?tab=readme-ov-file#how-to-install) This has been tested on the current Dec 2023 release of Text generation webUI. If you have not updated it for a while, you may wish to update Text generation webUI, [instructions here](https://github.com/oobabooga/text-generation-webui?tab=readme-ov-file#how-to-install)
If you want to watch a video of how to do the below [link here](https://youtu.be/9BPKuwaav5w)
1) In a command prompt/terminal window you need to move into your Text generation webUI folder:<br><br> 1) In a command prompt/terminal window you need to move into your Text generation webUI folder:<br><br>
`cd text-generation-webui` `cd text-generation-webui`
2) Start the Text generation webUI Python environment for your OS:<br><br> 2) Start the Text generation webUI Python environment for your OS with whichever **one** of the below is correct for your OS:<br><br>
`cmd_windows.bat`, `./cmd_linux.sh`, `cmd_macos.sh` or `cmd_wsl.bat` `cmd_windows.bat`, `./cmd_linux.sh`, `cmd_macos.sh` or `cmd_wsl.bat`<br><br> Loading Text-generation-webui's Python Environment is $\textcolor{red}{\textsf{VERY IMPORTANT}}$. If you are uncertain what a loaded Python environment looks like, image [here](https://github.com/erew123/alltalk_tts/issues/25#issuecomment-1869344442) and video [here](https://www.youtube.com/watch?v=9BPKuwaav5w)
3) Move into your extensions folder:<br><br> 3) Move into your extensions folder:<br><br>
`cd extensions` `cd extensions`
@@ -51,17 +49,17 @@ This has been tested on the current Dec 2023 release of Text generation webUI. I
5) Move into the **alltalk_tts** folder:<br><br> 5) Move into the **alltalk_tts** folder:<br><br>
`cd alltalk_tts` `cd alltalk_tts`
6) Install the requirements that are correct for your machine:<br><br> 6) Install one of the two requirements files. Whichever one of the two is correct for your machine type:<br><br>
**Nvidia graphics card machines** - `pip install -r requirements_nvidia.txt`<br><br> **Nvidia graphics card machines** - `pip install -r requirements_nvidia.txt`<br><br>
**Other machines (mac, amd etc)** - `pip install -r requirements_other.txt` **Other machines (mac, amd etc)** - `pip install -r requirements_other.txt`
7) **(Optional DeepSpeed)** If you have an Nvidia Graphics card on a system running Linux or Windows and wish to use **DeepSpeed** please follow these instructions [here](https://github.com/erew123/alltalk_tts?#-deepspeed-installation-options). **However**, I would highly reccommend before you install DeepSpeed, you start text-generation-webui up, confirm AllTalk starts correctly and everything is working, as DeepSpeed can add another layer of complications troubleshooting any potential start-up issues. If necessary you can `pip uninstall deepspeed`. 7) **(Optional DeepSpeed)** If you have an Nvidia Graphics card on a system running Linux or Windows and wish to use **DeepSpeed** please follow these instructions [here](https://github.com/erew123/alltalk_tts?#-deepspeed-installation-options). **However**, I would highly reccommend before you install DeepSpeed, you start text-generation-webui up, confirm AllTalk starts correctly and everything is working, as DeepSpeed can add another layer of complications troubleshooting any potential start-up issues. If necessary you can `pip uninstall deepspeed`.
8) You can now start move back to the main Text generation webUI folder `cd ..` (a few times), start Text generation webUI (`start_windows.bat`,`./start_linux.sh`, `start_macos.sh` or `start_wsl.bat`) and load the AllTalk extension in the Text generation webUI **session** tab. 8) You can now start move back to the main Text generation webUI folder `cd ..` (a few times), start Text generation webUI with whichever **one** of the startup scripts is correct for your OS (`start_windows.bat`,`./start_linux.sh`, `start_macos.sh` or `start_wsl.bat`) and load the AllTalk extension in the Text generation webUI **session** tab.<br><br> Starting Text-generation-webui with its correct start-up script is $\textcolor{red}{\textsf{VERY IMPORTANT}}$.
9) Please read the note below about start-up times and also the note about ensuring your character cards are set up [correctly](https://github.com/erew123/alltalk_tts#the-one-thing-i-cant-easily-work-around) 10) Please read the note below about start-up times and also the note about ensuring your character cards are set up [correctly](https://github.com/erew123/alltalk_tts#the-one-thing-i-cant-easily-work-around)
10) Some extra voices downloadable [here](https://drive.google.com/file/d/1bYdZdr3L69kmzUN3vSiqZmLRD7-A3M47/view?usp=drive_link) 11) Some extra voices downloadable [here](https://drive.google.com/file/d/1bYdZdr3L69kmzUN3vSiqZmLRD7-A3M47/view?usp=drive_link)
#### 🟩 Other installation notes #### 🟩 Other installation notes
On first startup, AllTalk will download the Coqui XTTSv2 2.0.2 model to its **models** folder (1.8GB space required). Check the command prompt/terminal window if you want to know what its doing. After it says "Model Loaded" the Text generation webUI is usually available on its IP address a few seconds later, for you to connect to in your browser. On first startup, AllTalk will download the Coqui XTTSv2 2.0.2 model to its **models** folder (1.8GB space required). Check the command prompt/terminal window if you want to know what its doing. After it says "Model Loaded" the Text generation webUI is usually available on its IP address a few seconds later, for you to connect to in your browser.
@@ -103,6 +101,7 @@ I did leave a mistake in the `/extensions/alltalk_tts/.gitignore` file at one po
voices/*.* voices/*.*
models/*.* models/*.*
outputs/*.* outputs/*.*
finetune/*.*
config.json config.json
confignew.json confignew.json
models.json models.json
@@ -143,7 +142,7 @@ Assuming its all working fine and you are happy, you can delete the old alltalk_
</details> </details>
## 🟫 Screenshots ## 🟫 Screenshots
|![image](https://github.com/erew123/alltalk_tts/assets/35898566/4ca9b4c7-60ce-4ac6-82e5-fd1989b84644) | ![image](https://github.com/erew123/alltalk_tts/assets/35898566/548619c8-5f1b-47d0-a73d-54d2fee3f3db) | |![image](https://github.com/erew123/alltalk_tts/assets/35898566/15c6ba0b-e6b0-4570-8253-b920dd76174d) | ![image](https://github.com/erew123/alltalk_tts/assets/35898566/548619c8-5f1b-47d0-a73d-54d2fee3f3db) |
|:---:|:---:| |:---:|:---:|
|![image](https://github.com/erew123/alltalk_tts/assets/35898566/b0e13dba-c6b1-4ab7-845d-244ac1158330) | ![image](https://github.com/erew123/alltalk_tts/assets/35898566/e35e987c-543a-486b-b4fb-ee6ebe6f59c6) | |![image](https://github.com/erew123/alltalk_tts/assets/35898566/b0e13dba-c6b1-4ab7-845d-244ac1158330) | ![image](https://github.com/erew123/alltalk_tts/assets/35898566/e35e987c-543a-486b-b4fb-ee6ebe6f59c6) |
|![image](https://github.com/erew123/alltalk_tts/assets/35898566/68edc968-bdd2-4f98-9d56-b9ca40decf26) | ![image](https://github.com/erew123/alltalk_tts/assets/35898566/eb5e617b-2345-418d-8267-a9d30f705a10) | |![image](https://github.com/erew123/alltalk_tts/assets/35898566/68edc968-bdd2-4f98-9d56-b9ca40decf26) | ![image](https://github.com/erew123/alltalk_tts/assets/35898566/eb5e617b-2345-418d-8267-a9d30f705a10) |
@@ -255,10 +254,29 @@ I would suggest following [Problems Updating](https://github.com/erew123/alltalk
As far as I am aware, these are to do with the chrome browser the gradio text-generation-webui in some way. I raised an issue about this on the text-generation-webui [here](https://github.com/oobabooga/text-generation-webui/issues/4788) where you can see that AllTalk is not loaded and the messages persist. Either way, this is more a warning than an actual issue, so shouldnt affect any functionality of either AllTalk or text-generation-webui, they are more just an annoyance. As far as I am aware, these are to do with the chrome browser the gradio text-generation-webui in some way. I raised an issue about this on the text-generation-webui [here](https://github.com/oobabooga/text-generation-webui/issues/4788) where you can see that AllTalk is not loaded and the messages persist. Either way, this is more a warning than an actual issue, so shouldnt affect any functionality of either AllTalk or text-generation-webui, they are more just an annoyance.
</details> </details>
#### 🟨 I have multiple GPU's and I have problems running Finetuning
<details>
<summary>Click to expand</summary><br>
Finetuning pulls in various other scripts and some of those scripts can have issues with multiple Nvidia GPU's being present. Until the people that created those other scripts fix up their code, there is a workaround to temporarily tell your system to only use the 1x of your Nvidia GPU's. To do this:
- **Windows** - You will start the script with `set CUDA_VISIBLE_DEVICES=0 && python finetune.py`<br>
After you have completed training, you can reset back with `set CUDA_VISIBLE_DEVICES=`<br>
- **Linux** - You will start the script with `CUDA_VISIBLE_DEVICES=0 python finetune.py`<br>
After you have completed training, you can reset back with `unset CUDA_VISIBLE_DEVICES`<br>
Rebooting your system will also unset this. The setting is only applied temporarily.
Depending on which of your Nvidia GPU's is the more powerful one, you can change the `0` to `1` or whichever of your GPU's is the most powerful.
</details>
## ⚫ Finetuning a model ## ⚫ Finetuning a model
If you have a voice that the model doesnt quite reproduce correctly, or indeed you just want to improve the reproduced voice, then finetuning is a way to train your "XTTSv2 local" model **(stored in `/alltalk_tts/models/xxxxx/`)** on a specific voice. For this you will need: If you have a voice that the model doesnt quite reproduce correctly, or indeed you just want to improve the reproduced voice, then finetuning is a way to train your "XTTSv2 local" model **(stored in `/alltalk_tts/models/xxxxx/`)** on a specific voice. For this you will need:
- An Nvidia graphics card - An Nvidia graphics card. (Please see this [note](https://github.com/erew123/alltalk_tts#i-have-multiple-gpus-and-i-have-problems-running-finetuning) if you have multiple Nvidia GPU's).
- To install a few portions of the Nvidia CUDA 11.8 Toolkit (this will not impact text-generation-webui's cuda setup. - To install a few portions of the Nvidia CUDA 11.8 Toolkit (this will not impact text-generation-webui's cuda setup.
- 18GB of disk space free (most of this is used temporarily) - 18GB of disk space free (most of this is used temporarily)
- At least 2 minutes of good quality speech from your chosen speaker in mp3, wav or flacc format, in one or more files (have tested as far as 20 minutes worth of audio). - At least 2 minutes of good quality speech from your chosen speaker in mp3, wav or flacc format, in one or more files (have tested as far as 20 minutes worth of audio).
@@ -272,17 +290,23 @@ I would suggest that if its in an interview format, you cut out the interviewer
#### ⚫ Important requirements CUDA 11.8 #### ⚫ Important requirements CUDA 11.8
As mentioned you must have a small portion of the Nvidia CUDA Toolkit **11.8** installed. Not higher or lower versions. Specifically **11.8**. You do not have to uninstall any other versions, change any graphics drivers, reinstall torch or anything like that. To keep the download+install as small as possible, you will need to: As mentioned you must have a small portion of the Nvidia CUDA Toolkit **11.8** installed. Not higher or lower versions. Specifically **11.8**. You do not have to uninstall any other versions, change any graphics drivers, reinstall torch or anything like that. To keep the download+install as small as possible, you will need to:
- Download the **xxx (network)** install of the Nvidia Cuda Toolkit 11.8 from [here](https://developer.nvidia.com/cuda-11-8-0-download-archive) - Download the **xxx (network)** install of the Nvidia Cuda Toolkit 11.8 from [here](https://developer.nvidia.com/cuda-11-8-0-download-archive)
- When you run the installation, select **Custom Advanced** as your installation type. Uncheck `CUDA`, `Other Components` and `Driver Components` at the top then expand `CUDA` > `Development` > `Compiler` > and select `nvcc` then expand `Libraries` and select `CUBLAS` - Run the installer. At minimum, you need to [minimally] install the `nvcc` compiler and the `CUBLAS` development and runtime libraries:
- Back at the top of `CUDA` expand `Runtime` > `Libraries` and select `CUBLAS`. You can now next through the install. - Select **Custom Advanced** as your installation type.
- Uncheck all the checkboxes in the list.
- Now check the following elements:
- `CUDA` > `Development` > `Compiler` > `nvcc`
- `CUDA` > `Development` > `Compiler` > `Libraries` > `CUBLAS`
- `CUDA` > `Runtime` > `Libraries` > `CUBLAS`
- You can now proceed through the install.
- When that has installed, open a terminal/command prompt and type `nvcc --version`. If it reports back `Cuda compilation tools, release 11.8.` you are good to go. **Specifically, 11.8**. If not continue to the next step. - When that has installed, open a terminal/command prompt and type `nvcc --version`. If it reports back `Cuda compilation tools, release 11.8.` you are good to go. **Specifically, 11.8**. If not continue to the next step.
- For both Windows an Linux, you will need to ensure that `nvcc` and the 11.8 cuda library files are in your environments search path. You can undo the changes below after finetuning if you prefer.<br><br> - For both Windows and Linux, you need to ensure that `nvcc` and the 11.8 cuda library files are in your environments search path. You can undo the changes below after finetuning if you prefer:
**Windows** - Edit the Windows PATH environment variable and add `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin`<br><br> - **Windows**: Edit the Windows `Path` environment variable and add `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin`
**Linux** - The path may be different depending on what flavour of Linux you are running, so you may need to seek out specific instructions on the internet. Generic paths **may** be:<br> - **Linux**: The path may be different depending on what flavour of Linux you are running, so you may need to seek out specific instructions on the internet. Generic paths **may** be:
`export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}` and<br> - `export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}` and
`export LD_LIBRARY_PATH=/usr/local/cuda-11.8/bin`<br> - `export LD_LIBRARY_PATH=/usr/local/cuda-11.8/bin`
Add these to your '~/.bashrc' if you want this to be permanent and not something you have to set each time you open a new terminal.<br><br> - Add these to your '~/.bashrc' if you want this to be permanent and not something you have to set each time you open a new terminal.
- When you have made the changes, open a new terminal/command prompt and `nvcc --version`. It should report back `Cuda compilation tools, release 11.8.` at which point, you are good to go. - When you have made the changes, open a **new** terminal/command prompt (in order to load the new search paths) and `nvcc --version`. It should report back `Cuda compilation tools, release 11.8.` at which point, you are good to go.
- If it doesnt report that, check you have correctly set the search environment paths, dont have overlapping other versions of cuda paths etc. - If it doesn't report that, check you have correctly set the search environment paths, dont have overlapping other versions of cuda paths etc.
#### ⚫ Starting Finetuning #### ⚫ Starting Finetuning
**NOTE:** Please make sure you have started AllTalk at least once after updating, so that it downloads the additional files needed for finetuning. **NOTE:** Please make sure you have started AllTalk at least once after updating, so that it downloads the additional files needed for finetuning.
@@ -310,6 +334,18 @@ As mentioned you must have a small portion of the Nvidia CUDA Toolkit **11.8** i
11) Follow the on-screen instructions when the web interface starts up. 11) Follow the on-screen instructions when the web interface starts up.
12) When you have finished finetuning, the final tab will tell you what to do with your files and how to move your newly trained model to the correct location on disk. 12) When you have finished finetuning, the final tab will tell you what to do with your files and how to move your newly trained model to the correct location on disk.
#### ⚫ Using a Finetuned model in Text-generation-webui
At the end of the finetune process, you will have an option to `Compact and move model to /trainedmodel/` this will compact the raw training file and move it to `/model/trainedmodel/`. When AllTalk starts up within Text-generation-webui, if it finds a model in this location a new loader will appear in the interface for `XTTSv2 FT` and you can use this to load your finetuned model. <br><br>**Be careful** not to train a new model from the base model, then overwrite your current `/model/trainedmodel/` **if** you want a seperately trained model. This is why there is an `OPTION B` to move your just trained model to `/models/lastfinetuned/`.
#### ⚫ Training one model with multiple voices
At the end of the finetune process, you will have an option to `Compact and move model to /trainedmodel/` this will compact the raw training file and move it to `/model/trainedmodel/`. This model will become available when you start up finetuning. You will have a choice to train the Base Model or the `Existing finetuned model` (which is the one in `/model/trainedmodel/`). So you can use this to keep further training this model with additional voices, then copying it back to `/model/trainedmodel/` at the end of training.
#### ⚫ Do I need to keep the raw training data/model?
If you've compacted and moved your model, its highly unlikely you would want to keep that data, however the choice is there to keep it if you wish. It will be between 5-10GB in size, so most people will want to delete it.
## 🔵🟢🟡 DeepSpeed Installation Options ## 🔵🟢🟡 DeepSpeed Installation Options
**NOTE**: You **DO NOT** need to set Text-generation-webUI's **--deepspeed** setting for AllTalk to be able to use DeepSpeed. These are two completely separate things and incorrectly setting that on Text-generation-webUI may cause other complications. **NOTE**: You **DO NOT** need to set Text-generation-webUI's **--deepspeed** setting for AllTalk to be able to use DeepSpeed. These are two completely separate things and incorrectly setting that on Text-generation-webUI may cause other complications.
@@ -463,13 +499,100 @@ def get_shm_size():
**Removal** - If it became necessary to uninstall DeepSpeed, you can do so with `cmd_windows.bat` and then `pip uninstall deepspeed`<br><br> **Removal** - If it became necessary to uninstall DeepSpeed, you can do so with `cmd_windows.bat` and then `pip uninstall deepspeed`<br><br>
</details> </details>
## 🟦 Running AllTalk as a standalone app
AllTalk will run as a standalone app, as long as you install its requirements files into whatever Python environment you are using. You can follow the steps to install the AllTalk's requirements into whatever Python environment you wish. Because I dont know what Python environment you are wanting to use, I can only give you a loose set of installation instructions.
Please note, at time of writing, the TTS engine requires Python **3.9.x** to **3.11.x** [TTS Engine details here](https://pypi.org/project/TTS/). AllTalk and its requirements are tested on Python 3.11.x.
#### 🟦 (Option 1) I already have AllTalk installed as an extension of Text-generation-webui
If you already have AllTalk as a extension of Text-generation-webui, and wish to run it as standalone, load Text-generation-webui's Python environment `cmd_windows.bat`, `./cmd_linux.sh`, `cmd_macos.sh` or `cmd_wsl.bat`, move into the AllTalk folder `cd extensions` > `cd alltalk_tts` and start AllTalk with `python script.py`. There is nothing beyond this you would need to do.
#### 🟦 (Option 2) I wish to do a custom install of AllTalk
1) In your chosen disk location git clone this repository:<br><br>
`git clone https://github.com/erew123/alltalk_tts`
2) Move into the **alltalk_tts** folder:<br><br>
`cd alltalk_tts`
3) If you have a custom Python environment, now is the time to load it!
4) Install one of the two requirements files. Whichever one of the two is correct for your machine type:<br><br>
**Nvidia graphics card machines** - `pip install -r requirements_nvidia.txt`<br><br>
**Other machines (mac, amd etc)** - `pip install -r requirements_other.txt`
5) Start AllTalk with `python script.py`
Deepspeed and other such things can be installed. Please read the relevant instructions for those items, however, make the relevant changes to load your correct Python environment when installing any requirements files and starting AllTalk.
## 🟠 API Suite and JSON-CURL ## 🟠 API Suite and JSON-CURL
### 🟠Overview ### 🟠Overview
The Text-to-Speech (TTS) Generation API allows you to generate speech from text input using various configuration options. This API supports both character and narrator voices, providing flexibility for creating dynamic and engaging audio content. The Text-to-Speech (TTS) Generation API allows you to generate speech from text input using various configuration options. This API supports both character and narrator voices, providing flexibility for creating dynamic and engaging audio content.
- URL: `http://127.0.0.1:7851/api/tts-generate`<br> #### 🟠 Ready Endpoint<br>
- Method: `POST`<br> Check if the Text-to-Speech (TTS) service is ready to accept requests.
- Content-Type: `application/x-www-form-urlencoded`<br>
- URL: `http://127.0.0.1:7851/api/ready`<br> - Method: `GET`<br>
`curl -X GET "http://127.0.0.1:7851/api/ready"`
Response: `Ready`
#### 🟠 Voices List Endpoint<br>
Retrieve a list of available voices for generating speech.
- URL: `http://127.0.0.1:7851/api/voices`<br> - Method: `GET`<br>
`curl -X GET "http://127.0.0.1:7851/api/voices"`
JSON return: `{"voices": ["voice1.wav", "voice2.wav", "voice3.wav"]}`
#### 🟠 Preview Voice Endpoint
Generate a preview of a specified voice with hardcoded settings.
- URL: `http://127.0.0.1:7851/api/previewvoice/`<br> - Method: `POST`<br> - Content-Type: `application/x-www-form-urlencoded`<br>
`curl -X POST "http://127.0.0.1:7851/api/previewvoice/" -F "voice=female_01.wav"`
Replace `female_01.wav` with the name of the voice sample you want to hear.
JSON return: `{"status": "generate-success", "output_file_path": "/path/to/outputs/api_preview_voice.wav", "output_file_url": "http://127.0.0.1:7851/audio/api_preview_voice.wav"}`
#### 🟠 Switching Model Endpoint<br>
- URL: `http://127.0.0.1:7851/api/reload`<br> - Method: `POST`<br><br>
`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=API%20Local"`<br>
`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=API%20TTS"`<br>
`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=XTTSv2%20Local"`<br>
Switch between the 3 models respectively.
`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=XTTSv2%20FT"`<br>
If you have a finetuned model in `/models/trainedmodel/` (will error otherwise)
JSON return `{"status": "model-success"}`
#### 🟠 Switch DeepSpeed Endpoint<br>
- URL: `http://127.0.0.1:7851/api/deepspeed`<br> - Method: `POST`<br><br>
`curl -X POST "http://127.0.0.1:7851/api/deepspeed?new_deepspeed_value=True"`
Replace True with False to disable DeepSpeed mode.
JSON return `{"status": "deepspeed-success"}`
#### 🟠 Switching Low VRAM Endpoint<br>
- URL: `http://127.0.0.1:7851/api/lowvramsetting`<br> - Method: `POST`<br><br>
`curl -X POST "http://127.0.0.1:7851/api/lowvramsetting?new_low_vram_value=True"`
Replace True with False to disable Low VRAM mode.
JSON return `{"status": "lowvram-success"}`
### 🟠 TTS Generation Endpoint
- URL: `http://127.0.0.1:7851/api/tts-generate`<br> - Method: `POST`<br> - Content-Type: `application/x-www-form-urlencoded`<br>
### 🟠 Example command lines ### 🟠 Example command lines
Standard TTS speech Example (standard text) generating a time-stamped file<br> Standard TTS speech Example (standard text) generating a time-stamped file<br>
@@ -526,22 +649,22 @@ Example:
🟠 **language**: Choose the language for TTS. Options: 🟠 **language**: Choose the language for TTS. Options:
`ar Arabic`<br> `ar` Arabic<br>
`zh-cn Chinese (Simplified)`<br> `zh-cn` Chinese (Simplified)<br>
`cs Czech`<br> `cs` Czech<br>
`nl Dutch`<br> `nl` Dutch<br>
`en English`<br> `en` English<br>
`fr French`<br> `fr` French<br>
`de German`<br> `de` German<br>
`hu Hungarian`<br> `hu` Hungarian<br>
`it Italian`<br> `it` Italian<br>
`ja Japanese`<br> `ja` Japanese<br>
`ko Korean`<br> `ko` Korean<br>
`pl Polish`<br> `pl` Polish<br>
`pt Portuguese`<br> `pt` Portuguese<br>
`ru Russian`<br> `ru` Russian<br>
`es Spanish`<br> `es` Spanish<br>
`tr Turkish`<br> `tr` Turkish<br>
`-d "language=en"`<br> `-d "language=en"`<br>
@@ -554,12 +677,12 @@ Example:
`-d "output_file_timestamp=true"`<br> `-d "output_file_timestamp=true"`<br>
`-d "output_file_timestamp=false"` `-d "output_file_timestamp=false"`
🟠 **autoplay**: Feature not yet available. Enable or disable autoplay. Still needs to be specified in the JSON request. 🟠 **autoplay**: Enable or disable playing the generated TTS to your standard sound output device at time of TTS generation.
`-d "autoplay=true"`<br> `-d "autoplay=true"`<br>
`-d "autoplay=false"` `-d "autoplay=false"`
🟠 **autoplay_volume**: Feature not yet available. Set the autoplay volume. Should be between 0.1 and 1.0. Still needs to be specified in the JSON request. 🟠 **autoplay_volume**: Set the autoplay volume. Should be between 0.1 and 1.0. Needs to be specified in the JSON request even if autoplay is false.
`-d "autoplay_volume=0.8"` `-d "autoplay_volume=0.8"`
@@ -574,29 +697,6 @@ Example JSON TTS Generation Response:
`{"status": "generate-success", "output_file_path": "C:\text-generation-webui\extensions\alltalk_tts\outputs\myoutputfile_1703149973.wav", "output_file_url": "http://127.0.0.1:7851/audio/myoutputfile_1703149973.wav"}` `{"status": "generate-success", "output_file_path": "C:\text-generation-webui\extensions\alltalk_tts\outputs\myoutputfile_1703149973.wav", "output_file_url": "http://127.0.0.1:7851/audio/myoutputfile_1703149973.wav"}`
🟠 **Switching Model**<br><br>
`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=API%20Local"`<br>
`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=API%20TTS"`<br>
`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=XTTSv2%20Local"`<br>
Switch between the 3 models respectively.
JSON return `{"status": "model-success"}`
🟠 **Switch DeepSpeed**<br><br>
`curl -X POST "http://127.0.0.1:7851/api/deepspeed?new_deepspeed_value=True"`
Replace True with False to disable DeepSpeed mode.
JSON return `{"status": "deepspeed-success"}`
🟠 **Switching Low VRAM**<br><br>
`curl -X POST "http://127.0.0.1:7851/api/lowvramsetting?new_low_vram_value=True"`
Replace True with False to disable Low VRAM mode.
JSON return `{"status": "lowvram-success"}`
### 🔴 Future to-do list ### 🔴 Future to-do list
- Voice output within the command prompt/terminal (TBD). - Voice output within the command prompt/terminal (TBD).
- Correct a few spelling mistakes in the documentation. - Correct a few spelling mistakes in the documentation.
+39 -6
View File
@@ -6,6 +6,7 @@ try:
import torch import torch
import os # Import the os module import os # Import the os module
import re import re
import sys
import glob import glob
import textwrap import textwrap
import packaging.version import packaging.version
@@ -17,7 +18,7 @@ except ImportError as e:
print(f"\033[91mError importing module: {e}\033[0m\n") print(f"\033[91mError importing module: {e}\033[0m\n")
print("\033[94mPlease ensure you started the Text-generation-webUI Python environment with either\033[0m") print("\033[94mPlease ensure you started the Text-generation-webUI Python environment with either\033[0m")
print("\033[92mcmd_linux.sh\033[0m, \033[92mcmd_windows.bat\033[0m, \033[92mcmd_macos.sh\033[0m, or \033[92mcmd_wsl.bat\033[0m") print("\033[92mcmd_linux.sh\033[0m, \033[92mcmd_windows.bat\033[0m, \033[92mcmd_macos.sh\033[0m, or \033[92mcmd_wsl.bat\033[0m")
print("\033[94mand then try running the diagnostics again.\033[0m") print("\033[94mfrom the text-generation-webui directory, and then try running the diagnostics again.\033[0m")
exit(1) exit(1)
try: try:
@@ -110,6 +111,18 @@ def log_system_info():
# Package versions using importlib_metadata # Package versions using importlib_metadata
package_versions = {d.metadata['Name']: d.version for d in distributions()} package_versions = {d.metadata['Name']: d.version for d in distributions()}
# Python environment information
python_executable = sys.executable
python_version_info = sys.version_info
python_virtual_env = os.environ.get('VIRTUAL_ENV', 'N/A')
# Conda environment information
conda_env = os.environ.get('CONDA_DEFAULT_ENV', 'N/A')
# Get Path environment information
search_path = sys.path
path_env = os.environ.get('PATH', 'N/A')
# Compare with requirements file # Compare with requirements file
requirements_file = get_requirements_file() requirements_file = get_requirements_file()
if requirements_file: if requirements_file:
@@ -134,14 +147,24 @@ def log_system_info():
# Log and print information # Log and print information
logging.info(f"OS Version: {os_version}") logging.info(f"OS Version: {os_version}")
logging.info(f"Note: Windows 11 build is 10.x.22xxx") logging.info(f"Note: Windows 11 will list as build is 10.x.22xxx")
logging.info(f"Python Version: {python_version}")
logging.info(f"Torch Version: {torch_version}") logging.info(f"Torch Version: {torch_version}")
logging.info(f"System RAM: {system_ram}") logging.info(f"System RAM: {system_ram}")
logging.info(f"CUDA_HOME: {cuda_home}") logging.info(f"CUDA_HOME: {cuda_home}")
logging.info(f"Port Status: {port_status}") logging.info(f"Port Status: {port_status}")
logging.info(f"Python Version: {platform.python_version()}")
logging.info(f"Python Version Info: {python_version_info}")
logging.info(f"Python Executable: {python_executable}")
logging.info(f"Python Virtual Environment: {python_virtual_env} (Should be N/A when in Text-generation-webui Conda Python environment)")
logging.info(f"Conda Environment: {conda_env}")
logging.info("\nPython Search Path:")
for path in search_path:
logging.info(f" {path}")
logging.info("\nOS PATH Environment Variable:")
for path in path_env.split(';'):
logging.info(f" {path}")
if required_packages: # Check if the dictionary is not empty if required_packages: # Check if the dictionary is not empty
logging.info("Package Versions:") logging.info("\nPackage Versions:")
max_package_length = max(len(package) for package in required_packages.keys()) max_package_length = max(len(package) for package in required_packages.keys())
for package_name, (operator, required_version) in required_packages.items(): for package_name, (operator, required_version) in required_packages.items():
installed_version = installed_packages.get(package_name, 'Not installed') installed_version = installed_packages.get(package_name, 'Not installed')
@@ -153,12 +176,22 @@ def log_system_info():
# Print to screen # Print to screen
print(f"\n\033[94mOS Version:\033[0m \033[92m{os_version}\033[0m") print(f"\n\033[94mOS Version:\033[0m \033[92m{os_version}\033[0m")
print(f"\033[94mOS Ver note:\033[0m \033[92mWindows 11 build is 10.x.22xxx\033[0m") print(f"\033[94mOS Ver note:\033[0m \033[92m(Windows 11 will say build is 10.x.22xxx)\033[0m")
print(f"\033[94mCUDA_HOME:\033[0m \033[92m{cuda_home}\033[0m") print(f"\033[94mCUDA_HOME:\033[0m \033[92m{cuda_home}\033[0m")
print(f"\033[94mSystem RAM:\033[0m \033[92m{system_ram}\033[0m") print(f"\033[94mSystem RAM:\033[0m \033[92m{system_ram}\033[0m")
print(f"\033[94mPort Status:\033[0m \033[92m{port_status}\033[0m") print(f"\033[94mPort Status:\033[0m \033[92m{port_status}\033[0m")
print(f"\033[94mTorch Version:\033[0m \033[92m{torch_version}\033[0m") print(f"\033[94mTorch Version:\033[0m \033[92m{torch_version}\033[0m")
print(f"\033[94mPython Version:\033[0m \033[92m{python_version}\033[0m") print(f"\033[94mPython Version:\033[0m \033[92m{platform.python_version()}\033[0m")
print(f"\033[94mPython Version Info:\033[0m \033[92m{python_version_info}\033[0m")
print(f"\033[94mPython Executable:\033[0m \033[92m{python_executable}\033[0m")
print(f"\033[94mPython Virtual Environment:\033[0m \033[92m{python_virtual_env}\033[0m (Should be N/A when in Text-generation-webui Conda Python environment)")
print(f"\033[94mConda Environment:\033[0m \033[92m{conda_env}\033[0m")
print(f"\n\033[94mPython Search Path:\033[0m")
for path in search_path:
print(f" {path}")
print(f"\n\033[94mOS Search PATH Environment Variable:\033[0m")
for path in path_env.split(';'):
print(f" {path}")
if required_packages: # Check if the dictionary is not empty if required_packages: # Check if the dictionary is not empty
print("\033[94m\nRequirements file package comparison:\033[0m") print("\033[94m\nRequirements file package comparison:\033[0m")
max_package_length = max(len(package) for package in required_packages.keys()) max_package_length = max(len(package) for package in required_packages.keys())
+451 -121
View File
@@ -14,6 +14,7 @@ import gc
import time import time
import shutil import shutil
import pandas import pandas
import glob
import json import json
from pathlib import Path from pathlib import Path
from tqdm import tqdm from tqdm import tqdm
@@ -40,12 +41,27 @@ if modeldownload_config_file_path.exists():
# Extract settings from the loaded JSON # Extract settings from the loaded JSON
base_path = Path(settings.get("base_path", "")) base_path = Path(settings.get("base_path", ""))
model_path = Path(settings.get("model_path", "")) model_path = Path(settings.get("model_path", ""))
base_model_path = Path(settings.get("model_path", ""))
files_to_download = settings.get("files_to_download", {}) files_to_download = settings.get("files_to_download", {})
else: else:
# Default settings if the JSON file doesn't exist or is empty # Default settings if the JSON file doesn't exist or is empty
print("[FINETUNE] \033[91mWarning\033[0m modeldownload.json is missing. Please run this script in the /alltalk_tts/ folder") print("[FINETUNE] \033[91mWarning\033[0m modeldownload.json is missing. Please run this script in the /alltalk_tts/ folder")
sys.exit(1) sys.exit(1)
##################################################
#### Check to see if a finetuned model exists ####
##################################################
# Set the path to the directory
trained_model_directory = this_dir / "models" / "trainedmodel"
# Check if the directory "trainedmodel" exists
finetuned_model = trained_model_directory.exists()
# If the directory exists, check for the existence of the required files
# If true, this will add a extra option in the Gradio interface for loading Xttsv2 FT
if finetuned_model:
required_files = ["model.pth", "config.json", "vocab.json", "mel_stats.pth", "dvae.pth"]
finetuned_model = all((trained_model_directory / file).exists() for file in required_files)
basemodel_or_finetunedmodel = True
##################### #####################
#### STEP 1 BITS #### #### STEP 1 BITS ####
##################### #####################
@@ -270,6 +286,8 @@ def format_audio_list(target_language, whisper_model, out_path, gradio_progress=
# deallocate VRAM and RAM # deallocate VRAM and RAM
del asr_model, final_eval_set, final_training_set, new_data_df, existing_metadata del asr_model, final_eval_set, final_training_set, new_data_df, existing_metadata
gc.collect() gc.collect()
existing_train_df = None
existing_eval_df = None
print("[FINETUNE] Train CSV:", train_metadata_path) print("[FINETUNE] Train CSV:", train_metadata_path)
print("[FINETUNE] Eval CSV:", eval_metadata_path) print("[FINETUNE] Eval CSV:", eval_metadata_path)
print("[FINETUNE] Audio Total:", audio_total_size) print("[FINETUNE] Audio Total:", audio_total_size)
@@ -287,6 +305,13 @@ from TTS.tts.layers.xtts.trainer.gpt_trainer import GPTArgs, GPTTrainer, GPTTrai
from TTS.utils.manage import ModelManager from TTS.utils.manage import ModelManager
def basemodel_or_finetunedmodel_choice(value):
global basemodel_or_finetunedmodel
if value == "Base Model":
basemodel_or_finetunedmodel = True
elif value == "Existing finetuned model":
basemodel_or_finetunedmodel = False
def train_gpt(language, num_epochs, batch_size, grad_acumm, train_csv, eval_csv, output_path, max_audio_length=255995): def train_gpt(language, num_epochs, batch_size, grad_acumm, train_csv, eval_csv, output_path, max_audio_length=255995):
# Logging parameters # Logging parameters
RUN_NAME = "XTTS_FT" RUN_NAME = "XTTS_FT"
@@ -319,12 +344,22 @@ def train_gpt(language, num_epochs, batch_size, grad_acumm, train_csv, eval_csv,
# Add here the configs of the datasets # Add here the configs of the datasets
DATASETS_CONFIG_LIST = [config_dataset] DATASETS_CONFIG_LIST = [config_dataset]
# XTTS model checkpoints for fine-tuning. if basemodel_or_finetunedmodel:
TOKENIZER_FILE = str(this_dir / base_path / model_path / "vocab.json") # vocab.json file # BASE XTTS model checkpoints for fine-tuning.
XTTS_CHECKPOINT = str(this_dir / base_path / model_path / "model.pth") # model.pth file print("[FINETUNE] Starting finetuning on Base Model")
XTTS_CONFIG_FILE = str(this_dir / base_path / model_path / "config.json") # config.json file TOKENIZER_FILE = str(this_dir / base_path / model_path / "vocab.json")
DVAE_CHECKPOINT = str(this_dir / base_path / model_path / "dvae.pth") XTTS_CHECKPOINT = str(this_dir / base_path / model_path / "model.pth")
MEL_NORM_FILE = str(this_dir / base_path / model_path / "mel_stats.pth") XTTS_CONFIG_FILE = str(this_dir / base_path / model_path / "config.json")
DVAE_CHECKPOINT = str(this_dir / base_path / model_path / "dvae.pth")
MEL_NORM_FILE = str(this_dir / base_path / model_path / "mel_stats.pth")
else:
# FINETUNED XTTS model checkpoints for fine-tuning.
print("[FINETUNE] Starting finetuning on Existing Finetuned Model")
TOKENIZER_FILE = str(this_dir / base_path / "trainedmodel" / "vocab.json")
XTTS_CHECKPOINT = str(this_dir / base_path / "trainedmodel" / "model.pth")
XTTS_CONFIG_FILE = str(this_dir / base_path / "trainedmodel" / "config.json")
DVAE_CHECKPOINT = str(this_dir / base_path / "trainedmodel" / "dvae.pth")
MEL_NORM_FILE = str(this_dir / base_path / "trainedmodel" / "mel_stats.pth")
# init args and config # init args and config
model_args = GPTArgs( model_args = GPTArgs(
@@ -415,9 +450,14 @@ def train_gpt(language, num_epochs, batch_size, grad_acumm, train_csv, eval_csv,
trainer_out_path = trainer.output_path trainer_out_path = trainer.output_path
# deallocate VRAM and RAM # deallocate VRAM and RAM
del model, trainer, train_samples, eval_samples del model, trainer, train_samples, eval_samples, config, model_args, config_dataset
gc.collect() gc.collect()
train_samples = None
eval_samples = None
config_dataset = None
trainer = None
model = None
model_args = None
return XTTS_CONFIG_FILE, XTTS_CHECKPOINT, TOKENIZER_FILE, trainer_out_path, speaker_ref return XTTS_CONFIG_FILE, XTTS_CHECKPOINT, TOKENIZER_FILE, trainer_out_path, speaker_ref
########################## ##########################
@@ -495,7 +535,222 @@ xtts_config_files = find_jsons(main_directory, "config.json")
# XTTS vocab files (vocab.json) # XTTS vocab files (vocab.json)
xtts_vocab_files = find_jsons(main_directory, "vocab.json") xtts_vocab_files = find_jsons(main_directory, "vocab.json")
##########################
#### STEP 4 AND OTHER ####
##########################
def find_latest_best_model(folder_path):
search_path = folder_path / "XTTS_FT-*" / "best_model.pth"
files = glob.glob(str(search_path), recursive=True)
latest_file = max(files, key=os.path.getctime, default=None)
return latest_file
def compact_model():
this_dir = Path(__file__).parent.resolve()
best_model_path_str = find_latest_best_model(this_dir / "finetune" / "tmp-trn" / "training")
# Check if the best model file exists
if best_model_path_str is None:
print("[FINETUNE] No trained model was found.")
return "No trained model was found."
# Convert model_path_str to Path
best_model_path = Path(best_model_path_str)
# Attempt to load the model
try:
checkpoint = torch.load(best_model_path, map_location=torch.device("cpu"))
except Exception as e:
print("[FINETUNE] Error loading checkpoint:", e)
raise
del checkpoint["optimizer"]
for key in list(checkpoint["model"].keys()):
if "dvae" in key:
del checkpoint["model"][key]
# Define the target directory
target_dir = this_dir / "models" / "trainedmodel"
# Create the target directory if it doesn't exist
target_dir.mkdir(parents=True, exist_ok=True)
# Save the modified checkpoint in the target directory
torch.save(checkpoint, target_dir / "model.pth")
# Specify the files you want to copy
files_to_copy = ["vocab.json", "config.json", "dvae.pth", "mel_stats.pth"]
for file_name in files_to_copy:
src_path = this_dir / base_path / base_model_path / file_name
dest_path = target_dir / file_name
shutil.copy(str(src_path), str(dest_path))
source_wavs_dir = this_dir / "finetune" / "tmp-trn" / "wavs"
target_wavs_dir = target_dir / "wavs"
target_wavs_dir.mkdir(parents=True, exist_ok=True)
# Iterate through files in the source directory
for file_path in source_wavs_dir.iterdir():
# Check if it's a file and larger than 1000 KB
if file_path.is_file() and file_path.stat().st_size > 1000 * 1024:
# Copy the file to the target directory
shutil.copy(str(file_path), str(target_wavs_dir / file_path.name))
print("[FINETUNE] Model copied to '/models/trainedmodel/'")
return "Model copied to '/models/trainedmodel/'"
def compact_lastfinetuned_model():
this_dir = Path(__file__).parent.resolve()
best_model_path_str = find_latest_best_model(this_dir / "finetune" / "tmp-trn" / "training")
# Check if the best model file exists
if best_model_path_str is None:
print("[FINETUNE] No trained model was found.")
return "No trained model was found."
# Convert model_path_str to Path
best_model_path = Path(best_model_path_str)
# Attempt to load the model
try:
checkpoint = torch.load(best_model_path, map_location=torch.device("cpu"))
except Exception as e:
print("[FINETUNE] Error loading checkpoint:", e)
raise
del checkpoint["optimizer"]
for key in list(checkpoint["model"].keys()):
if "dvae" in key:
del checkpoint["model"][key]
# Define the target directory
target_dir = this_dir / "models" / "lastfinetuned"
# Create the target directory if it doesn't exist
target_dir.mkdir(parents=True, exist_ok=True)
# Save the modified checkpoint in the target directory
torch.save(checkpoint, target_dir / "model.pth")
# Specify the files you want to copy
files_to_copy = ["vocab.json", "config.json", "dvae.pth", "mel_stats.pth"]
for file_name in files_to_copy:
src_path = this_dir / base_path / base_model_path / file_name
dest_path = target_dir / file_name
shutil.copy(str(src_path), str(dest_path))
source_wavs_dir = this_dir / "finetune" / "tmp-trn" / "wavs"
target_wavs_dir = target_dir / "wavs"
target_wavs_dir.mkdir(parents=True, exist_ok=True)
# Iterate through files in the source directory
for file_path in source_wavs_dir.iterdir():
# Check if it's a file and larger than 1000 KB
if file_path.is_file() and file_path.stat().st_size > 1000 * 1024:
# Copy the file to the target directory
shutil.copy(str(file_path), str(target_wavs_dir / file_path.name))
print("[FINETUNE] Model copied to '/models/lastfinetuned/'")
return "Model copied to '/models/lastfinetuned/'"
def compact_legacy_model():
this_dir = Path(__file__).parent.resolve()
best_model_path_str = os.path.join(this_dir, "finetune", "best_model.pth")
# Check if the best model file exists
if not os.path.exists(best_model_path_str):
print("[FINETUNE] No model called best_model.pth was found in /finetune/")
return "No model called best_model.pth was found in /finetune/"
# Convert model_path_str to Path
best_model_path = Path(best_model_path_str)
# Attempt to load the model
try:
checkpoint = torch.load(best_model_path, map_location=torch.device("cpu"))
except Exception as e:
print("[FINETUNE] Error loading checkpoint:", e)
raise
del checkpoint["optimizer"]
for key in list(checkpoint["model"].keys()):
if "dvae" in key:
del checkpoint["model"][key]
# Define the target directory
target_dir = this_dir / "finetune"
# Create the target directory if it doesn't exist
target_dir.mkdir(parents=True, exist_ok=True)
# Save the modified checkpoint in the target directory
torch.save(checkpoint, target_dir / "model.pth")
print("[FINETUNE] model.pth created in '/finetune/'")
return "model.pth created in '/finetune/'"
def delete_training_data():
# Define the folder to be deleted
folder_to_delete = Path(this_dir / "finetune" / "tmp-trn")
# Check if the folder exists before deleting
if folder_to_delete.exists():
# Iterate over all files and subdirectories
for item in folder_to_delete.iterdir():
# Exclude trainer_0_log.txt from deletion
if item.name != "trainer_0_log.txt":
try:
if item.is_file():
item.unlink()
elif item.is_dir():
shutil.rmtree(item)
except PermissionError:
print(f"[FINETUNE] PermissionError: Could not delete {item}. Skipping.")
print(f"[FINETUNE] Folder {folder_to_delete} contents (excluding trainer_0_log.txt) deleted successfully.")
return "Folder '/finetune/tmp-trn/' contents (excluding trainer_0_log.txt) deleted successfully."
else:
print(f"[FINETUNE] Folder {folder_to_delete} does not exist.")
return "Folder '/finetune/tmp-trn/' does not exist."
def delete_voice_sample_contents():
# Define the folder to be cleared
folder_to_clear = Path(this_dir / "finetune" / "put-voice-samples-in-here")
# Check if the folder exists before clearing its contents
if folder_to_clear.exists() and folder_to_clear.is_dir():
# List all files and subdirectories in the folder
for item in os.listdir(folder_to_clear):
item_path = folder_to_clear / item
if item_path.is_file():
# If it's a file, remove it
os.remove(item_path)
elif item_path.is_dir():
# If it's a subdirectory, remove it recursively
shutil.rmtree(item_path)
print(f"[FINETUNE] Contents of {folder_to_clear} deleted successfully.")
return f"Contents of 'put-voice-samples-in-here deleted' successfully."
else:
print(f"[FINETUNE] Folder {folder_to_clear} does not exist.")
return f"Folder 'put-voice-samples-in-here' does not exist."
#######################
#### OTHER Generic ####
#######################
# define a logger to redirect # define a logger to redirect
class Logger: class Logger:
def __init__(self, filename="finetune.log"): def __init__(self, filename="finetune.log"):
@@ -620,20 +875,21 @@ if __name__ == "__main__":
f""" f"""
## <u>Finetuning Information</u><br> ## <u>Finetuning Information</u><br>
### 🟥 <u>Important Note</u> ### 🟥 <u>Important Note</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟥 <span style="color: #3366ff;">finetune.py</span> needs to be run from the <span style="color: #3366ff;">/alltalk_tts/</span> folder. Don't move the location of this script. #### &nbsp;&nbsp;&nbsp;&nbsp; - <span style="color: #3366ff;">finetune.py</span> needs to be run from the <span style="color: #3366ff;">/alltalk_tts/</span> folder. Don't move the location of this script.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟥 Have you run AllTalk at least once? It needs to have downloaded+updated the voice model, before we can finetune it. #### &nbsp;&nbsp;&nbsp;&nbsp; - Have you run AllTalk at least once? It needs to have downloaded+updated the voice model, before we can finetune it.
### 🟦 <u>What you need to run finetuning</u> ### 🟦 <u>What you need to run finetuning</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 An Nvidia GPU. Tested on Windows with extended shared VRAM and training used about 16GB's total (which worked on a 12GB card). #### &nbsp;&nbsp;&nbsp;&nbsp; - An Nvidia GPU. Tested on Windows with extended shared VRAM and training used about 16GB's total (which worked on a 12GB card).
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 I have not been able to test this on a GPU with less than 12GB of VRAM, so cannot say if it will work or how that would affect performance. #### &nbsp;&nbsp;&nbsp;&nbsp; - If you have multiple Nvidia GPU's in your system, please see this [important note](https://github.com/erew123/alltalk_tts#-i-have-multiple-gpus-and-i-have-problems-running-finetuning).
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 <span style="color: red;">Version 11.8</span> of Nvidia cuBLAS and cuDNN (guide below). Only 11.8 of cuBLAS and cuDNN work for this process currently. #### &nbsp;&nbsp;&nbsp;&nbsp; - I have not been able to test this on a GPU with less than 12GB of VRAM, so cannot say if it will work or how that would affect performance.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 Minimum <span style="color: red;">18GB</span> free disk space (most of it is used temporarily). #### &nbsp;&nbsp;&nbsp;&nbsp; - <span style="color: red;">Version 11.8</span> of Nvidia cuBLAS and cuDNN (guide below). Only 11.8 of cuBLAS and cuDNN work for this process currently.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 Some decent quality audio, multiple files if you like. Minimum of 2 minutes and Ive tested up to 20 minutes of audio. #### &nbsp;&nbsp;&nbsp;&nbsp; - Minimum <span style="color: red;">18GB</span> free disk space (most of it is used temporarily).
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 There is no major need to chop down your audio files into small slices as Step 1 will do that for you automatically and prepare the training set. Ive been testing with 5 minute long clips. #### &nbsp;&nbsp;&nbsp;&nbsp; - Some decent quality audio, multiple files if you like. Minimum of 2 minutes and Ive tested up to 20 minutes of audio.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 This process will need access to all your GPU and VRAM, so close any other software that's using your GPU currently. #### &nbsp;&nbsp;&nbsp;&nbsp; - There is no major need to chop down your audio files into small slices as Step 1 will do that for you automatically and prepare the training set. Ive been testing with 5 minute long clips.
#### &nbsp;&nbsp;&nbsp;&nbsp; - This process will need access to all your GPU and VRAM, so close any other software that's using your GPU currently.
### 🟨 <u>Setting up cuBLAS and cuDNN <span style="color: red;">Version 11.8</span></u> ### 🟨 <u>Setting up cuBLAS and cuDNN <span style="color: red;">Version 11.8</span></u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 If you have the <span style="color: #3366ff;;">Nvidia CUDA Toolkit Version 11.8</span> installed and can type <span style="color: #3366ff;;">nvcc --version</span> at the command prompt/terminal and it reports <span style="color: #00a000;">Cuda compilation tools, release 11.8</span> you should be good to go. #### &nbsp;&nbsp;&nbsp;&nbsp; - If you have the <span style="color: #3366ff;;">Nvidia CUDA Toolkit Version 11.8</span> installed and can type <span style="color: #3366ff;;">nvcc --version</span> at the command prompt/terminal and it reports <span style="color: #00a000;">Cuda compilation tools, release 11.8</span> you should be good to go.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 If you dont have the toolkit installed, the idea is just to install the smallest bit possible and this will not affect or impact other things on your system. #### &nbsp;&nbsp;&nbsp;&nbsp; - If you dont have the toolkit installed, the idea is just to install the smallest bit possible and this will not affect or impact other things on your system.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 You will need to download the Nvidia Cuda Toolkit 11.8<span style="color: #3366ff;"> network</span> install from [here](https://developer.nvidia.com/cuda-11-8-0-download-archive) #### &nbsp;&nbsp;&nbsp;&nbsp; - You will need to download the Nvidia Cuda Toolkit 11.8<span style="color: #3366ff;"> network</span> install from [here](https://developer.nvidia.com/cuda-11-8-0-download-archive)
#### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) Run the installer and select <span style="color: #3366ff;">Custom Advanced</span> Uncheck <span style="color: #3366ff;">everything</span> at the top then expand <span style="color: #3366ff;">CUDA</span>, <span style="color: #3366ff;">Development</span> > <span style="color: #3366ff;">Compiler</span> > and select <span style="color: #3366ff;;">nvcc</span> then expand <span style="color: #3366ff;;">Libraries</span> and select <span style="color: #3366ff;;">CUBLAS</span>. #### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1) Run the installer and select <span style="color: #3366ff;">Custom Advanced</span> Uncheck <span style="color: #3366ff;">everything</span> at the top then expand <span style="color: #3366ff;">CUDA</span>, <span style="color: #3366ff;">Development</span> > <span style="color: #3366ff;">Compiler</span> > and select <span style="color: #3366ff;;">nvcc</span> then expand <span style="color: #3366ff;;">Libraries</span> and select <span style="color: #3366ff;;">CUBLAS</span>.
#### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) Back at the top of <span style="color: #3366ff;">CUDA</span>, expand <span style="color: #3366ff;">Runtime</span> > <span style="color: #3366ff;">Libraries</span> and select <span style="color: #3366ff;">CUBLAS</span>. Click <span style="color: #3366ff;;">Next</span>, accept the default path (taking a note of its location) and let the install run. #### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2) Back at the top of <span style="color: #3366ff;">CUDA</span>, expand <span style="color: #3366ff;">Runtime</span> > <span style="color: #3366ff;">Libraries</span> and select <span style="color: #3366ff;">CUBLAS</span>. Click <span style="color: #3366ff;;">Next</span>, accept the default path (taking a note of its location) and let the install run.
#### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) You should be able to drop to your terminal or command prompt and type <span style="color: #3366ff;">nvcc --version</span> and have it report <span style="color: #00a000;">Cuda compilation tools, release 11.8</span>. If it does you are good to go. If it doesn't > Step 4. #### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3) You should be able to drop to your terminal or command prompt and type <span style="color: #3366ff;">nvcc --version</span> and have it report <span style="color: #00a000;">Cuda compilation tools, release 11.8</span>. If it does you are good to go. If it doesn't > Step 4.
@@ -657,16 +913,16 @@ if __name__ == "__main__":
f""" f"""
## <u>STEP 1 - Preparing Audio/Generating the dataset</u><br> ## <u>STEP 1 - Preparing Audio/Generating the dataset</u><br>
### 🟦 <u>What you need to do</u> ### 🟦 <u>What you need to do</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 Please read Coqui's guide on what makes a good dataset [here](https://docs.coqui.ai/en/latest/what_makes_a_good_dataset.html#what-makes-a-good-dataset) #### &nbsp;&nbsp;&nbsp;&nbsp; - Please read Coqui's guide on what makes a good dataset [here](https://docs.coqui.ai/en/latest/what_makes_a_good_dataset.html#what-makes-a-good-dataset)
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 Place your audio files in <span style="color: #3366ff;">{str(audio_folder)}</span> #### &nbsp;&nbsp;&nbsp;&nbsp; - Place your audio files in <span style="color: #3366ff;">{str(audio_folder)}</span>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 Your audio samples can be in the format <span style="color: #3366ff;">mp3, wav,</span> or <span style="color: #3366ff;">flac.</span> #### &nbsp;&nbsp;&nbsp;&nbsp; - Your audio samples can be in the format <span style="color: #3366ff;">mp3, wav,</span> or <span style="color: #3366ff;">flac.</span>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 You will need a minimum of <span style="color: #3366ff;">2 minutes</span> of audio in either one or multiple audio files. #### &nbsp;&nbsp;&nbsp;&nbsp; - You will need a minimum of <span style="color: #3366ff;">2 minutes</span> of audio in either one or multiple audio files. Very small sample files cause errors, so I would suggest 30 seconds and longer samples.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 When you have completed Steps 1, 2, and 3, you are welcome to delete your samples from "put-voice-samples-in-here".<br> #### &nbsp;&nbsp;&nbsp;&nbsp; - When you have completed Steps 1, 2, and 3, you are welcome to delete your samples from "put-voice-samples-in-here".<br>
### 🟨 <u>What this step is doing</u> ### 🟨 <u>What this step is doing</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 With step one, we are going to be stripping your audio file(s) into smaller files, using Whisper to find spoken words/sentences, compile that into excel sheets of training data, ready for finetuning the model on Step 2. #### &nbsp;&nbsp;&nbsp;&nbsp; - With step one, we are going to be stripping your audio file(s) into smaller files, using Whisper to find spoken words/sentences, compile that into excel sheets of training data, ready for finetuning the model on Step 2.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 Whilst you can choose multiple Whisper models, its best only to use the 1 model as each one is about 3GB in size and will download to your local huggingface cache on first-time use. If and when you have completed training, you wish to delete this 3GB model from your system, you are welcome to do so. #### &nbsp;&nbsp;&nbsp;&nbsp; - Whilst you can choose multiple Whisper models, its best only to use the 1 model as each one is about 3GB in size and will download to your local huggingface cache on first-time use. If and when you have completed training, you wish to delete this 3GB model from your system, you are welcome to do so.
### 🟩 <u>How long will this take?</u> ### 🟩 <u>How long will this take?</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟩 First time, it needs to download the Whisper model which is 3GB. After that a few minutes on an average 3-4 year old system. #### &nbsp;&nbsp;&nbsp;&nbsp; - First time, it needs to download the Whisper model which is 3GB. After that a few minutes on an average 3-4 year old system.
""" """
) )
@@ -675,41 +931,41 @@ if __name__ == "__main__":
value=out_path, value=out_path,
visible=False, visible=False,
) )
with gr.Row():
whisper_model = gr.Dropdown(
label="Whisper Model",
value="large-v3",
choices=[
"large-v3",
"large-v2",
"large",
"medium",
"small"
],
)
whisper_model = gr.Dropdown( lang = gr.Dropdown(
label="Whisper Model", label="Dataset Language",
value="large-v3", value="en",
choices=[ choices=[
"large-v3", "en",
"large-v2", "es",
"large", "fr",
"medium", "de",
"small" "it",
], "pt",
) "pl",
"tr",
lang = gr.Dropdown( "ru",
label="Dataset Language", "nl",
value="en", "cs",
choices=[ "ar",
"en", "zh",
"es", "hu",
"fr", "ko",
"de", "ja"
"it", ],
"pt", )
"pl",
"tr",
"ru",
"nl",
"cs",
"ar",
"zh",
"hu",
"ko",
"ja"
],
)
progress_data = gr.Label( progress_data = gr.Label(
label="Progress:" label="Progress:"
) )
@@ -744,6 +1000,7 @@ if __name__ == "__main__":
print("[FINETUNE] Dataset Generated. Move to Step 2") print("[FINETUNE] Dataset Generated. Move to Step 2")
return "Dataset Generated. Move to Step 2", train_meta, eval_meta return "Dataset Generated. Move to Step 2", train_meta, eval_meta
####################### #######################
#### GRADIO STEP 2 #### #### GRADIO STEP 2 ####
####################### #######################
@@ -753,51 +1010,67 @@ if __name__ == "__main__":
f""" f"""
## <u>STEP 2 - Fine-tuning the XTTS Encoder</u><br> ## <u>STEP 2 - Fine-tuning the XTTS Encoder</u><br>
### 🟦 <u>What you need to do</u> ### 🟦 <u>What you need to do</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 The <span style="color: #3366ff;">Train CSV</span> and <span style="color: #3366ff;">Eval CSV</span> should already be populated. If not, just go back to Step 1 and click the button again. #### &nbsp;&nbsp;&nbsp;&nbsp; - The <span style="color: #3366ff;">Train CSV</span> and <span style="color: #3366ff;">Eval CSV</span> should already be populated. If not, just go back to Step 1 and click the button again.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 If for any reason it crashed, close the app and re-start the finetuning and kick it off again, clicking through setp 1 (it doesnt need to regenerate the data) #### &nbsp;&nbsp;&nbsp;&nbsp; - If for any reason it crashed, close the app and re-start the finetuning and kick it off again, clicking through setp 1 (it doesnt need to regenerate the data)
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 The settings below are factory and should be ok.<br> #### &nbsp;&nbsp;&nbsp;&nbsp; - The settings below are factory and should be ok.<br>
### 🟨 <u>What this step is doing</u> ### 🟨 <u>What this step is doing</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 Very simply put, it's taking all our wav files generated in Step 1, along with our recorded speech in out excel documents and its training the model on that voice. #### &nbsp;&nbsp;&nbsp;&nbsp; - Very simply put, it's taking all our wav files generated in Step 1, along with our recorded speech in out excel documents and its training the model on that voice.
### 🟩 <u>How long will this take?</u> ### 🟩 <u>How long will this take?</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟩 On a RTX 4070 with factory settings (as below) and 20 minutes of audio, this took 20 minutes. Again, it will vary by system and how much audio you are throwing at it. You have time to go make a coffee. #### &nbsp;&nbsp;&nbsp;&nbsp; - On a RTX 4070 with factory settings (as below) and 20 minutes of audio, this took 20 minutes. Again, it will vary by system and how much audio you are throwing at it. You have time to go make a coffee.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟩 Look at your command prompt/terminal window if you want to see what it is doing. #### &nbsp;&nbsp;&nbsp;&nbsp; - Look at your command prompt/terminal window if you want to see what it is doing.
""" """
) )
with gr.Row():
train_csv = gr.Textbox(
label="Train CSV:",
)
eval_csv = gr.Textbox(
label="Eval CSV:",
)
with gr.Row():
num_epochs = gr.Slider(
label="Number of epochs:",
minimum=1,
maximum=100,
step=1,
value=args.num_epochs,
)
batch_size = gr.Slider(
label="Batch size:",
minimum=2,
maximum=512,
step=1,
value=args.batch_size,
)
grad_acumm = gr.Slider(
label="Grad accumulation steps:",
minimum=2,
maximum=128,
step=1,
value=args.grad_acumm,
)
max_audio_length = gr.Slider(
label="Max permitted audio size in seconds:",
minimum=2,
maximum=20,
step=1,
value=args.max_audio_length,
)
with gr.Row():
model_to_train_choices = ["Base Model"]
if finetuned_model:
model_to_train_choices.append("Existing finetuned model")
model_to_train = gr.Radio(
choices=model_to_train_choices,
label="Which model do you want to train?",
value="Base Model"
)
gr.Markdown(
f"""
##### If you have an existing finetuned model in <span style="color: #3366ff;">/models/trainedmodel/</span> you will have an option to select <span style="color: #3366ff;">Existing finetuned model</span>, allowing you to further train it. Otherwise, you will only have Base Model as an option.
"""
)
train_csv = gr.Textbox(
label="Train CSV:",
)
eval_csv = gr.Textbox(
label="Eval CSV:",
)
num_epochs = gr.Slider(
label="Number of epochs:",
minimum=1,
maximum=100,
step=1,
value=args.num_epochs,
)
batch_size = gr.Slider(
label="Batch size:",
minimum=2,
maximum=512,
step=1,
value=args.batch_size,
)
grad_acumm = gr.Slider(
label="Grad accumulation steps:",
minimum=2,
maximum=128,
step=1,
value=args.grad_acumm,
)
max_audio_length = gr.Slider(
label="Max permitted audio size in seconds:",
minimum=2,
maximum=20,
step=1,
value=args.max_audio_length,
)
progress_train = gr.Label( progress_train = gr.Label(
label="Progress:" label="Progress:"
) )
@@ -839,16 +1112,16 @@ if __name__ == "__main__":
f""" f"""
## <u>STEP 3 - Inference/Testing</u><br> ## <u>STEP 3 - Inference/Testing</u><br>
### 🟥 <u>Important Note</u> ### 🟥 <u>Important Note</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟥 This step will error if you are using TTS version 0.22.0. Please re-run <span style="color: #3366ff;">pip install -r requirements_finetune.txt</span> if it errors loading the model. #### &nbsp;&nbsp;&nbsp;&nbsp; - This step will error if you are using TTS version 0.22.0. Please re-run <span style="color: #3366ff;">pip install -r requirements_finetune.txt</span> if it errors loading the model.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟥 If you dont see multiple speaker reference files and you used more than 3 minutes of speech, try refreshing the page as it may not have loaded them correctly. #### &nbsp;&nbsp;&nbsp;&nbsp; - If you dont see multiple speaker reference files and you used more than 3 minutes of speech, try refreshing the page as it may not have loaded them correctly.
### 🟦 <u>What you need to do</u> ### 🟦 <u>What you need to do</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 The model is now trained and you are at the testing stage. Hopefully all the dropdowns should be pre-populated now. #### &nbsp;&nbsp;&nbsp;&nbsp; - The model is now trained and you are at the testing stage. Hopefully all the dropdowns should be pre-populated now.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 You need to <span style="color: #3366ff;">Load Fine-tuned XTTS model</span> and then select your <span style="color: #3366ff;">Speaker Reference Audio</span>. You can choose various <span style="color: #3366ff;">Speaker Reference Audios</span> to see which works best. #### &nbsp;&nbsp;&nbsp;&nbsp; - You need to <span style="color: #3366ff;">Load Fine-tuned XTTS model</span> and then select your <span style="color: #3366ff;">Speaker Reference Audio</span>. You can choose various <span style="color: #3366ff;">Speaker Reference Audios</span> to see which works best.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 All the <span style="color: #3366ff;">Speaker Reference Audios</span> in the dropdown are ones that are <span style="color: #3366ff;">8 seconds</span> long or more. You can use one of these later for your voice sample in All Talk, so remember the one you like. #### &nbsp;&nbsp;&nbsp;&nbsp; - All the <span style="color: #3366ff;">Speaker Reference Audios</span> in the dropdown are ones that are <span style="color: #3366ff;">8 seconds</span> long or more. You can use one of these later for your voice sample in All Talk, so remember the one you like.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 Some <span style="color: #3366ff;">Speaker Reference Audios</span> are a bit long and may cause issues generating the TTS, so try different ones. #### &nbsp;&nbsp;&nbsp;&nbsp; - Some <span style="color: #3366ff;">Speaker Reference Audios</span> are a bit long and may cause issues generating the TTS, so try different ones.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 Once you are happy, move to the next tab for instruction on cleaning out the training data and how to copy your newly trained model over your current model. #### &nbsp;&nbsp;&nbsp;&nbsp; - Once you are happy, move to the next tab for instruction on cleaning out the training data and how to copy your newly trained model over your current model.
### 🟨 <u>What this step is doing</u> ### 🟨 <u>What this step is doing</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 Its loading the finetuned model into memory, loading a voice sample and generating TTS, so that you can test out how well fine tuning worked. #### &nbsp;&nbsp;&nbsp;&nbsp; - Its loading the finetuned model into memory, loading a voice sample and generating TTS, so that you can test out how well fine tuning worked.
""" """
) )
@@ -941,22 +1214,57 @@ if __name__ == "__main__":
f""" f"""
## <u>What to do next</u><br> ## <u>What to do next</u><br>
### 🟦 <u>What you need to do</u> ### 🟦 <u>What you need to do</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 The wav(s) you liked from <span style="color: #3366ff;">Speaker Reference Audios</span> are in <span style="color: #3366ff;">/finetune/tmp-trn/wavs/</span> so copy the one(s) you selected to your <span style="color: #3366ff;">/alltalk_tts/voices/</span> samples folder. #### &nbsp;&nbsp;&nbsp;&nbsp; - You have a few options below:
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 You can delete your original samples from inside of the <span style="color: #3366ff;">/finetune/put-voice-samples-in-here/</span> folder. #### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 🔹 Compact &amp; move model. This will compress the raw finetuned model and move it, along with any large enough wav files created to one of two locations (please read text next to the button).<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; You can use the wav files in that location as sample voices with your model. Models moved to <span style="color: #3366ff;">/models/trainedmodel/</span> will be loadable within Text-gen-webui on the <span style="color: #3366ff;">XTTSv2 FT</span> loader.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 In the folder <span style="color: #3366ff;">/finetune/tmp-trn/training/XTTS_FT(date here)/</span> you will find your <span style="color: #3366ff;">best_model.pth</span>, <span style="color: #3366ff;">config.json</span> and <span style="color: #3366ff;">vocab.json</span> (also the last epoch training best_model_xxx.pth) #### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 🔹 Delete Generated Training data. This will delete the finetuned model and any other training data generated during this process. You will more than likely want to do this after you have Compacted &amp; moved the model.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 You can delete the last epoch training model file <span style="color: #3366ff;">best_model_xxx.pth</span> (the one with the numbers). #### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 🔹 Delete original voice samples. This will delete the voice samples you placed in put-voice-samples-in-here (if you no longer have a use for them).
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 You will need to rename <span style="color: #3366ff;">best_model.pth</span> to <span style="color: #3366ff;">model.pth</span>. #### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 🔹 Compress a legacy finetuned model. For any models that were generated pre the current version of finetuning, you can still compact them down.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 You will close the Finetuning application and copy your 3 files listed above over the top of the existing model files inside your <span style="color: #3366ff;">/alltalk_tts/models/xttsv2_2.0.2/</span> folder. #### &nbsp;&nbsp;&nbsp;&nbsp; - Instructions on using the finetuned model in Text-generation-webui and also further tuning this model you just created are on <span style="color: #3366ff;">OPTION A - Compact and move model to '/trainedmodel/'</span>.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟦 Start up Alltalk and you should be off and running. Preferably use the <span style="color: #3366ff;">XTTS Local</span> method for best results.
### 🟨 <u>Clearing up disk space</u> ### 🟨 <u>Clearing up disk space</u>
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 When you are happy with everything, you can delete the <span style="color: #3366ff;">/alltalk_tts/finetune/tmp-trn/</span> folder. This will delete all training data that was generated. #### &nbsp;&nbsp;&nbsp;&nbsp; - If you are not going to train anything again, you can delete the whisper model from inside of your huggingface cache (3GB approx)
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 If you are not going to train anything again, you can delete the whisper model from inside of your huggingface cache (3GB approx)
#### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Linux <span style="color: #3366ff;">~/.cache/huggingface/hub/(folder-here)</span> #### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Linux <span style="color: #3366ff;">~/.cache/huggingface/hub/(folder-here)</span>
#### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Windows <span style="color: #3366ff;">C:&bsol;users&lpar;your-username&rpar;&bsol;.cache&bsol;huggingface&bsol;hub&bsol;(folder-here)</span>. #### &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Windows <span style="color: #3366ff;">C:&bsol;users&lpar;your-username&rpar;&bsol;.cache&bsol;huggingface&bsol;hub&bsol;(folder-here)</span>.
#### &nbsp;&nbsp;&nbsp;&nbsp; 🟨 You can also uninstall the Nvidia CUDA 11.8 Toolkit if you wish and remove your environment variable entries. #### &nbsp;&nbsp;&nbsp;&nbsp; - You can also uninstall the Nvidia CUDA 11.8 Toolkit if you wish and remove your environment variable entries.
""" """
) )
final_progress_data = gr.Label(
label="Progress:"
)
with gr.Row():
compact_btn = gr.Button(value="OPTION A - Compact and move model to '/trainedmodel/'")
gr.Markdown(
f"""
##### This will compact the model and move it, along with the reference wav's to <span style="color: #3366ff;">/models/trainedmodel/</span> and will <span style="color: red;">OVERWRITE</span> any model in that location. This model will become available to load in Text-gen-webui with the <span style="color: #3366ff;">XTTSv2 FT</span> loader. It will also be detected by Finetune as a model that can be further trained (Reload finetune.py).
"""
)
with gr.Row():
compact_lastfinetuned_btn = gr.Button(value="OPTION B - Compact and move model to '/lastfinetuned/'")
gr.Markdown(
f"""
##### This will compact the model and move it, along with the reference wav's to <span style="color: #3366ff;">/models/lastfinetuned/</span> and will <span style="color: red;">OVERWRITE</span> any model in that location. This will just leave you a finetuned model that you can do with as you please. It will <span style="color: red;">NOT</span> be available in Text-gen-webui unless you copy it over one of the other model loader locations.
"""
)
with gr.Row():
delete_training_btn = gr.Button(value="Delete generated training data")
gr.Markdown(
f"""
##### This will <span style="color: red;">DELETE</span> your training data and the raw finetuned model from <span style="color: #3366ff;">/finetune/tmp-trn/</span>.
"""
)
with gr.Row():
delete_voicesamples_btn = gr.Button(value="Delete original voice samples")
gr.Markdown(
f"""
##### This will <span style="color: red;">DELETE</span> your original voice samples from <span style="color: #3366ff;">/finetune/put-voice-samples-in-here/</span>.
"""
)
with gr.Row():
compact_legacy_btn = gr.Button(value="Compact a legacy finetuned model")
gr.Markdown(
f"""
##### This will compact your old finetuned models from 5GB to 1.9GB. Place your 5GB <span style="color: #3366ff;">base_model.pth</span> file in <span style="color: #3366ff;">/finetune/</span> (rename your file to <span style="color: #3366ff;">base_model.pth</span> if necessary). This will generate you a <span style="color: #3366ff;">model.pth</span> file.
"""
)
prompt_compute_btn.click( prompt_compute_btn.click(
fn=preprocess_dataset, fn=preprocess_dataset,
@@ -1007,6 +1315,28 @@ if __name__ == "__main__":
], ],
outputs=[progress_gen, tts_output_audio, reference_audio], outputs=[progress_gen, tts_output_audio, reference_audio],
) )
compact_btn.click(
fn=compact_model,
outputs=[final_progress_data],
)
compact_lastfinetuned_btn.click(
fn=compact_lastfinetuned_model,
outputs=[final_progress_data],
)
delete_training_btn.click(
fn=delete_training_data,
outputs=[final_progress_data],
)
delete_voicesamples_btn.click(
fn=delete_voice_sample_contents,
outputs=[final_progress_data],
)
compact_legacy_btn.click(
fn=compact_legacy_model,
outputs=[final_progress_data],
)
model_to_train.change(basemodel_or_finetunedmodel_choice, model_to_train, None)
demo.queue().launch( demo.queue().launch(
show_api=False, show_api=False,
+26
View File
@@ -0,0 +1,26 @@
import torch
import os
MODEL_PATH = "best_model.pth"
# Check if best_model.pth exists
if not os.path.exists(MODEL_PATH):
print(f"\nCannot find \033[94m{MODEL_PATH}\033[0m in the current folder.")
# Check if model.pth exists as an alternative
ALTERNATIVE_PATH = "model.pth"
if os.path.exists(ALTERNATIVE_PATH):
print(f"\nIf your model is currently called \033[93m{ALTERNATIVE_PATH}\033[0m please rename it to \033[94mbest_model.pth\033[0m.")
else:
print(f"Please put \033[91mbest_model.pth\033[0m in the current folder or rename your model file to \033[94mbest_model.pth\033[0m.")
exit(1)
# Attempt to load the model
try:
checkpoint = torch.load(MODEL_PATH, map_location=torch.device("cpu"))
except Exception as e:
print("Error loading checkpoint:", e)
raise
del checkpoint["optimizer"]
for key in list(checkpoint["model"].keys()):
if "dvae" in key:
del checkpoint["model"][key]
torch.save(checkpoint, "model.pth")
print(f"\nYour compacted model is created \033[93mmodel.pth\033[0m.")
+2 -1
View File
@@ -8,6 +8,7 @@
"model.pth": "https://huggingface.co/coqui/XTTS-v2/resolve/v2.0.2/model.pth?download=true", "model.pth": "https://huggingface.co/coqui/XTTS-v2/resolve/v2.0.2/model.pth?download=true",
"dvae.pth": "https://huggingface.co/coqui/XTTS-v2/resolve/v2.0.2/dvae.pth?download=true", "dvae.pth": "https://huggingface.co/coqui/XTTS-v2/resolve/v2.0.2/dvae.pth?download=true",
"mel_stats.pth": "https://huggingface.co/coqui/XTTS-v2/resolve/v2.0.2/mel_stats.pth?download=true", "mel_stats.pth": "https://huggingface.co/coqui/XTTS-v2/resolve/v2.0.2/mel_stats.pth?download=true",
"speakers_xtts.pth": "https://huggingface.co/coqui/XTTS-v2/resolve/v2.0.2/speakers_xtts.pth?download=true",
"vocab.json": "https://huggingface.co/coqui/XTTS-v2/resolve/v2.0.2/vocab.json?download=true" "vocab.json": "https://huggingface.co/coqui/XTTS-v2/resolve/v2.0.2/vocab.json?download=true"
} }
} }
+2
View File
@@ -11,3 +11,5 @@ tqdm>=4.66.1
importlib-metadata>=4.8.1 importlib-metadata>=4.8.1
packaging>=23.2 packaging>=23.2
pydantic>=1.10.13 pydantic>=1.10.13
sounddevice>=0.4.6
python-multipart>=0.0.6
+2
View File
@@ -11,3 +11,5 @@ tqdm>=4.66.1
importlib-metadata>=4.8.1 importlib-metadata>=4.8.1
packaging>=23.2 packaging>=23.2
pydantic>=1.10.13 pydantic>=1.10.13
sounddevice>=0.4.6
python-multipart>=0.0.6
+55 -21
View File
@@ -77,6 +77,8 @@ with open(this_dir / "languages.json", encoding="utf8") as f:
languages = json.load(f) languages = json.load(f)
# Create a global lock # Create a global lock
process_lock = threading.Lock() process_lock = threading.Lock()
# Base setting for a possible FineTuned model existing and the loader being available
tts_method_xtts_ft = False
# Gather the voice files # Gather the voice files
def get_available_voices(): def get_available_voices():
@@ -139,10 +141,23 @@ def check_required_files():
subprocess.run(["python", str(download_script_path)]) subprocess.run(["python", str(download_script_path)])
print(f"[{params['branding']}Startup] All required files are present.") print(f"[{params['branding']}Startup] All required files are present.")
# STARTUP Call Check routine # STARTUP Call Check routine
check_required_files() check_required_files()
##################################################
#### Check to see if a finetuned model exists ####
##################################################
# Set the path to the directory
trained_model_directory = this_dir / "models" / "trainedmodel"
# Check if the directory "trainedmodel" exists
finetuned_model = trained_model_directory.exists()
# If the directory exists, check for the existence of the required files
# If true, this will add a extra option in the Gradio interface for loading Xttsv2 FT
if finetuned_model:
required_files = ["model.pth", "config.json", "vocab.json"]
finetuned_model = all((trained_model_directory / file).exists() for file in required_files)
if finetuned_model:
print(f"[{params['branding']}Startup] Finetuned model \033[93mDetected\033[0m")
#################################################### ####################################################
#### SET GRADIO BUTTONS BASED ON confignew.json #### #### SET GRADIO BUTTONS BASED ON confignew.json ####
@@ -252,7 +267,7 @@ else:
timeout = 120 # Adjust the timeout as needed timeout = 120 # Adjust the timeout as needed
# Introduce a delay before starting the check loop # Introduce a delay before starting the check loop
time.sleep(25) # Wait 25 secs before checking if the tts_server.py has started up. time.sleep(26) # Wait 26 secs before checking if the tts_server.py has started up.
start_time = time.time() start_time = time.time()
while time.time() - start_time < timeout: while time.time() - start_time < timeout:
try: try:
@@ -264,7 +279,7 @@ while time.time() - start_time < timeout:
print( print(
f"[{params['branding']}Startup] \033[91mWarning\033[0m TTS Subprocess has NOT started up yet, Will keep trying for 120 seconds maximum. Please wait." f"[{params['branding']}Startup] \033[91mWarning\033[0m TTS Subprocess has NOT started up yet, Will keep trying for 120 seconds maximum. Please wait."
) )
time.sleep(1) time.sleep(4)
else: else:
print( print(
f"[{params['branding']}Startup] Startup timed out. Check the server logs for more information." f"[{params['branding']}Startup] Startup timed out. Check the server logs for more information."
@@ -272,11 +287,13 @@ else:
# Cleanly kill off this script, but allow text-generation-webui to keep running, albeit without this alltalk_tts # Cleanly kill off this script, but allow text-generation-webui to keep running, albeit without this alltalk_tts
sys.exit(1) sys.exit(1)
##################################### #####################################
#### MODEL LOADING AND UNLOADING #### #### MODEL LOADING AND UNLOADING ####
##################################### #####################################
# MODEL - Swap model based on Gradio selection API TTS, API Local, XTTSv2 Local # MODEL - Swap model based on Gradio selection API TTS, API Local, XTTSv2 Local
def send_reload_request(tts_method): def send_reload_request(tts_method):
global tts_method_xtts_ft
try: try:
params["tts_model_loaded"] = False params["tts_model_loaded"] = False
url = f"{base_url}/api/reload" url = f"{base_url}/api/reload"
@@ -295,17 +312,26 @@ def send_reload_request(tts_method):
params["tts_method_api_tts"] = True params["tts_method_api_tts"] = True
params["deepspeed_activate"] = False params["deepspeed_activate"] = False
audio_path = this_dir / "templates" / "apitts.wav" audio_path = this_dir / "templates" / "apitts.wav"
tts_method_xtts_ft = False
elif tts_method == "API Local": elif tts_method == "API Local":
params["tts_method_api_tts"] = False params["tts_method_api_tts"] = False
params["tts_method_xtts_local"] = False params["tts_method_xtts_local"] = False
params["tts_method_api_local"] = True params["tts_method_api_local"] = True
params["deepspeed_activate"] = False params["deepspeed_activate"] = False
audio_path = this_dir / "templates" / "apilocal.wav" audio_path = this_dir / "templates" / "apilocal.wav"
tts_method_xtts_ft = False
elif tts_method == "XTTSv2 Local": elif tts_method == "XTTSv2 Local":
params["tts_method_api_tts"] = False params["tts_method_api_tts"] = False
params["tts_method_api_local"] = False params["tts_method_api_local"] = False
params["tts_method_xtts_local"] = True params["tts_method_xtts_local"] = True
audio_path = this_dir / "templates" / "xttslocal.wav" audio_path = this_dir / "templates" / "xttslocal.wav"
tts_method_xtts_ft = False
elif tts_method == "XTTSv2 FT":
params["tts_method_api_tts"] = False
params["tts_method_api_local"] = False
params["tts_method_xtts_local"] = False
audio_path = this_dir / "templates" / "xttsfinetuned.wav"
tts_method_xtts_ft = True
return f'<audio src="file/{audio_path}" controls autoplay></audio>' return f'<audio src="file/{audio_path}" controls autoplay></audio>'
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
# Handle the HTTP request error # Handle the HTTP request error
@@ -483,6 +509,9 @@ def voice_preview(string):
return f"[{params['branding']}Server] Audio generation failed. Status: {generate_response.get('status')}" return f"[{params['branding']}Server] Audio generation failed. Status: {generate_response.get('status')}"
def replace_asterisk(match):
return match.group(0) + '&quot;<*'
################################# #################################
#### TTS STANDARD GENERATION #### #### TTS STANDARD GENERATION ####
################################# #################################
@@ -501,32 +530,34 @@ def output_modifier(string, state):
if process_lock.acquire(blocking=False): if process_lock.acquire(blocking=False):
try: try:
if params["narrator_enabled"]: if params["narrator_enabled"]:
#print(original_string)
# Do Some basic stripping and remove any double CR's # Do Some basic stripping and remove any double CR's
processed_string = ( processed_string = (
original_string original_string
.replace("***", "*") .replace("***", "*")
.replace("**", "*") .replace("**", "*")
.replace("\n\n", "\n") .replace("\n\n", "\n")
.replace("\n", "")
) )
# Clean up two asterisks (narrators) being made between a newline, making it one sentence.
processed_string = re.sub(r'\.\*\n\*', '. ', processed_string) processed_string = re.sub(r'\.\*\n\*', '. ', processed_string)
# Clean up a few other bits. processed_string = (processed_string .replace('&quot;\n\n*', '&quot;<*'))
processed_string = ( processed_string = (processed_string .replace('&quot;\n', '< '))
processed_string processed_string = (processed_string .replace("&#x27;", "'"))
.replace("&#x27;", "'") processed_string = (processed_string .replace("\n", " "))
.replace("\n", " ") processed_string = (processed_string .replace('&quot;', '&quot;<'))
# Add special characters to the quote so that we can use it to identify things later after its been split processed_string = (processed_string .replace('"', '&quot;<'))
.replace('&quot;', '&quot;<') #pattern = re.compile(r'(?<=[a-zA-Z!])&quot;<(?=[a-zA-Z])')
# Capture new conversations which wont have things like &quote in them pattern = re.compile(r'(?<=[a-zA-Z!?\.])&quot;<(?=[a-zA-Z])')
.replace('"', '&quot;<') processed_string = pattern.sub('&quot; ', processed_string)
) pattern = re.compile(r'(?<=[a-zA-Z])\*(?=[a-zA-Z])')
#capturing another outlier in inital character paragraph processed_string = pattern.sub('*&quot;', processed_string)
#print("processed string 1 is:", processed_string)
processed_string = processed_string.replace('&quot;<. *', '&quot;< *"') processed_string = processed_string.replace('&quot;<. *', '&quot;< *"')
processed_string = processed_string.replace('< *"', '< *') processed_string = processed_string.replace('< *"', '< *')
processed_string = processed_string.replace('. *', '< *') processed_string = processed_string.replace('. *', '< *')
#print("processed string 2 is:", processed_string) processed_string = processed_string.replace('! *', '&quot;< *')
processed_string = processed_string.replace('? *', '< *')
processed_string = processed_string.replace('* ', '* &quot;<')
processed_string = processed_string.replace('*. ', '* &quot;<')
processed_string = re.sub(r'\*(?=[a-zA-Z])', replace_asterisk, processed_string)
# Set up a tracking of the individual wav files. # Set up a tracking of the individual wav files.
audio_files_all_paragraphs = [] audio_files_all_paragraphs = []
# Split the line using &quot; and ".* " (so end of sentences, leaving special characters added to the start of all OTHER sentences, bar possibly the first one if its starting with a * # Split the line using &quot; and ".* " (so end of sentences, leaving special characters added to the start of all OTHER sentences, bar possibly the first one if its starting with a *
@@ -534,7 +565,7 @@ def output_modifier(string, state):
audio_files_paragraph = [] audio_files_paragraph = []
for i, part in enumerate(parts): for i, part in enumerate(parts):
# Skip parts that are too short # Skip parts that are too short
if len(part.strip()) <= 1: if len(part.strip()) <= 3:
continue continue
# Figure out which type of line it is, then replace characters as necessary to avoid TTS trying to pronunce them, htmlunescape after. # Figure out which type of line it is, then replace characters as necessary to avoid TTS trying to pronunce them, htmlunescape after.
# Character will always be a < with a letter immediately after it # Character will always be a < with a letter immediately after it
@@ -779,14 +810,17 @@ def ui():
deepspeed_checkbox_play = gr.HTML(visible=False) deepspeed_checkbox_play = gr.HTML(visible=False)
with gr.Row(): with gr.Row():
model_loader_choices=["API TTS", "API Local", "XTTSv2 Local"]
if finetuned_model:
model_loader_choices.append("XTTSv2 FT")
tts_radio_buttons = gr.Radio( tts_radio_buttons = gr.Radio(
choices=["API TTS", "API Local", "XTTSv2 Local"], choices=model_loader_choices,
label="Select TTS Generation Method (Read NOTE)", label="Select TTS Generation Method (Read NOTE)",
value=gr_modelchoice, # Set the default value value=gr_modelchoice, # Set the default value
) )
tts_radio_buttons_play = gr.HTML(visible=False) tts_radio_buttons_play = gr.HTML(visible=False)
explanation_text = gr.HTML( explanation_text = gr.HTML(
f"<p>NOTE: Switching Model Type, Low VRAM & DeepSpeed, each takes 15 seconds. Each TTS generation method has a slightly different sound. DeepSpeed checkbox is only visible if DeepSpeed is present. Readme & Settings: <a href='http://{params['ip_address']}:{params['port_number']}'>http://{params['ip_address']}:{params['port_number']}</a>" f"<p>⚙️ <a href='http://{params['ip_address']}:{params['port_number']}'>Click here for the Settings page, help & instructions</a><a href='http://{params['ip_address']}:{params['port_number']}'></a>⚙️<br>NOTE: Switching Model Type, Low VRAM & DeepSpeed, each takes 15 seconds. Each TTS generation method has a slightly different sound. DeepSpeed checkbox is only visible if DeepSpeed is installed on your system."
) )
with gr.Row(): with gr.Row():
Binary file not shown.
+151 -20
View File
@@ -33,7 +33,8 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
# STARTUP VARIABLE - Import languges file for Gradio to be able to display them in the interface # STARTUP VARIABLE - Import languges file for Gradio to be able to display them in the interface
with open(this_dir / "languages.json", encoding="utf8") as f: with open(this_dir / "languages.json", encoding="utf8") as f:
languages = json.load(f) languages = json.load(f)
# Base setting for a possible FineTuned model existing and the loader being available
tts_method_xtts_ft = False
################################################################# #################################################################
#### LOAD PARAMS FROM confignew.json - REQUIRED FOR BRANDING #### #### LOAD PARAMS FROM confignew.json - REQUIRED FOR BRANDING ####
@@ -123,7 +124,7 @@ app = FastAPI(lifespan=startup_shutdown)
##################################### #####################################
#### MODEL LOADING AND UNLOADING #### #### MODEL LOADING AND UNLOADING ####
##################################### #####################################
# MODEL LOADERS Picker For API TTS, API Local, XTTSv2 Local # MODEL LOADERS Picker For API TTS, API Local, XTTSv2 Local, XTTSv2 FT
async def setup(): async def setup():
global device global device
# Set a timer to calculate load times # Set a timer to calculate load times
@@ -150,6 +151,13 @@ async def setup():
"\033[0m", "\033[0m",
) )
model = await xtts_manual_load_model() model = await xtts_manual_load_model()
elif tts_method_xtts_ft:
print(
f"[{params['branding']}Model] \033[94mXTTSv2 FT Loading\033[0m /models/fintuned/model.pth \033[94minto\033[93m",
device,
"\033[0m",
)
model = await xtts_ft_manual_load_model()
# Create an end timer for calculating load times # Create an end timer for calculating load times
generate_end_time = time.time() generate_end_time = time.time()
# Calculate start time minus end time # Calculate start time minus end time
@@ -222,6 +230,23 @@ async def xtts_manual_load_model():
model.to(device) model.to(device)
return model return model
# MODEL LOADER For "XTTSv2 FT"
async def xtts_ft_manual_load_model():
global model
config = XttsConfig()
config_path = this_dir / "models" / "trainedmodel" / "config.json"
vocab_path_dir = this_dir / "models" / "trainedmodel" / "vocab.json"
checkpoint_dir = this_dir / "models" / "trainedmodel"
config.load_json(str(config_path))
model = Xtts.init_from_config(config)
model.load_checkpoint(
config,
checkpoint_dir=str(checkpoint_dir),
vocab_path=str(vocab_path_dir),
use_deepspeed=params["deepspeed_activate"],
)
model.to(device)
return model
# MODEL UNLOADER # MODEL UNLOADER
async def unload_model(model): async def unload_model(model):
@@ -236,6 +261,7 @@ async def unload_model(model):
# MODEL - Swap model based on Gradio selection API TTS, API Local, XTTSv2 Local # MODEL - Swap model based on Gradio selection API TTS, API Local, XTTSv2 Local
async def handle_tts_method_change(tts_method): async def handle_tts_method_change(tts_method):
global model global model
global tts_method_xtts_ft
# Update the params dictionary based on the selected radio button # Update the params dictionary based on the selected radio button
print( print(
f"[{params['branding']}Model] \033[94mChanging model \033[92m(Please wait 15 seconds)\033[0m" f"[{params['branding']}Model] \033[94mChanging model \033[92m(Please wait 15 seconds)\033[0m"
@@ -246,15 +272,23 @@ async def handle_tts_method_change(tts_method):
params["tts_method_xtts_local"] = False params["tts_method_xtts_local"] = False
params["tts_method_api_tts"] = True params["tts_method_api_tts"] = True
params["deepspeed_activate"] = False params["deepspeed_activate"] = False
tts_method_xtts_ft = False
elif tts_method == "API Local": elif tts_method == "API Local":
params["tts_method_api_tts"] = False params["tts_method_api_tts"] = False
params["tts_method_xtts_local"] = False params["tts_method_xtts_local"] = False
params["tts_method_api_local"] = True params["tts_method_api_local"] = True
params["deepspeed_activate"] = False params["deepspeed_activate"] = False
tts_method_xtts_ft = False
elif tts_method == "XTTSv2 Local": elif tts_method == "XTTSv2 Local":
params["tts_method_api_tts"] = False params["tts_method_api_tts"] = False
params["tts_method_api_local"] = False params["tts_method_api_local"] = False
params["tts_method_xtts_local"] = True params["tts_method_xtts_local"] = True
tts_method_xtts_ft = False
elif tts_method == "XTTSv2 FT":
tts_method_xtts_ft = True
params["tts_method_api_tts"] = False
params["tts_method_api_local"] = False
params["tts_method_xtts_local"] = False
# Unload the current model # Unload the current model
model = await unload_model(model) model = await unload_model(model)
@@ -267,7 +301,7 @@ async def handle_tts_method_change(tts_method):
@app.route("/api/reload", methods=["POST"]) @app.route("/api/reload", methods=["POST"])
async def reload(request: Request): async def reload(request: Request):
tts_method = request.query_params.get("tts_method") tts_method = request.query_params.get("tts_method")
if tts_method not in ["API TTS", "API Local", "XTTSv2 Local"]: if tts_method not in ["API TTS", "API Local", "XTTSv2 Local", "XTTSv2 FT"]:
return {"status": "error", "message": "Invalid TTS method specified"} return {"status": "error", "message": "Invalid TTS method specified"}
await handle_tts_method_change(tts_method) await handle_tts_method_change(tts_method)
return Response( return Response(
@@ -424,8 +458,8 @@ async def generate_audio(text, voice, language, output_file):
if params["low_vram"] and device == "cpu": if params["low_vram"] and device == "cpu":
await switch_device() await switch_device()
generate_start_time = time.time() # Record the start time of generating TTS generate_start_time = time.time() # Record the start time of generating TTS
# XTTSv2 LOCAL Method # XTTSv2 LOCAL & Xttsv2 FT Method
if params["tts_method_xtts_local"]: if params["tts_method_xtts_local"] or tts_method_xtts_ft:
print(f"[{params['branding']}TTSGen] {text}") print(f"[{params['branding']}TTSGen] {text}")
gpt_cond_latent, speaker_embedding = model.get_conditioning_latents( gpt_cond_latent, speaker_embedding = model.get_conditioning_latents(
audio_path=[f"{this_dir}/voices/{voice}"], audio_path=[f"{this_dir}/voices/{voice}"],
@@ -619,16 +653,84 @@ async def get_audio(filename: str):
audio_path = this_dir / "outputs" / filename audio_path = this_dir / "outputs" / filename
return FileResponse(audio_path) return FileResponse(audio_path)
#########################
#### VOICES LIST API ####
#########################
# Define the new endpoint
@app.get("/api/voices")
async def get_voices():
wav_files = list_files(this_dir / "voices")
return {"voices": wav_files}
###########################
#### PREVIEW VOICE API ####
###########################
@app.post("/api/previewvoice/", response_class=JSONResponse)
async def preview_voice(request: Request, voice: str = Form(...)):
try:
# Hardcoded settings
language = "en"
output_file_name = "api_preview_voice"
# Clean the voice filename for inclusion in the text
clean_voice_filename = re.sub(r'\.wav$', '', voice.replace(' ', '_'))
clean_voice_filename = re.sub(r'[^a-zA-Z0-9]', ' ', clean_voice_filename)
# Generate the audio
text = f"Hello, this is a preview of voice {clean_voice_filename}."
# Generate the audio
output_file_path = this_dir / "outputs" / f"{output_file_name}.wav"
await generate_audio(text, voice, language, output_file_path)
# Generate the URL
output_file_url = f'http://{params["ip_address"]}:{params["port_number"]}/audio/{output_file_name}.wav'
# Return the response with both local file path and URL
return JSONResponse(
content={
"status": "generate-success",
"output_file_path": str(output_file_path),
"output_file_url": str(output_file_url),
},
status_code=200,
)
except Exception as e:
print(f"An error occurred: {e}")
return JSONResponse(content={"error": "An error occurred"}, status_code=500)
######################## ########################
#### GENERATION API #### #### GENERATION API ####
######################## ########################
import html import html
import re import re
import uuid
import numpy as np import numpy as np
import soundfile as sf import soundfile as sf
import sys
# Check for PortAudio library on Linux
try:
import sounddevice as sd
sounddevice_installed=True
except OSError:
print(f"[{params['branding']}Startup] \033[91mInfo\033[0m PortAudio library not found. If you wish to play TTS in standalone mode through the API suite")
print(f"[{params['branding']}Startup] \033[91mInfo\033[0m please install PortAudio. This will not affect any other features or use of Alltalk.")
print(f"[{params['branding']}Startup] \033[91mInfo\033[0m If you don't know what the API suite is, then this message is nothing to worry about.")
sounddevice_installed=False
if sys.platform.startswith('linux'):
print(f"[{params['branding']}Startup] \033[91mInfo\033[0m On Linux, you can use the following command to install PortAudio:")
print(f"[{params['branding']}Startup] \033[91mInfo\033[0m sudo apt-get install portaudio19-dev")
from typing import Union, Dict from typing import Union, Dict
from pydantic import BaseModel, ValidationError, Field from pydantic import BaseModel, ValidationError, Field
def play_audio(file_path, volume):
data, fs = sf.read(file_path)
sd.play(volume * data, fs)
sd.wait()
class Request(BaseModel): class Request(BaseModel):
# Define the structure of the 'Request' class if needed # Define the structure of the 'Request' class if needed
pass pass
@@ -737,10 +839,6 @@ async def tts_generate(
autoplay_volume: float = Form(...), autoplay_volume: float = Form(...),
): ):
try: try:
#print(f"text_filtering: {text_filtering}")
#print(f"narrator_enabled: {narrator_enabled}")
#print(f"text_not_inside: {text_not_inside}")
#print(f"output_file_timestamp: {output_file_timestamp}")
json_input_data = { json_input_data = {
"text_input": text_input, "text_input": text_input,
"text_filtering": text_filtering, "text_filtering": text_filtering,
@@ -760,49 +858,41 @@ async def tts_generate(
else: else:
return JSONResponse(content={"error": JSONresult}, status_code=400) return JSONResponse(content={"error": JSONresult}, status_code=400)
if narrator_enabled: if narrator_enabled:
print("ORIGINAL UNTOUCHED STRING IS:", text_input,"\n") #print("ORIGINAL UNTOUCHED STRING IS:", text_input,"\n")
if text_filtering in ["standard", "none"]: if text_filtering in ["standard", "none"]:
cleaned_string = ( cleaned_string = (
text_input text_input
.replace('"', '"<') .replace('"', '"<')
.replace('*', '<*') .replace('*', '<*')
) )
print("STANDARD FILTERING IS NOW:", cleaned_string,"\n")
#parts = re.split(r'\.(?<!<[*"])', cleaned_string)
parts = re.split(r'(?<=<\*\s)|(?<=\.\s)|(?<=\."\<)|(?<=\."<)', cleaned_string) parts = re.split(r'(?<=<\*\s)|(?<=\.\s)|(?<=\."\<)|(?<=\."<)', cleaned_string)
parts = list(filter(lambda x: x.strip(), parts)) parts = list(filter(lambda x: x.strip(), parts))
elif text_filtering == "html": elif text_filtering == "html":
cleaned_string = standard_filtering(text_input) cleaned_string = standard_filtering(text_input)
cleaned_string = narrator_filtering(cleaned_string) cleaned_string = narrator_filtering(cleaned_string)
print("HTML FILTERING IS NOW:", cleaned_string,"\n")
parts = re.split(r'&quot;|\.\*', cleaned_string) parts = re.split(r'&quot;|\.\*', cleaned_string)
audio_files_all_paragraphs = [] audio_files_all_paragraphs = []
audio_files_paragraph = [] audio_files_paragraph = []
for i, part in enumerate(parts): for i, part in enumerate(parts):
if len(part.strip()) <= 1: if len(part.strip()) <= 1:
continue continue
print("THIS IS A PART", part)
# Figure out which type of line it is, then replace characters as necessary to avoid TTS trying to pronunce them, htmlunescape after. # Figure out which type of line it is, then replace characters as necessary to avoid TTS trying to pronunce them, htmlunescape after.
# Character will always be a < with a letter immediately after it # Character will always be a < with a letter immediately after it
if '<' in part and '<*' not in part and '< *' not in part and '< *' not in part and '< ' not in part and '< ' not in part: if '<' in part and '<*' not in part and '< *' not in part and '< *' not in part and '< ' not in part and '< ' not in part:
print("IF - Character\n")
cleaned_part = html.unescape(part.replace('<', '')) cleaned_part = html.unescape(part.replace('<', ''))
voice_to_use = character_voice_gen voice_to_use = character_voice_gen
#Narrator will always be an * or < with an * a position or two after it. #Narrator will always be an * or < with an * a position or two after it.
elif '<*' in part or '< *' in part or '< *' in part or '*' in part: elif '<*' in part or '< *' in part or '< *' in part or '*' in part:
print("IF - Narrator\n")
cleaned_part = html.unescape(part.replace('<*', '').replace('< *', '').replace('< *', '').replace('*', '').replace('<. ', '')) cleaned_part = html.unescape(part.replace('<*', '').replace('< *', '').replace('< *', '').replace('*', '').replace('<. ', ''))
voice_to_use = narrator_voice_gen voice_to_use = narrator_voice_gen
#If the other two dont capture it, aka, the AI gave no * or &quot; on the line, use non_quoted_text_is aka user interface, user can choose Char or Narrator #If the other two dont capture it, aka, the AI gave no * or &quot; on the line, use non_quoted_text_is aka user interface, user can choose Char or Narrator
elif text_not_inside == "character": elif text_not_inside == "character":
print("ELSE - CHARACTER\n")
cleaned_part = html.unescape(part.replace('< ', '').replace('< ', '').replace('< ', '')) cleaned_part = html.unescape(part.replace('< ', '').replace('< ', '').replace('< ', ''))
voice_to_use = character_voice_gen voice_to_use = character_voice_gen
elif text_not_inside == "narrator": elif text_not_inside == "narrator":
print("ELSE - NARRATOR\n")
cleaned_part = html.unescape(part.replace('< ', '').replace('< ', '').replace('< ', '')) cleaned_part = html.unescape(part.replace('< ', '').replace('< ', '').replace('< ', ''))
voice_to_use = narrator_voice_gen voice_to_use = narrator_voice_gen
output_file = this_dir / "outputs" / f"{output_file_name}_{int(time.time())}_{i}.wav" output_file = this_dir / "outputs" / f"{output_file_name}_{uuid.uuid4()}_{int(time.time())}_{i}.wav"
output_file_str = output_file.as_posix() output_file_str = output_file.as_posix()
await generate_audio(cleaned_part, voice_to_use, language, output_file_str) await generate_audio(cleaned_part, voice_to_use, language, output_file_str)
audio_path = output_file_str audio_path = output_file_str
@@ -826,6 +916,10 @@ async def tts_generate(
else: else:
cleaned_string = text_input cleaned_string = text_input
await generate_audio(cleaned_string, character_voice_gen, language, output_file_path) await generate_audio(cleaned_string, character_voice_gen, language, output_file_path)
if sounddevice_installed == False:
autoplay = False
if autoplay:
play_audio(output_file_path, autoplay_volume)
return JSONResponse(content={"status": "generate-success", "output_file_path": str(output_file_path), "output_file_url": str(output_file_url)}, status_code=200) return JSONResponse(content={"status": "generate-success", "output_file_path": str(output_file_path), "output_file_url": str(output_file_url)}, status_code=200)
except Exception as e: except Exception as e:
return JSONResponse(content={"status": "generate-failure", "error": "An error occurred"}, status_code=500) return JSONResponse(content={"status": "generate-failure", "error": "An error occurred"}, status_code=500)
@@ -1157,7 +1251,7 @@ simple_webpage = """
<p style="padding-left: 30px; text-align: justify;">Save your generated wav file in the&nbsp;<span style="color: #3366ff;">/alltalk_tts/voices/ <span style="color: #808080;">folder.</span></span></p> <p style="padding-left: 30px; text-align: justify;">Save your generated wav file in the&nbsp;<span style="color: #3366ff;">/alltalk_tts/voices/ <span style="color: #808080;">folder.</span></span></p>
<p style="padding-left: 30px; text-align: justify;">Its worth mentioning that using AI generated audio clips may introduce unwanted sounds as its already a copy/simulation of a voice.</p> <p style="padding-left: 30px; text-align: justify;">Its worth mentioning that using AI generated audio clips may introduce unwanted sounds as its already a copy/simulation of a voice.</p>
<h4>Why doesnt it sound like XXX Person?</h4> <h4>Why doesnt it sound like XXX Person?</h4>
<p style="padding-left: 30px; text-align: justify;">The reasons can be that you:</p> <p style="padding-left: 30px; text-align: justify;">Maybe you might be interested in trying <a href="#finetune">Finetuning of the model</a>. Otherwise, the reasons can be that you:</p>
<ul style="text-align: justify;"> <ul style="text-align: justify;">
<li>Didn't downsample it as above.</li> <li>Didn't downsample it as above.</li>
<li>Have a bad quality voice sample.</li> <li>Have a bad quality voice sample.</li>
@@ -1672,6 +1766,33 @@ simple_webpage = """
<p style="padding-left: 30px;"><span style="color: #3366ff;">curl -X POST "http://127.0.0.1:7851/api/lowvramsetting?new_low_vram_value=True"</span></p> <p style="padding-left: 30px;"><span style="color: #3366ff;">curl -X POST "http://127.0.0.1:7851/api/lowvramsetting?new_low_vram_value=True"</span></p>
<p style="padding-left: 30px;">Replace True with False to disable Low VRAM mode.</p> <p style="padding-left: 30px;">Replace True with False to disable Low VRAM mode.</p>
<p style="padding-left: 30px;">JSON return <span style="color: #339966;">{"status": "lowvram-success"}</span></p> <p style="padding-left: 30px;">JSON return <span style="color: #339966;">{"status": "lowvram-success"}</span></p>
<h4>Ready Endpoint</strong></h4>
<p>Check if the Text-to-Speech (TTS) service is ready to accept requests.</p>
<ul>
<li>URL: <span style="color: #3366ff;">http://127.0.0.1:7851/api/ready</span></li>
<li>Method: <span style="color: #3366ff;">GET</span></li>
<li>Response: <span style="color: #339966;">Ready</span></li>
</ul>
<p style="padding-left: 30px;"><span style="color: #3366ff;">curl -X GET "http://127.0.0.1:7851/api/ready"</span></p>
<h4>Voices List Endpoint</strong></h4>
<p>Retrieve a list of available voices for generating speech.</p>
<ul>
<li>URL: <span style="color: #3366ff;">http://127.0.0.1:7851/api/voices</span></li>
<li>Method: <span style="color: #3366ff;">GET</span></li>
</ul>
<p style="padding-left: 30px;"><span style="color: #3366ff;">curl -X GET "http://127.0.0.1:7851/api/voices"</span></p>
<p style="padding-left: 30px;">JSON return: <span style="color: #339966;">{"voices": ["voice1.wav", "voice2.wav", "voice3.wav"]}</span></p>
<h4><strong>Preview Voice Endpoint</strong></h4>
<p>Generate a preview of a specified voice with hardcoded settings.</p>
<ul>
<li>URL: <span style="color: #3366ff;">http://127.0.0.1:7851/api/previewvoice/</span></li>
<li>Method: <span style="color: #3366ff;">POST</span></li>
<li>Content-Type: <span style="color: #3366ff;">application/x-www-form-urlencoded</span></li>
</ul>
<p style="padding-left: 30px;"><span style="color: #3366ff;">curl -X POST "http://127.0.0.1:7851/api/previewvoice/" -F "voice=female_01.wav"</span></p>
<p style="padding-left: 30px;">Replace <span style="color: #3366ff;">female_01.wav</span> with the name of the voice sample you want to hear.</p>
<p style="padding-left: 30px;">JSON return: <span style="color: #339966;">{"status": "generate-success", "output_file_path": "/path/to/outputs/api_preview_voice.wav", "output_file_url": "http://127.0.0.1:7851/audio/api_preview_voice.wav"}</span></p>
<p><a href="#toc">Back to top of page<br /></a></p> <p><a href="#toc">Back to top of page<br /></a></p>
<h2 id="debugging-and-tts-generation-information"><strong>Debugging and TTS Generation Information</strong></h2> <h2 id="debugging-and-tts-generation-information"><strong>Debugging and TTS Generation Information</strong></h2>
@@ -1716,10 +1837,20 @@ template = Template(simple_webpage)
# Render the template with the dynamic values # Render the template with the dynamic values
rendered_html = template.render(params=params) rendered_html = template.render(params=params)
###############################
#### Internal script ready ####
###############################
@app.get("/ready") @app.get("/ready")
async def ready(): async def ready():
return Response("Ready endpoint") return Response("Ready endpoint")
############################
#### External API ready ####
############################
@app.get("/api/ready")
async def ready():
return Response("Ready")
@app.get("/") @app.get("/")
async def read_root(): async def read_root():
return HTMLResponse(content=rendered_html, status_code=200) return HTMLResponse(content=rendered_html, status_code=200)