Spaces:
Build error
Build error
File size: 4,268 Bytes
16e6319 3905f37 16e6319 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | import gradio as gr
import os
import tempfile
import subprocess
import sys
from auto_mapper import run_pipeline
def process_audio(audio_path, bpm, target_stem, mode, quantize_strength, offset, shift, threshold_multiplier, min_votes, tolerance_ms, sr):
if not audio_path:
raise gr.Error("μ€λμ€ νμΌμ λ¨Όμ μ
λ‘λν΄μ£ΌμΈμ.")
if not bpm or bpm <= 0:
raise gr.Error("μ¬λ°λ₯Έ BPM(μ: 120, 150)μ μ
λ ₯ν΄μ£ΌμΈμ.")
out_dir = tempfile.mkdtemp()
out_path = os.path.join(out_dir, "mapped_output.mid")
try:
run_pipeline(
audio_path=audio_path,
output_path=out_path,
bpm=float(bpm),
threshold_multiplier=float(threshold_multiplier),
quantize_strength=quantize_strength,
sr=int(sr),
target_stem=target_stem,
mode=mode,
min_votes=int(min_votes),
tolerance_ms=float(tolerance_ms),
offset=float(offset),
shift=float(shift)
)
if os.path.exists(out_path):
return out_path
else:
raise gr.Error("MIDI νμΌ μμ±μ μ€ν¨νμ΅λλ€. (μΆλ ₯ νμΌ μμ)")
except Exception as e:
raise gr.Error(f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}")
with gr.Blocks(theme=gr.themes.Soft()) as app:
gr.Markdown("# π΅ λ¦¬λ¬ κ²μ μ€ν λ§€ν μΉ UI 곡μ μΌν°")
gr.Markdown(
"νμλ€κ³Ό ν¨κ» μ¬μ©ν μ μλ μ€ν λ§€ν ν΄μ
λλ€.\n\n"
"μ΄ νμ΄μ§μ **μΈλΆ μ£Όμ(Public URL)**λ₯Ό νμμκ² μ λ¬νλ©΄, νμλ€μ νμ΄μ¬μ΄λ κ°λ° νκ²½ μμ΄λ μΉ λΈλΌμ°μ μμ λ°λ‘ μ¬μ©ν μ μμ΅λλ€."
)
with gr.Row():
with gr.Column(scale=1):
audio_input = gr.Audio(type="filepath", label="1οΈβ£ μ€λμ€ νμΌ μ
λ‘λ (.wav, .mp3)")
bpm_input = gr.Number(label="2οΈβ£ λͺ©ν 곑 BPM (νμ μ«μ)", value=120, precision=2)
with gr.Accordion("κΈ°λ³Έ μ€μ ν¨λ (νΌμΉκΈ°/μ κΈ°)", open=True):
target_stem_input = gr.Dropdown(choices=["drums", "vocals", "bass", "other"], value="drums", label="λΆμ μ
κΈ° (κΈ°λ³Έ: drums)")
quantize_input = gr.Dropdown(choices=["1/4", "1/8", "1/16", "1/32"], value="1/16", label="ννμ΄μ¦ 그리λ λ¨μ")
offset_input = gr.Number(label="첫 λ°μ μ€νμ
(μ΄ λλ μ΄, μ: 0.045)", value=0.0)
shift_input = gr.Number(label="μ 체 λ
ΈνΈ κ°μ μ΄λ (μ΄, μ: -0.025λ μλΉκΉ)", value=0.0)
with gr.Accordion("κ³ κΈ μ€μ ν¨λ (μ λ¬Έκ°μ©)", open=False):
mode_input = gr.Radio(choices=["single", "vote"], value="single", label="μλ λͺ¨λ (κΈ°λ³Έ: single)")
threshold_input = gr.Slider(minimum=0.1, maximum=2.0, value=0.5, step=0.1, label="λλΌ μλμ§ μκ³μΉ (Threshold)")
min_votes_input = gr.Slider(minimum=1, maximum=4, value=2, step=1, label="μ΅μ ν©μ μ (Vote λͺ¨λ νμ )")
tolerance_input = gr.Number(label="ν©μ νμ© μ€μ°¨ (ms)", value=50.0)
sr_input = gr.Number(label="μ€λμ€ μνλ μ΄νΈ (Hz)", value=22050)
submit_btn = gr.Button("π MIDI νμ΄νλΌμΈ κ°λ", variant="primary")
with gr.Column(scale=1):
midi_output = gr.File(label="π₯ μμ±λ κ²°κ³Όλ¬Ό (MIDI νμΌ λ€μ΄λ‘λ)")
submit_btn.click(
fn=process_audio,
inputs=[
audio_input, bpm_input, target_stem_input, mode_input,
quantize_input, offset_input, shift_input, threshold_input,
min_votes_input, tolerance_input, sr_input
],
outputs=midi_output
)
if __name__ == "__main__":
# share=True μ€μ μ ngrokμ μ°μ§ μμλ μλ μΈλΆ λ§ν¬ λ°κΈ(72μκ°)
print("μΉ μλ²λ₯Ό μμν©λλ€. νμ΄μ¬ μ½μμ μΆλ ₯λλ \"Running on public URL\" μ£Όμλ₯Ό νμλΆλ€μκ² μ λ¬ν΄μ£ΌμΈμ!")
app.launch(share=True, server_name="0.0.0.0")
|