CoolFace
Apppublic

Florii/Aesthetic_RVC

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
processing.py220 linesDownload Raw Back to tabs
1import sys2 3sys.path.append("..")4import os5 6now_dir = os.getcwd()7from lib.infer.infer_libs.train.process_ckpt import (8    change_info,9    extract_small_model,10    merge,11    show_info,12)13from assets.i18n.i18n import I18nAuto14 15i18n = I18nAuto()16 17import gradio as gr18import traceback19 20 21def change_info_(ckpt_path):22    if not os.path.exists(ckpt_path.replace(os.path.basename(ckpt_path), "train.log")):23        return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}24    try:25        with open(26            ckpt_path.replace(os.path.basename(ckpt_path), "train.log"), "r"27        ) as f:28            info = eval(f.read().strip("\n").split("\n")[0].split("\t")[-1])29            sr, f0 = info["sample_rate"], info["if_f0"]30            version = "v2" if ("version" in info and info["version"] == "v2") else "v1"31            return sr, str(f0), version32    except:33        traceback.print_exc()34        return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}35 36 37def processing_():38 39        with gr.Accordion(40            label=i18n("Model fusion, can be used to test timbre fusion")41        ):42            with gr.Row():43                with gr.Column():44                    name_to_save0 = gr.Textbox(45                        label=i18n("Name:"),46                        value="",47                        max_lines=1,48                        interactive=True,49                        placeholder=i18n("Name for saving"),50                    )51                    alpha_a = gr.Slider(52                        minimum=0,53                        maximum=1,54                        label=i18n("Weight for Model A:"),55                        value=0.5,56                        interactive=True,57                    )58                    if_f0_ = gr.Checkbox(59                        label=i18n("Whether the model has pitch guidance."),60                        value=True,61                        interactive=True,62                    )63                    version_2 = gr.Radio(64                        label=i18n("Model architecture version:"),65                        choices=["v1", "v2"],66                        value="v2",67                        interactive=True,68                    )69                    sr_ = gr.Radio(70                        label=i18n("Target sample rate:"),71                        choices=["40k", "48k", "32k"],72                        value="40k",73                        interactive=True,74                    )75                with gr.Column():76                    ckpt_a = gr.Textbox(77                        label=i18n("Path to Model A:"),78                        value="",79                        interactive=True,80                        placeholder=i18n("Path to model"),81                    )82                    ckpt_b = gr.Textbox(83                        label=i18n("Path to Model B:"),84                        value="",85                        interactive=True,86                        placeholder=i18n("Path to model"),87                    )88                    info__ = gr.Textbox(89                        label=i18n("Model information to be placed:"),90                        value="",91                        max_lines=8,92                        interactive=True,93                        placeholder=i18n("Model information to be placed"),94                    )95                    info4 = gr.Textbox(96                        label=i18n("Output information:"), value="", max_lines=897                    )98 99            but6 = gr.Button(i18n("Fusion"), variant="primary")100 101            but6.click(102                merge,103                [104                    ckpt_a,105                    ckpt_b,106                    alpha_a,107                    sr_,108                    if_f0_,109                    info__,110                    name_to_save0,111                    version_2,112                ],113                info4,114                api_name="ckpt_merge",115            )  # def merge(path1,path2,alpha1,sr,f0,info):116 117        with gr.Accordion(label=i18n("Modify model information")):118            with gr.Row():  ######119                with gr.Column():120                    ckpt_path0 = gr.Textbox(121                        label=i18n("Path to Model:"),122                        value="",123                        interactive=True,124                        placeholder=i18n("Path to model"),125                    )126                    info_ = gr.Textbox(127                        label=i18n("Model information to be modified:"),128                        value="",129                        max_lines=8,130                        interactive=True,131                        placeholder=i18n("Model information to be placed"),132                    )133 134                with gr.Column():135                    name_to_save1 = gr.Textbox(136                        label=i18n("Save file name:"),137                        placeholder=i18n("Name for saving"),138                        value="",139                        max_lines=8,140                        interactive=True,141                    )142 143                    info5 = gr.Textbox(144                        label=i18n("Output information:"), value="", max_lines=8145                    )146            but7 = gr.Button(i18n("Modify"), variant="primary")147            but7.click(change_info, [ckpt_path0, info_, name_to_save1], info5, api_name="ckpt_modify",)148 149        with gr.Accordion(label=i18n("View model information")):150            with gr.Row():151                with gr.Column():152                    ckpt_path1 = gr.Textbox(153                        label=i18n("Path to Model:"),154                        value="",155                        interactive=True,156                        placeholder=i18n("Path to model"),157                    )158 159                    info6 = gr.Textbox(160                        label=i18n("Output information:"), value="", max_lines=8161                    )162                    but8 = gr.Button(i18n("View"), variant="primary")163            but8.click(show_info, [ckpt_path1], info6, api_name="ckpt_show")164 165        with gr.Accordion(label=i18n("Model extraction")):166            with gr.Row():167                with gr.Column():168                    save_name = gr.Textbox(169                        label=i18n("Name:"),170                        value="",171                        interactive=True,172                        placeholder=i18n("Name for saving"),173                    )174                    if_f0__ = gr.Checkbox(175                        label=i18n("Whether the model has pitch guidance."),176                        value=True,177                        interactive=True,178                    )179                    version_1 = gr.Radio(180                        label=i18n("Model architecture version:"),181                        choices=["v1", "v2"],182                        value="v2",183                        interactive=True,184                    )185                    sr__ = gr.Radio(186                        label=i18n("Target sample rate:"),187                        choices=["32k", "40k", "48k"],188                        value="40k",189                        interactive=True,190                    )191 192                with gr.Column():193                    ckpt_path2 = gr.Textbox(194                        label=i18n("Path to Model:"),195                        placeholder=i18n("Path to model"),196                        interactive=True,197                    )198                    info___ = gr.Textbox(199                        label=i18n("Model information to be placed:"),200                        value="",201                        max_lines=8,202                        interactive=True,203                        placeholder=i18n("Model information to be placed"),204                    )205                    info7 = gr.Textbox(206                        label=i18n("Output information:"), value="", max_lines=8207                    )208 209            with gr.Row():210                but9 = gr.Button(i18n("Extract"), variant="primary")211                ckpt_path2.change(212                    change_info_, [ckpt_path2], [sr__, if_f0__, version_1]213                )214            but9.click(215                extract_small_model,216                [ckpt_path2, save_name, sr__, if_f0__, info___, version_1],217                info7,218                api_name="ckpt_extract",219            )220