Spaces:
Sleeping
Sleeping
import gradio as gr | |
from tempocnn.classifier import TempoClassifier | |
from tempocnn.feature import read_features | |
# Инициализируем модель один раз | |
model_name = 'cnn' | |
classifier = TempoClassifier(model_name) | |
def estimate_tempo(audio_file): | |
"""Функция для оценки темпа одного аудиофайла.""" | |
if not audio_file: | |
return "Ошибка: Файл не загружен!" | |
features = read_features(audio_file) | |
tempo = classifier.estimate_tempo(features, interpolate=True) | |
return f"Estimated global tempo: {tempo} BPM" | |
def compare_tempos(audio_file1, audio_file2): | |
"""Функция для оценки темпов двух файлов и вычисления их соотношения.""" | |
if not audio_file1 or not audio_file2: | |
return "Ошибка: Загрузите оба файла!" | |
features1 = read_features(audio_file1) | |
features2 = read_features(audio_file2) | |
tempo1 = classifier.estimate_tempo(features1, interpolate=True) | |
tempo2 = classifier.estimate_tempo(features2, interpolate=True) | |
ratio1 = tempo1 / tempo2 | |
ratio2 = tempo2 / tempo1 | |
return f"Tempo 1: {tempo1} BPM\nTempo 2: {tempo2} BPM\nRatio 1/2: {ratio1}\nRatio 2/1: {ratio2}" | |
# Создаем вкладки | |
tab1 = gr.Interface( | |
fn=estimate_tempo, | |
inputs=gr.Audio(type="filepath"), | |
outputs="text", | |
title="Single Audio Tempo Estimation", | |
description="Upload an audio file to estimate its tempo." | |
) | |
tab2 = gr.Interface( | |
fn=compare_tempos, | |
inputs=[gr.Audio(type="filepath"), gr.Audio(type="filepath")], | |
outputs="text", | |
title="Two Audio Files Tempo Comparison", | |
description="Upload two audio files to compare their tempos and calculate ratios." | |
) | |
# Запускаем Gradio с двумя вкладками | |
gr.TabbedInterface([tab1, tab2], ["Single File", "Compare Two Files"]).launch() | |