Spaces:
Build error
Build error
Download app.py from oddsilk/MidiMakerUI: direct link, hf CLI and curl.
- Browser
- Download file 4.27 kB
-
https://huggingface.co/spaces/oddsilk/MidiMakerUI/resolve/main/app.py
- Command line
-
hf download hf://spaces/oddsilk/MidiMakerUI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/oddsilk/MidiMakerUI/resolve/main/app.py
4.27 kB
| 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") | |