The MuseCoco Text-to-MIDI Service is a refactored version of the MuseCoco repository, designed as a deployable service module. This service adapts to new data, manages the history of its checkpoints, and abstracts away the underlying implementation details to provide a seamless interface for generating MIDI files from textual inputs. Detailed comments are included to facilitate easy navigation and understanding of the codebase.
The repository is organized as follows:
musecoco-text2midi-service/
โโโ src/
โ โโโ musecoco_text2midi_service/
โ โโโ control/ # Controllers for orchestrating service logic
โ โ โโโ __init__.py
โ โ โโโ _musecoco/
โ โ โ โโโ __init__.py
โ โ โ โโโ view.py
โ โ โโโ _text2midi.py
โ โโโ dao/ # Data Access Objects for configuration management
โ โ โโโ __init__.py
โ โ โโโ _config_manager.py
โ โโโ model/ # Models representing the structure and workflow of MIDI generation
โ โ โโโ __init__.py
โ โ โโโ _config_model.py
โ โโโ utils/ # Utility functions for common tasks
โ โ โโโ __init__.py
โ โ โโโ _watch_dog.py
โ โโโ view/ # Views for API or CLI outputs
โ โโโ __init__.py
โ โโโ _app_view.py
โโโ storage/
โ โโโ checkpoints/ # Model checkpoints
โ โ โโโ linear_mask-1billion/
โ โ โโโ checkpoint_2_280000.pt
โ โ โโโ README.md # Instructions for managing checkpoints
โ โโโ config/ # Configuration files
โ โ โโโ main_config.yaml # Main configuration file
โ โ โโโ att_key.json
โ โ โโโ num_labels.json
โ โโโ input/ # Input files for predictions
โ โ โโโ predict_backup.json # Example input format for predictions
โ โ โโโ predict.json
โ โโโ log/ # Log files
โ โโโ tmp/ # Temporary files and outputs
โโโ tests/
โ โโโ __init__.py # Initializer for the tests package
โ โโโ ... # Test modules for various components
โโโ .gitignore # Specifies files and directories to ignore in version control
โโโ LICENSE # License file
โโโ main.py # Entry point for running the service
โโโ README.md # Project description and instructions
โโโ setup.py # Setup script for packaging and distribution
To install the MuseCoco Text-to-MIDI Service, follow these steps:
Clone the Repository:
git clone https://github.com/your-repo/musecoco-text2midi-service.git
cd musecoco-text2midi-service
Install Dependencies:
Create a new environment and install the dependencies. Currently, PyTorch needs to be installed with conda
:
conda env create -f conda_env.yml
conda activate MuseCoco
conda -c nvidia/label/cuda-12.3
pip install torch==2.3
pip install --user --no-cache-dir pytorch-fast-transformers
pip install -e .
<!-- cd modules
git clone https://github.com/pytorch/fairseq
cd fairseq
pip install -e . -->
Note: Other dependencies can be installed with
pip install -e .
orpip install musecoco_text2midi_service
. PyTorch installation withpip
will be supported later.
The service uses YAML configuration files located in storage/config/
. The main configuration file is main_config.yaml
, which is used by the main.py
script. You can modify these files to configure parameters such as model checkpoints, logging settings, and API keys.
Checkpoints should follow the instructions provided in storage/checkpoints/linear_mask-1billion/README.md
and be saved in the same directory as the README.md file.
To start the service, run:
python main.py
The main.py
file provides a terminal-based app demo.
Refer to
storage/input/predict_backup.json
for examples of acceptable input formats for the service. This file contains sample data that illustrates how to structure text input for the MIDI generation process.
You can also import the package to your project.
from musecoco_text2midi_service.control import Text2Midi
from musecoco_text2midi_service.dao import load_config_from_file
config = load_config_from_file("storage/config/main_config.yaml")
text2midi = Text2Midi(config)
input_text = "This music's use of major key creates a distinct atmosphere, with a playtime of 1 ~ 15 seconds. The rhythm in this song is very pronounced, and the music is enriched by grand piano, cello and drum. Overall, the song's length is around about 6 bars. The music conveys edginess."
midi_data, meta_data = text2midi.text_to_midi(input_text, return_midi=True)
Later this will launch the MuseCoco Text-to-MIDI Service, allowing you to convert textual descriptions into MIDI files through the defined APIs or CLI.
To run the test suite, use:
pytest /tests
This command will execute all test cases in the tests
directory and provide a report of the test results. Ensure that the project is built correctly before running the tests.
We welcome contributions from the community. Please follow these steps to contribute:
This project is licensed under Apache License 2.0 - see the LICENSE file for more details.
Thank you for your interest in the MuseCoco Text-to-MIDI Service! If you have any questions or need further assistance, feel free to open an issue or contact us.