Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -87,202 +87,130 @@ def low_pass_filter(audio_path, cutoff_freq):
|
|
87 |
def clear_output():
|
88 |
return None
|
89 |
|
90 |
-
# Словарь с переводами
|
91 |
-
translations = {
|
92 |
-
"en": {
|
93 |
-
"title": "Audio Editor",
|
94 |
-
"examples_label": "Audio Examples",
|
95 |
-
"select_example": "Select an example audio",
|
96 |
-
"volume_tab": "Change Volume",
|
97 |
-
"volume_label": "Volume Change (dB)",
|
98 |
-
"speed_tab": "Change Speed",
|
99 |
-
"speed_label": "Speed Factor",
|
100 |
-
"pitch_tab": "Change Pitch",
|
101 |
-
"pitch_label": "Pitch Change (semitones)",
|
102 |
-
"trim_tab": "Trim Audio",
|
103 |
-
"start_time_label": "Start Time (sec)",
|
104 |
-
"end_time_label": "End Time (sec)",
|
105 |
-
"echo_tab": "Add Echo",
|
106 |
-
"echo_delay_label": "Echo Delay (sec)",
|
107 |
-
"echo_decay_label": "Echo Decay",
|
108 |
-
"reverse_tab": "Reverse Audio",
|
109 |
-
"normalize_tab": "Normalize Audio",
|
110 |
-
"noise_tab": "Add Background Noise",
|
111 |
-
"noise_label": "Noise Level (dB)",
|
112 |
-
"filter_tab": "Low Pass Filter",
|
113 |
-
"cutoff_label": "Cutoff Frequency (Hz)",
|
114 |
-
"apply_button": "Apply",
|
115 |
-
"clear_button": "Clear Results",
|
116 |
-
"output_label": "Output Audio"
|
117 |
-
},
|
118 |
-
"ru": {
|
119 |
-
"title": "Аудио-редактор",
|
120 |
-
"examples_label": "Примеры аудио",
|
121 |
-
"select_example": "Выберите пример аудио",
|
122 |
-
"volume_tab": "Изменение громкости",
|
123 |
-
"volume_label": "Изменение громкости (dB)",
|
124 |
-
"speed_tab": "Изменение скорости",
|
125 |
-
"speed_label": "Фактор скорости",
|
126 |
-
"pitch_tab": "Изменение высоты тона",
|
127 |
-
"pitch_label": "Изменение высоты тона (полутоны)",
|
128 |
-
"trim_tab": "Обрезка аудио",
|
129 |
-
"start_time_label": "Начальное время обрезки (сек)",
|
130 |
-
"end_time_label": "Конечное время обрезки (сек)",
|
131 |
-
"echo_tab": "Добавление эха",
|
132 |
-
"echo_delay_label": "Задержка эха (сек)",
|
133 |
-
"echo_decay_label": "Затухание эха",
|
134 |
-
"reverse_tab": "Реверс аудио",
|
135 |
-
"normalize_tab": "Нормализация аудио",
|
136 |
-
"noise_tab": "Добавление фонового шума",
|
137 |
-
"noise_label": "Уровень шума (dB)",
|
138 |
-
"filter_tab": "Фильтр низких частот",
|
139 |
-
"cutoff_label": "Частота среза (Гц)",
|
140 |
-
"apply_button": "Применить",
|
141 |
-
"clear_button": "Очистить результаты",
|
142 |
-
"output_label": "Выходное аудио"
|
143 |
-
},
|
144 |
-
"es": {
|
145 |
-
"title": "Editor de Audio",
|
146 |
-
"examples_label": "Ejemplos de Audio",
|
147 |
-
"select_example": "Selecciona un ejemplo de audio",
|
148 |
-
"volume_tab": "Cambiar Volumen",
|
149 |
-
"volume_label": "Cambio de Volumen (dB)",
|
150 |
-
"speed_tab": "Cambiar Velocidad",
|
151 |
-
"speed_label": "Factor de Velocidad",
|
152 |
-
"pitch_tab": "Cambiar Tono",
|
153 |
-
"pitch_label": "Cambio de Tono (semitones)",
|
154 |
-
"trim_tab": "Recortar Audio",
|
155 |
-
"start_time_label": "Tiempo de Inicio (seg)",
|
156 |
-
"end_time_label": "Tiempo de Fin (seg)",
|
157 |
-
"echo_tab": "Añadir Eco",
|
158 |
-
"echo_delay_label": "Retardo del Eco (seg)",
|
159 |
-
"echo_decay_label": "Decaimiento del Eco",
|
160 |
-
"reverse_tab": "Invertir Audio",
|
161 |
-
"normalize_tab": "Normalizar Audio",
|
162 |
-
"noise_tab": "Añadir Ruido de Fondo",
|
163 |
-
"noise_label": "Nivel de Ruido (dB)",
|
164 |
-
"filter_tab": "Filtro de Paso Bajo",
|
165 |
-
"cutoff_label": "Frecuencia de Corte (Hz)",
|
166 |
-
"apply_button": "Aplicar",
|
167 |
-
"clear_button": "Limpiar Resultados",
|
168 |
-
"output_label": "Audio de Salida"
|
169 |
-
},
|
170 |
-
"zh": {
|
171 |
-
"title": "音频编辑器",
|
172 |
-
"examples_label": "音频示例",
|
173 |
-
"select_example": "选择一个示例音频",
|
174 |
-
"volume_tab": "改变音量",
|
175 |
-
"volume_label": "音量变化 (dB)",
|
176 |
-
"speed_tab": "改变速度",
|
177 |
-
"speed_label": "速度因子",
|
178 |
-
"pitch_tab": "改变音高",
|
179 |
-
"pitch_label": "音高变化 (半音)",
|
180 |
-
"trim_tab": "裁剪音频",
|
181 |
-
"start_time_label": "开始时间 (秒)",
|
182 |
-
"end_time_label": "结束时间 (秒)",
|
183 |
-
"echo_tab": "添加回声",
|
184 |
-
"echo_delay_label": "回声延迟 (秒)",
|
185 |
-
"echo_decay_label": "回声衰减",
|
186 |
-
"reverse_tab": "反转音频",
|
187 |
-
"normalize_tab": "标准化音频",
|
188 |
-
"noise_tab": "添加背景噪音",
|
189 |
-
"noise_label": "噪音水平 (dB)",
|
190 |
-
"filter_tab": "低通滤波器",
|
191 |
-
"cutoff_label": "截止频率 (Hz)",
|
192 |
-
"apply_button": "应用",
|
193 |
-
"clear_button": "清除结果",
|
194 |
-
"output_label": "输出音频"
|
195 |
-
}
|
196 |
-
}
|
197 |
-
|
198 |
-
# Функция для обновления интерфейса в зависимости от выбранного языка
|
199 |
-
def update_interface(lang):
|
200 |
-
return (
|
201 |
-
translations[lang]["title"],
|
202 |
-
translations[lang]["examples_label"],
|
203 |
-
translations[lang]["select_example"],
|
204 |
-
translations[lang]["volume_tab"],
|
205 |
-
translations[lang]["volume_label"],
|
206 |
-
translations[lang]["speed_tab"],
|
207 |
-
translations[lang]["speed_label"],
|
208 |
-
translations[lang]["pitch_tab"],
|
209 |
-
translations[lang]["pitch_label"],
|
210 |
-
translations[lang]["trim_tab"],
|
211 |
-
translations[lang]["start_time_label"],
|
212 |
-
translations[lang]["end_time_label"],
|
213 |
-
translations[lang]["echo_tab"],
|
214 |
-
translations[lang]["echo_delay_label"],
|
215 |
-
translations[lang]["echo_decay_label"],
|
216 |
-
translations[lang]["reverse_tab"],
|
217 |
-
translations[lang]["normalize_tab"],
|
218 |
-
translations[lang]["noise_tab"],
|
219 |
-
translations[lang]["noise_label"],
|
220 |
-
translations[lang]["filter_tab"],
|
221 |
-
translations[lang]["cutoff_label"],
|
222 |
-
translations[lang]["apply_button"],
|
223 |
-
translations[lang]["clear_button"],
|
224 |
-
translations[lang]["output_label"]
|
225 |
-
)
|
226 |
-
|
227 |
# Создание интерфейса Gradio с вкладками
|
228 |
with gr.Blocks() as interface:
|
229 |
-
|
230 |
-
lang = gr.Dropdown(choices=["en", "ru", "es", "zh"], label="选择语言 / Select Language", value="zh")
|
231 |
|
232 |
# Общий блок для примеров аудио
|
233 |
with gr.Row():
|
234 |
-
|
235 |
examples = gr.Examples(
|
236 |
examples=[
|
237 |
["https://huggingface.co/spaces/Felguk/Felguk-audio-edit/resolve/main/Varilla%20%26%20DJ%20Elnica%20-%20This%20Is%20How%20We%20Do%20It%20(Original%20Mix).mp3"],
|
238 |
["https://huggingface.co/spaces/Felguk/Felguk-audio-edit/resolve/main/LowRaise%20%E2%80%94%20Shake%20The%20Ground%20(www.hotplayer.ru).mp3"]
|
239 |
],
|
240 |
-
inputs=[gr.Audio(type="filepath", label="
|
241 |
-
label=
|
242 |
)
|
243 |
|
244 |
# Вкладки с инструментами
|
245 |
with gr.Tabs():
|
246 |
# Вкладка 1: Изменение громкости
|
247 |
-
with gr.Tab(
|
248 |
with gr.Column():
|
249 |
-
audio_input_1 = gr.Audio(type="filepath", label="
|
250 |
-
volume_change = gr.Slider(minimum=-20, maximum=20, step=1, label="
|
251 |
-
output_1 = gr.Audio(type="filepath", label="
|
252 |
with gr.Row():
|
253 |
-
apply_button_1 = gr.Button("
|
254 |
-
clear_button_1 = gr.Button("
|
255 |
apply_button_1.click(change_volume, inputs=[audio_input_1, volume_change], outputs=output_1)
|
256 |
clear_button_1.click(clear_output, inputs=None, outputs=output_1)
|
257 |
|
258 |
# Вкладка 2: Изменение скорости
|
259 |
-
with gr.Tab(
|
260 |
with gr.Column():
|
261 |
-
audio_input_2 = gr.Audio(type="filepath", label="
|
262 |
-
speed_factor = gr.Slider(minimum=0.5, maximum=2.0, step=0.1, label="
|
263 |
-
output_2 = gr.Audio(type="filepath", label="
|
264 |
with gr.Row():
|
265 |
-
apply_button_2 = gr.Button("
|
266 |
-
clear_button_2 = gr.Button("
|
267 |
apply_button_2.click(change_speed, inputs=[audio_input_2, speed_factor], outputs=output_2)
|
268 |
clear_button_2.click(clear_output, inputs=None, outputs=output_2)
|
269 |
|
270 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
interface.launch()
|
|
|
87 |
def clear_output():
|
88 |
return None
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
# Создание интерфейса Gradio с вкладками
|
91 |
with gr.Blocks() as interface:
|
92 |
+
gr.Markdown("## Аудио-редактор (Audio Editor / 音频编辑器)")
|
|
|
93 |
|
94 |
# Общий блок для примеров аудио
|
95 |
with gr.Row():
|
96 |
+
gr.Markdown("### Примеры аудио (Audio Examples / 音频示例)")
|
97 |
examples = gr.Examples(
|
98 |
examples=[
|
99 |
["https://huggingface.co/spaces/Felguk/Felguk-audio-edit/resolve/main/Varilla%20%26%20DJ%20Elnica%20-%20This%20Is%20How%20We%20Do%20It%20(Original%20Mix).mp3"],
|
100 |
["https://huggingface.co/spaces/Felguk/Felguk-audio-edit/resolve/main/LowRaise%20%E2%80%94%20Shake%20The%20Ground%20(www.hotplayer.ru).mp3"]
|
101 |
],
|
102 |
+
inputs=[gr.Audio(type="filepath", label="Выберите пример аудио (Select an example audio / 选择一个示例音频)")],
|
103 |
+
label="Примеры аудио (Audio Examples / 音频示例)"
|
104 |
)
|
105 |
|
106 |
# Вкладки с инструментами
|
107 |
with gr.Tabs():
|
108 |
# Вкладка 1: Изменение громкости
|
109 |
+
with gr.Tab("Изменение громкости (Change Volume / 改变音量)"):
|
110 |
with gr.Column():
|
111 |
+
audio_input_1 = gr.Audio(type="filepath", label="Входное аудио (Input Audio / 输入音频)")
|
112 |
+
volume_change = gr.Slider(minimum=-20, maximum=20, step=1, label="Изменение громкости (dB) (Volume Change (dB) / 音量变化 (dB))")
|
113 |
+
output_1 = gr.Audio(type="filepath", label="Выходное аудио (Output Audio / 输出音频)")
|
114 |
with gr.Row():
|
115 |
+
apply_button_1 = gr.Button("Применить (Apply / 应用)")
|
116 |
+
clear_button_1 = gr.Button("Очистить результаты (Clear Results / 清除结果)")
|
117 |
apply_button_1.click(change_volume, inputs=[audio_input_1, volume_change], outputs=output_1)
|
118 |
clear_button_1.click(clear_output, inputs=None, outputs=output_1)
|
119 |
|
120 |
# Вкладка 2: Изменение скорости
|
121 |
+
with gr.Tab("Изменение скорости (Change Speed / 改变速度)"):
|
122 |
with gr.Column():
|
123 |
+
audio_input_2 = gr.Audio(type="filepath", label="Входное аудио (Input Audio / 输入音频)")
|
124 |
+
speed_factor = gr.Slider(minimum=0.5, maximum=2.0, step=0.1, label="Фактор скорости (Speed Factor / 速度因子)")
|
125 |
+
output_2 = gr.Audio(type="filepath", label="Выходное аудио (Output Audio / 输出音频)")
|
126 |
with gr.Row():
|
127 |
+
apply_button_2 = gr.Button("Применить (Apply / 应用)")
|
128 |
+
clear_button_2 = gr.Button("Очистить результаты (Clear Results / 清除结果)")
|
129 |
apply_button_2.click(change_speed, inputs=[audio_input_2, speed_factor], outputs=output_2)
|
130 |
clear_button_2.click(clear_output, inputs=None, outputs=output_2)
|
131 |
|
132 |
+
# Вкладка 3: Изменение высоты тона
|
133 |
+
with gr.Tab("Изменение высоты тона (Change Pitch / 改变音高)"):
|
134 |
+
with gr.Column():
|
135 |
+
audio_input_3 = gr.Audio(type="filepath", label="Входное аудио (Input Audio / 输入音频)")
|
136 |
+
pitch_change = gr.Slider(minimum=-5, maximum=5, step=1, label="Изменение высоты тона (полутоны) (Pitch Change (semitones) / 音高变化 (半音))")
|
137 |
+
output_3 = gr.Audio(type="filepath", label="Выходное аудио (Output Audio / 输出音频)")
|
138 |
+
with gr.Row():
|
139 |
+
apply_button_3 = gr.Button("Применить (Apply / 应用)")
|
140 |
+
clear_button_3 = gr.Button("Очистить результаты (Clear Results / 清除结果)")
|
141 |
+
apply_button_3.click(change_pitch, inputs=[audio_input_3, pitch_change], outputs=output_3)
|
142 |
+
clear_button_3.click(clear_output, inputs=None, outputs=output_3)
|
143 |
|
144 |
+
# Вкладка 4: Обрезка аудио
|
145 |
+
with gr.Tab("Обрезка аудио (Trim Audio / 裁剪音频)"):
|
146 |
+
with gr.Column():
|
147 |
+
audio_input_4 = gr.Audio(type="filepath", label="Входное аудио (Input Audio / 输入音频)")
|
148 |
+
start_time = gr.Slider(minimum=0, maximum=60, step=1, label="Начальное время обрезки (сек) (Start Time (sec) / 开始时间 (秒))")
|
149 |
+
end_time = gr.Slider(minimum=0, maximum=60, step=1, label="Конечное время обрезки (сек) (End Time (sec) / 结束时间 (秒))")
|
150 |
+
output_4 = gr.Audio(type="filepath", label="Выходное аудио (Output Audio / 输出音频)")
|
151 |
+
with gr.Row():
|
152 |
+
apply_button_4 = gr.Button("Применить (Apply / 应用)")
|
153 |
+
clear_button_4 = gr.Button("Очистить результаты (Clear Results / 清除结果)")
|
154 |
+
apply_button_4.click(trim_audio, inputs=[audio_input_4, start_time, end_time], outputs=output_4)
|
155 |
+
clear_button_4.click(clear_output, inputs=None, outputs=output_4)
|
156 |
+
|
157 |
+
# Вкладка 5: Добавление эха
|
158 |
+
with gr.Tab("Добавление эха (Add Echo / 添加回声)"):
|
159 |
+
with gr.Column():
|
160 |
+
audio_input_5 = gr.Audio(type="filepath", label="Входное аудио (Input Audio / 输入音频)")
|
161 |
+
echo_delay = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Задержка эха (сек) (Echo Delay (sec) / 回声延迟 (秒))")
|
162 |
+
echo_decay = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Затухание эха (Echo Decay / 回声衰减)")
|
163 |
+
output_5 = gr.Audio(type="filepath", label="Выходное аудио (Output Audio / 输出音频)")
|
164 |
+
with gr.Row():
|
165 |
+
apply_button_5 = gr.Button("Применить (Apply / 应用)")
|
166 |
+
clear_button_5 = gr.Button("Очистить результаты (Clear Results / 清除结果)")
|
167 |
+
apply_button_5.click(add_echo, inputs=[audio_input_5, echo_delay, echo_decay], outputs=output_5)
|
168 |
+
clear_button_5.click(clear_output, inputs=None, outputs=output_5)
|
169 |
+
|
170 |
+
# Вкладка 6: Реверс аудио
|
171 |
+
with gr.Tab("Реверс аудио (Reverse Audio / 反转音频)"):
|
172 |
+
with gr.Column():
|
173 |
+
audio_input_6 = gr.Audio(type="filepath", label="Входное аудио (Input Audio / 输入音频)")
|
174 |
+
output_6 = gr.Audio(type="filepath", label="Выходное аудио (Output Audio / 输出音频)")
|
175 |
+
with gr.Row():
|
176 |
+
apply_button_6 = gr.Button("Применить (Apply / 应用)")
|
177 |
+
clear_button_6 = gr.Button("Очистить результаты (Clear Results / 清除结果)")
|
178 |
+
apply_button_6.click(reverse_audio, inputs=audio_input_6, outputs=output_6)
|
179 |
+
clear_button_6.click(clear_output, inputs=None, outputs=output_6)
|
180 |
+
|
181 |
+
# Вкладка 7: Нормализация аудио
|
182 |
+
with gr.Tab("Нормализация аудио (Normalize Audio / 标准化音频)"):
|
183 |
+
with gr.Column():
|
184 |
+
audio_input_7 = gr.Audio(type="filepath", label="Входное аудио (Input Audio / 输入音频)")
|
185 |
+
output_7 = gr.Audio(type="filepath", label="Выходное аудио (Output Audio / 输出音频)")
|
186 |
+
with gr.Row():
|
187 |
+
apply_button_7 = gr.Button("Применить (Apply / 应用)")
|
188 |
+
clear_button_7 = gr.Button("Очистить результаты (Clear Results / 清除结果)")
|
189 |
+
apply_button_7.click(normalize_audio, inputs=audio_input_7, outputs=output_7)
|
190 |
+
clear_button_7.click(clear_output, inputs=None, outputs=output_7)
|
191 |
+
|
192 |
+
# Вкладка 8: Добавление фонового шума
|
193 |
+
with gr.Tab("Добавление фонового шума (Add Background Noise / 添加背景噪音)"):
|
194 |
+
with gr.Column():
|
195 |
+
audio_input_8 = gr.Audio(type="filepath", label="Входное аудио (Input Audio / 输入音频)")
|
196 |
+
noise_level = gr.Slider(minimum=-20, maximum=20, step=1, label="Уровень шума (dB) (Noise Level (dB) / 噪音水平 (dB))")
|
197 |
+
output_8 = gr.Audio(type="filepath", label="Выходное аудио (Output Audio / 输出音频)")
|
198 |
+
with gr.Row():
|
199 |
+
apply_button_8 = gr.Button("Применить (Apply / 应用)")
|
200 |
+
clear_button_8 = gr.Button("Очистить результаты (Clear Results / 清除结果)")
|
201 |
+
apply_button_8.click(add_background_noise, inputs=[audio_input_8, noise_level], outputs=output_8)
|
202 |
+
clear_button_8.click(clear_output, inputs=None, outputs=output_8)
|
203 |
+
|
204 |
+
# Вкладка 9: Фильтр низких частот
|
205 |
+
with gr.Tab("Фильтр низких частот (Low Pass Filter / 低通滤波器)"):
|
206 |
+
with gr.Column():
|
207 |
+
audio_input_9 = gr.Audio(type="filepath", label="Входное аудио (Input Audio / 输入音频)")
|
208 |
+
cutoff_freq = gr.Slider(minimum=100, maximum=1000, step=50, label="Частота среза (Гц) (Cutoff Frequency (Hz) / 截止频率 (Hz))")
|
209 |
+
output_9 = gr.Audio(type="filepath", label="Выходное аудио (Output Audio / 输出音频)")
|
210 |
+
with gr.Row():
|
211 |
+
apply_button_9 = gr.Button("Применить (Apply / 应用)")
|
212 |
+
clear_button_9 = gr.Button("Очистить результаты (Clear Results / 清除结果)")
|
213 |
+
apply_button_9.click(low_pass_filter, inputs=[audio_input_9, cutoff_freq], outputs=output_9)
|
214 |
+
clear_button_9.click(clear_output, inputs=None, outputs=output_9)
|
215 |
|
216 |
interface.launch()
|