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")