| |
| |
| |
|
|
| import os |
| import time as reqtime |
| import datetime |
| from pytz import timezone |
|
|
| import gradio as gr |
|
|
| |
|
|
| import subprocess |
|
|
| def run_jar(jar_path='ArtificialSongGenerator.jar', args=["--title=MuseCraft_AlgoSong_Composition"]): |
| |
| cmd = ["java", "-jar", jar_path] |
| |
| if args: |
| cmd.extend(args) |
| |
| result = subprocess.run(cmd, capture_output=True, text=True) |
| |
| return result.stdout, result.stderr |
|
|
| |
|
|
| def Generate_Song(): |
|
|
| print('=' * 70) |
| print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT))) |
| start_time = reqtime.time() |
| print('=' * 70) |
|
|
| |
|
|
| print('=' * 70) |
| print('MuseCraft AlgoSong Generator') |
| print('=' * 70) |
|
|
| print('Generating...') |
|
|
| stdout, stderr = run_jar() |
| |
| print('Done!') |
| print('=' * 70) |
| |
| print("Output:", stdout) |
| print("Errors:", stderr) |
|
|
| output_midi = 'MuseCraft_AlgoSong_Composition_Demo.mid' |
| |
| |
|
|
| print('=' * 70) |
| |
| |
| |
| print('-' * 70) |
| print('Req end time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT))) |
| print('-' * 70) |
| print('Req execution time:', (reqtime.time() - start_time), 'sec') |
|
|
| return output_midi |
|
|
| |
|
|
| if __name__ == "__main__": |
| |
| PDT = timezone('US/Pacific') |
| |
| print('=' * 70) |
| print('App start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT))) |
| print('=' * 70) |
|
|
| |
| |
| app = gr.Blocks() |
| with app: |
| gr.Markdown("<h1 style='text-align: left; margin-bottom: 1rem'>MuseCraft AlgoSong</h1>") |
| gr.Markdown("<h1 style='text-align: left; margin-bottom: 1rem'>Algorithmic song generator</h1>") |
| gr.HTML(""" |
| Check out <a href="https://github.com/MIDIAI/MuseCraft">MuseCraft project</a> on GitHub |
| """) |
| gr.HTML(""" |
| Song generator source <a href="https://github.com/fabianostermann/ArtificialSongGenerator"> on Github</a> |
| <p> |
| <a href="https://huggingface.co/spaces/projectlosangeles/MuseCraft-AlgoSong?duplicate=true"> |
| <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-md.svg" alt="Duplicate in Hugging Face"> |
| </a> |
| </p> |
| """) |
| |
| run_btn = gr.Button("generate", variant="primary") |
|
|
| gr.Markdown("## Generation results") |
| |
| output_midi = gr.File(label="Output MIDI file", file_types=[".mid"]) |
|
|
| run_event = run_btn.click(Generate_Song, [], [output_midi]) |
| |
| app.queue().launch() |