oddsilk commited on
Commit
1bb3517
Β·
1 Parent(s): 16cd3c7

delete block border

Browse files
Files changed (1) hide show
  1. web_ui.py +71 -28
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
- fig = go.Figure()
 
 
 
 
 
 
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='rgba(67, 97, 238, 0.6)', width=1.5),
62
  hoverinfo='none'
63
- ))
64
 
65
- # Onset μœ„μΉ˜ 마컀 μΆ”κ°€ (빨간색 μˆ˜μ§μ„  λͺ¨μ‚¬ λ§‰λŒ€)
 
 
 
 
 
 
 
66
  fig.add_trace(go.Scatter(
67
- x=times,
68
- y=[0] * len(times),
69
- mode='markers',
70
- name="MIDI λ…ΈνŠΈ (타격 지점)",
71
- marker=dict(
72
- color='#ef233c',
73
- size=15,
74
- symbol='line-ns',
75
- line=dict(width=2, color='#ef233c')
76
- ),
77
- hovertemplate='μ‹œκ°„: %{x:.3f}초<extra></extra>'
78
- ))
 
 
 
79
 
80
  fig.update_layout(
81
- title=dict(text="<b>μ˜€λ””μ˜€ νŒŒν˜• 및 κ°μ§€λœ MIDI 동기화 λ·°</b>", font=dict(color="#e9ecef")),
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=350,
86
  margin=dict(l=40, r=20, t=50, b=40),
87
  paper_bgcolor='rgba(0,0,0,0)',
88
- plot_bgcolor='rgba(0,0,0,0)',
89
- legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1)
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
- block_border_color="transparent"
 
 
 
 
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: