oddsilk commited on
Commit
16e6319
Β·
verified Β·
1 Parent(s): 424badf

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
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")