oddsilk commited on
Commit Β·
1bb3517
1
Parent(s): 16cd3c7
delete block border
Browse files
web_ui.py
CHANGED
|
@@ -8,6 +8,7 @@ import numpy as np
|
|
| 8 |
import librosa
|
| 9 |
import soundfile as sf
|
| 10 |
import plotly.graph_objects as go
|
|
|
|
| 11 |
|
| 12 |
from auto_mapper import run_pipeline
|
| 13 |
|
|
@@ -22,7 +23,7 @@ def get_cached_songs():
|
|
| 22 |
songs.append(f)
|
| 23 |
return sorted(songs)
|
| 24 |
|
| 25 |
-
def generate_validation_data(audio_path, onsets, out_dir):
|
| 26 |
"""
|
| 27 |
λΆμλ Onset λ°μ΄ν°λ₯Ό λ°νμΌλ‘ ν±(Click) μ¬μ΄λλ₯Ό μΆκ°ν κ²μ¦μ© μ€λμ€ νμΌκ³Ό,
|
| 28 |
Waveform & Piano Roll λκΈ°ν μκ°ν Plotly Figureλ₯Ό μμ±ν©λλ€.
|
|
@@ -50,45 +51,82 @@ def generate_validation_data(audio_path, onsets, out_dir):
|
|
| 50 |
y_down = y[::down_factor]
|
| 51 |
time_axis = np.linspace(0, len(y)/sr, len(y_down))
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
# νν
|
| 56 |
fig.add_trace(go.Scatter(
|
| 57 |
x=time_axis,
|
| 58 |
y=y_down,
|
| 59 |
mode='lines',
|
| 60 |
-
name="μ€λμ€
|
| 61 |
-
line=dict(color='
|
| 62 |
hoverinfo='none'
|
| 63 |
-
))
|
| 64 |
|
| 65 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
fig.add_trace(go.Scatter(
|
| 67 |
-
x=
|
| 68 |
-
y=
|
| 69 |
-
mode='
|
| 70 |
-
name="MIDI
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
fig.update_layout(
|
| 81 |
-
title=dict(text="<b>
|
| 82 |
-
xaxis=dict(title="μκ° (μ΄)", color="#e9ecef", showgrid=True, gridcolor='rgba(255,255,255,0.1)'),
|
| 83 |
-
yaxis=dict(title="μ§ν", color="#e9ecef", showgrid=True, gridcolor='rgba(255,255,255,0.1)', range=[-1.1, 1.1]),
|
| 84 |
template='plotly_dark',
|
| 85 |
-
height=
|
| 86 |
margin=dict(l=40, r=20, t=50, b=40),
|
| 87 |
paper_bgcolor='rgba(0,0,0,0)',
|
| 88 |
-
plot_bgcolor='rgba(
|
| 89 |
-
|
| 90 |
)
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
return mixed_path, fig
|
| 93 |
|
| 94 |
def process_audio(input_mode, audio_upload, audio_cached, bpm, target_stem, mode, quantize_strength, offset, shift, threshold_multiplier, min_votes, tolerance_ms, sr):
|
|
@@ -132,7 +170,7 @@ def process_audio(input_mode, audio_upload, audio_cached, bpm, target_stem, mode
|
|
| 132 |
shift=float(shift)
|
| 133 |
)
|
| 134 |
if os.path.exists(out_path):
|
| 135 |
-
mixed_path, fig = generate_validation_data(audio_path_to_use, onsets, out_dir)
|
| 136 |
return out_path, mixed_path, fig
|
| 137 |
else:
|
| 138 |
raise gr.Error("MIDI νμΌ μμ±μ μ€ν¨νμ΅λλ€. (μΆλ ₯ νμΌ μμ)")
|
|
@@ -173,7 +211,7 @@ h1 {
|
|
| 173 |
box-shadow: 0 10px 20px rgba(67, 97, 238, 0.3) !important;
|
| 174 |
}
|
| 175 |
/* λΆνμν ν
λ리 μ κ±° */
|
| 176 |
-
.gr-box, .gr-block, .gr-form, .gr-panel, fieldset {
|
| 177 |
border-color: transparent !important;
|
| 178 |
border: none !important;
|
| 179 |
box-shadow: none !important;
|
|
@@ -186,8 +224,13 @@ custom_theme = gr.themes.Soft(
|
|
| 186 |
secondary_hue="slate"
|
| 187 |
).set(
|
| 188 |
block_border_width="0px",
|
|
|
|
| 189 |
panel_border_width="0px",
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
)
|
| 192 |
|
| 193 |
with gr.Blocks(theme=custom_theme, css=custom_css) as app:
|
|
|
|
| 8 |
import librosa
|
| 9 |
import soundfile as sf
|
| 10 |
import plotly.graph_objects as go
|
| 11 |
+
from plotly.subplots import make_subplots
|
| 12 |
|
| 13 |
from auto_mapper import run_pipeline
|
| 14 |
|
|
|
|
| 23 |
songs.append(f)
|
| 24 |
return sorted(songs)
|
| 25 |
|
| 26 |
+
def generate_validation_data(audio_path, onsets, out_dir, bpm, offset=0.0):
|
| 27 |
"""
|
| 28 |
λΆμλ Onset λ°μ΄ν°λ₯Ό λ°νμΌλ‘ ν±(Click) μ¬μ΄λλ₯Ό μΆκ°ν κ²μ¦μ© μ€λμ€ νμΌκ³Ό,
|
| 29 |
Waveform & Piano Roll λκΈ°ν μκ°ν Plotly Figureλ₯Ό μμ±ν©λλ€.
|
|
|
|
| 51 |
y_down = y[::down_factor]
|
| 52 |
time_axis = np.linspace(0, len(y)/sr, len(y_down))
|
| 53 |
|
| 54 |
+
# Ableton Live μ€νμΌλ‘ μλ¨: μ€λμ€, νλ¨: λ―Έλμ λ
립λ νΈλ μμ±
|
| 55 |
+
fig = make_subplots(
|
| 56 |
+
rows=2, cols=1,
|
| 57 |
+
shared_xaxes=True,
|
| 58 |
+
vertical_spacing=0.03,
|
| 59 |
+
row_heights=[0.5, 0.5]
|
| 60 |
+
)
|
| 61 |
|
| 62 |
+
# [Track 1] μ€λμ€ νν (μμ΄λΈν€ λλμ λ°μ μ΄λ‘μ)
|
| 63 |
fig.add_trace(go.Scatter(
|
| 64 |
x=time_axis,
|
| 65 |
y=y_down,
|
| 66 |
mode='lines',
|
| 67 |
+
name="μ€λμ€ μλ³Έ",
|
| 68 |
+
line=dict(color='#00ff88', width=1),
|
| 69 |
hoverinfo='none'
|
| 70 |
+
), row=1, col=1)
|
| 71 |
|
| 72 |
+
# [Track 2] MIDI νΌμλ
Έ λ‘€ (μμ΄λΈν€ λλμ νλμ λΈλ‘ νν)
|
| 73 |
+
x_midi = []
|
| 74 |
+
y_midi = []
|
| 75 |
+
# Plotlyμμ λμ΄μ§λ μ (λΈλ‘)μ 그리기 μν΄ Noneμ μ€κ°μ μ½μ
|
| 76 |
+
for t, p in onsets:
|
| 77 |
+
x_midi.extend([t, t + 0.08, None]) # κ° λ
ΈνΈμ μκ°μ κΈΈμ΄λ₯Ό 0.08μ΄λ‘ νν
|
| 78 |
+
y_midi.extend([p, p, None])
|
| 79 |
+
|
| 80 |
fig.add_trace(go.Scatter(
|
| 81 |
+
x=x_midi,
|
| 82 |
+
y=y_midi,
|
| 83 |
+
mode='lines',
|
| 84 |
+
name="MIDI ν격 μ§μ ",
|
| 85 |
+
line=dict(color='#3399ff', width=16),
|
| 86 |
+
hovertemplate='μκ°: %{x:.3f}μ΄<br>νΌμΉ: %{y}<extra></extra>'
|
| 87 |
+
), row=2, col=1)
|
| 88 |
+
|
| 89 |
+
# λ μ΄μμ μ΄κΈ°ν λ° λμμΈ
|
| 90 |
+
min_pitch = min([p for _, p in onsets]) if onsets else 60
|
| 91 |
+
max_pitch = max([p for _, p in onsets]) if onsets else 64
|
| 92 |
+
|
| 93 |
+
total_time = len(y) / sr
|
| 94 |
+
beat_duration = 60.0 / bpm
|
| 95 |
+
measure_duration = beat_duration * 4.0 # 4/4 λ°μ κΈ°μ€
|
| 96 |
|
| 97 |
fig.update_layout(
|
| 98 |
+
title=dict(text=f"<b>Ableton Live μ€νμΌ λ€μ€ νΈλ λκΈ°ν λ·° (BPM: {bpm})</b>", font=dict(color="#e9ecef")),
|
|
|
|
|
|
|
| 99 |
template='plotly_dark',
|
| 100 |
+
height=450,
|
| 101 |
margin=dict(l=40, r=20, t=50, b=40),
|
| 102 |
paper_bgcolor='rgba(0,0,0,0)',
|
| 103 |
+
plot_bgcolor='rgba(255,255,255,0.03)',
|
| 104 |
+
showlegend=False
|
| 105 |
)
|
| 106 |
|
| 107 |
+
# X/YμΆ λμμΈ μ‘°μ : λ°μ(Beat) λ¨μλ‘ μΌλ° 그리λ νμ
|
| 108 |
+
fig.update_xaxes(
|
| 109 |
+
showgrid=True, gridcolor='rgba(255,255,255,0.1)', gridwidth=1,
|
| 110 |
+
tickmode='linear', tick0=offset, dtick=beat_duration,
|
| 111 |
+
title="μκ° (μ΄)", row=2, col=1
|
| 112 |
+
)
|
| 113 |
+
fig.update_xaxes(
|
| 114 |
+
showgrid=True, gridcolor='rgba(255,255,255,0.1)', gridwidth=1,
|
| 115 |
+
tickmode='linear', tick0=offset, dtick=beat_duration,
|
| 116 |
+
row=1, col=1
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
# λ§λ(Measure) μμμ λ§λ€ κ΅΅μ μΈλ‘μ μΆκ° (μμλ νΈλ μ 체 κ΄ν΅)
|
| 120 |
+
measure_time = offset
|
| 121 |
+
while measure_time <= total_time:
|
| 122 |
+
fig.add_vline(x=measure_time, line_width=2, line_color='rgba(255, 255, 255, 0.5)')
|
| 123 |
+
measure_time += measure_duration
|
| 124 |
+
|
| 125 |
+
# μ€λμ€ νΈλ YμΆ λμμΈ
|
| 126 |
+
fig.update_yaxes(showgrid=False, showticklabels=False, range=[-1.1, 1.1], row=1, col=1)
|
| 127 |
+
# MIDI νΈλ YμΆ λμμΈ (ν΄λΉνλ νΌμΉλ§ 보μ΄λλ‘)
|
| 128 |
+
fig.update_yaxes(showgrid=True, gridcolor='rgba(255,255,255,0.1)', title="νΌμΉ", range=[min_pitch - 2, max_pitch + 2], row=2, col=1)
|
| 129 |
+
|
| 130 |
return mixed_path, fig
|
| 131 |
|
| 132 |
def process_audio(input_mode, audio_upload, audio_cached, bpm, target_stem, mode, quantize_strength, offset, shift, threshold_multiplier, min_votes, tolerance_ms, sr):
|
|
|
|
| 170 |
shift=float(shift)
|
| 171 |
)
|
| 172 |
if os.path.exists(out_path):
|
| 173 |
+
mixed_path, fig = generate_validation_data(audio_path_to_use, onsets, out_dir, float(bpm), float(offset))
|
| 174 |
return out_path, mixed_path, fig
|
| 175 |
else:
|
| 176 |
raise gr.Error("MIDI νμΌ μμ±μ μ€ν¨νμ΅λλ€. (μΆλ ₯ νμΌ μμ)")
|
|
|
|
| 211 |
box-shadow: 0 10px 20px rgba(67, 97, 238, 0.3) !important;
|
| 212 |
}
|
| 213 |
/* λΆνμν ν
λ리 μ κ±° */
|
| 214 |
+
.gr-box, .gr-block, .gr-form, .gr-panel, fieldset, .block, .group {
|
| 215 |
border-color: transparent !important;
|
| 216 |
border: none !important;
|
| 217 |
box-shadow: none !important;
|
|
|
|
| 224 |
secondary_hue="slate"
|
| 225 |
).set(
|
| 226 |
block_border_width="0px",
|
| 227 |
+
block_border_width_dark="0px",
|
| 228 |
panel_border_width="0px",
|
| 229 |
+
panel_border_width_dark="0px",
|
| 230 |
+
block_border_color="transparent",
|
| 231 |
+
block_border_color_dark="transparent",
|
| 232 |
+
border_color_primary="transparent",
|
| 233 |
+
border_color_primary_dark="transparent"
|
| 234 |
)
|
| 235 |
|
| 236 |
with gr.Blocks(theme=custom_theme, css=custom_css) as app:
|