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