nevreal commited on
Commit
745a860
1 Parent(s): e07bb32

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +194 -0
app.py ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from original import *
2
+ import shutil, glob
3
+ from easyfuncs import download_from_url, CachedModels
4
+ os.makedirs("dataset",exist_ok=True)
5
+ model_library = CachedModels()
6
+
7
+ with gr.Blocks(title="🔊",theme=gr.themes.Base(primary_hue="rose",neutral_hue="zinc")) as app:
8
+ with gr.Row():
9
+ gr.HTML("<img src='file/a.png' alt='image'>")
10
+ with gr.Tabs():
11
+ with gr.TabItem("Inference"):
12
+ with gr.Row():
13
+ voice_model = gr.Dropdown(label="Model Voice", choices=sorted(names), value=lambda:sorted(names)[0] if len(sorted(names)) > 0 else '', interactive=True)
14
+ refresh_button = gr.Button("Refresh", variant="primary")
15
+ spk_item = gr.Slider(
16
+ minimum=0,
17
+ maximum=2333,
18
+ step=1,
19
+ label="Speaker ID",
20
+ value=0,
21
+ visible=False,
22
+ interactive=True,
23
+ )
24
+ vc_transform0 = gr.Number(
25
+ label="Pitch",
26
+ value=0
27
+ )
28
+ but0 = gr.Button(value="Convert", variant="primary")
29
+ with gr.Row():
30
+ with gr.Column():
31
+ with gr.Row():
32
+ dropbox = gr.File(label="Drop your audio here & hit the Reload button.")
33
+ with gr.Row():
34
+ record_button=gr.Audio(source="microphone", label="OR Record audio.", type="filepath")
35
+ with gr.Row():
36
+ paths_for_files = lambda path:[os.path.abspath(os.path.join(path, f)) for f in os.listdir(path) if os.path.splitext(f)[1].lower() in ('.mp3', '.wav', '.flac', '.ogg')]
37
+ input_audio0 = gr.Dropdown(
38
+ label="Input Path",
39
+ value=paths_for_files('audios')[0] if len(paths_for_files('audios')) > 0 else '',
40
+ choices=paths_for_files('audios'), # Only show absolute paths for audio files ending in .mp3, .wav, .flac or .ogg
41
+ allow_custom_value=True
42
+ )
43
+ with gr.Row():
44
+ audio_player = gr.Audio()
45
+ input_audio0.change(
46
+ inputs=[input_audio0],
47
+ outputs=[audio_player],
48
+ fn=lambda path: {"value":path,"__type__":"update"} if os.path.exists(path) else None
49
+ )
50
+ record_button.stop_recording(
51
+ fn=lambda audio:audio, #TODO save wav lambda
52
+ inputs=[record_button],
53
+ outputs=[input_audio0])
54
+ dropbox.upload(
55
+ fn=lambda audio:audio.name,
56
+ inputs=[dropbox],
57
+ outputs=[input_audio0])
58
+ with gr.Column():
59
+ with gr.Accordion("Change Index", open=False):
60
+ file_index2 = gr.Dropdown(
61
+ label="Change Index",
62
+ choices=sorted(index_paths),
63
+ interactive=True,
64
+ value=sorted(index_paths)[0] if len(sorted(index_paths)) > 0 else ''
65
+ )
66
+ index_rate1 = gr.Slider(
67
+ minimum=0,
68
+ maximum=1,
69
+ label="Index Strength",
70
+ value=0.5,
71
+ interactive=True,
72
+ )
73
+ vc_output2 = gr.Audio(label="Output")
74
+ with gr.Accordion("General Settings", open=False):
75
+ f0method0 = gr.Radio(
76
+ label="Method",
77
+ choices=["pm", "harvest", "crepe", "rmvpe"]
78
+ if config.dml == False
79
+ else ["pm", "harvest", "rmvpe"],
80
+ value="rmvpe",
81
+ interactive=True,
82
+ )
83
+ filter_radius0 = gr.Slider(
84
+ minimum=0,
85
+ maximum=7,
86
+ label="Breathiness Reduction (Harvest only)",
87
+ value=3,
88
+ step=1,
89
+ interactive=True,
90
+ )
91
+ resample_sr0 = gr.Slider(
92
+ minimum=0,
93
+ maximum=48000,
94
+ label="Resample",
95
+ value=0,
96
+ step=1,
97
+ interactive=True,
98
+ visible=False
99
+ )
100
+ rms_mix_rate0 = gr.Slider(
101
+ minimum=0,
102
+ maximum=1,
103
+ label="Volume Normalization",
104
+ value=0,
105
+ interactive=True,
106
+ )
107
+ protect0 = gr.Slider(
108
+ minimum=0,
109
+ maximum=0.5,
110
+ label="Breathiness Protection (0 is enabled, 0.5 is disabled)",
111
+ value=0.33,
112
+ step=0.01,
113
+ interactive=True,
114
+ )
115
+ if voice_model != None: vc.get_vc(voice_model.value,protect0,protect0)
116
+ file_index1 = gr.Textbox(
117
+ label="Index Path",
118
+ interactive=True,
119
+ visible=False#Not used here
120
+ )
121
+ refresh_button.click(
122
+ fn=change_choices,
123
+ inputs=[],
124
+ outputs=[voice_model, file_index2],
125
+ api_name="infer_refresh",
126
+ )
127
+ refresh_button.click(
128
+ fn=lambda:{"choices":paths_for_files('audios'),"__type__":"update"}, #TODO check if properly returns a sorted list of audio files in the 'audios' folder that have the extensions '.wav', '.mp3', '.ogg', or '.flac'
129
+ inputs=[],
130
+ outputs = [input_audio0],
131
+ )
132
+ refresh_button.click(
133
+ fn=lambda:{"value":paths_for_files('audios')[0],"__type__":"update"} if len(paths_for_files('audios')) > 0 else {"value":"","__type__":"update"}, #TODO check if properly returns a sorted list of audio files in the 'audios' folder that have the extensions '.wav', '.mp3', '.ogg', or '.flac'
134
+ inputs=[],
135
+ outputs = [input_audio0],
136
+ )
137
+ with gr.Row():
138
+ f0_file = gr.File(label="F0 Path", visible=False)
139
+ with gr.Row():
140
+ vc_output1 = gr.Textbox(label="Information", placeholder="Welcome!",visible=False)
141
+ but0.click(
142
+ vc.vc_single,
143
+ [
144
+ spk_item,
145
+ input_audio0,
146
+ vc_transform0,
147
+ f0_file,
148
+ f0method0,
149
+ file_index1,
150
+ file_index2,
151
+ index_rate1,
152
+ filter_radius0,
153
+ resample_sr0,
154
+ rms_mix_rate0,
155
+ protect0,
156
+ ],
157
+ [vc_output1, vc_output2],
158
+ api_name="infer_convert",
159
+ )
160
+ voice_model.change(
161
+ fn=vc.get_vc,
162
+ inputs=[voice_model, protect0, protect0],
163
+ outputs=[spk_item, protect0, protect0, file_index2, file_index2],
164
+ api_name="infer_change_voice",
165
+ )
166
+ with gr.TabItem("Download Models"):
167
+ with gr.Row():
168
+ url_input = gr.Textbox(label="URL to model", value="",placeholder="https://...", scale=6)
169
+ name_output = gr.Textbox(label="Save as", value="",placeholder="MyModel",scale=2)
170
+ url_download = gr.Button(value="Download Model",scale=2)
171
+ url_download.click(
172
+ inputs=[url_input,name_output],
173
+ outputs=[url_input],
174
+ fn=download_from_url,
175
+ )
176
+ with gr.Row():
177
+ model_browser = gr.Dropdown(choices=list(model_library.models.keys()),label="OR Search Models (Quality UNKNOWN)",scale=5)
178
+ download_from_browser = gr.Button(value="Get",scale=2)
179
+ download_from_browser.click(
180
+ inputs=[model_browser],
181
+ outputs=[model_browser],
182
+ fn=lambda model: download_from_url(model_library.models[model],model),
183
+ )
184
+
185
+
186
+ if config.iscolab:
187
+ app.queue(concurrency_count=511, max_size=1022).launch(share=True)
188
+ else:
189
+ app.queue(concurrency_count=511, max_size=1022).launch(
190
+ server_name="0.0.0.0",
191
+ inbrowser=not config.noautoopen,
192
+ server_port=config.listen_port,
193
+ quiet=True,
194
+ )