File size: 1,662 Bytes
38548f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import gradio as gr
from infer.modules.train.extract.extract_f0_rmvpe import FeatureInput
from infer.modules.train.extract_feature_print import HubertFeatureExtractor
from zero import zero


@zero(duration=300)
def extract_features(exp_dir: str) -> str:
    err = None
    fi = FeatureInput(exp_dir)
    try:
        fi.run()
    except Exception as e:
        err = e

    fi.logfile.seek(0)
    log = fi.logfile.read()

    if err:
        log = f"Error: {err}\n{log}"
        return log

    hfe = HubertFeatureExtractor(exp_dir)
    try:
        hfe.run()
    except Exception as e:
        err = e

    hfe.logfile.seek(0)
    log += hfe.logfile.read()

    if err:
        log = f"Error: {err}\n{log}"

    return log


class FeatureExtractionTab:
    def __init__(self):
        pass

    def ui(self):
        gr.Markdown("# Feature Extraction")
        gr.Markdown(
            "Before training, you need to extract features from the audio files. "
            "This process may take a while, depending on the number of audio files. "
            "Under the hood, this process extracts speech features using HuBERT and extracts F0 by RMVPE."
        )

        with gr.Row():
            self.extract_features_btn = gr.Button(
                value="Extract features", variant="primary"
            )
        with gr.Row():
            self.extract_features_log = gr.Textbox(
                label="Feature extraction log", lines=10
            )

    def build(self, exp_dir: gr.Textbox):
        self.extract_features_btn.click(
            fn=extract_features,
            inputs=[exp_dir],
            outputs=[self.extract_features_log],
        )