CoolFace
Apppublic

vksingh7532/AI-Music-Composer

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
App README

AI Music Composer ๐ŸŽน

<p align="center"> <img src="https://github.com/user-attachments/assets/c316b03c-f11e-45f5-95b9-e640e3319c88" alt="Project Img" width="575"> </p>

Link to my project: https://huggingface.co/spaces/vksingh7532/AI-Music-Composer

This project uses a Long Short-Term Memory (LSTM) neural network to learn the patterns, melodies, and harmonies from a dataset of classical piano music. It can then generate new, original compositions in the same style.


Key Features

  • โ€”Music Generation: Creates novel piano compositions in MIDI format.
  • โ€”Style Learning: The model is trained on a corpus of classical music to learn its underlying structure.
  • โ€”LSTM Architecture: Built with a deep LSTM network using TensorFlow and Keras, ideal for learning sequential patterns.
  • โ€”Customizable: Can be re-trained on any collection of MIDI files to learn different musical styles.
  • โ€”Analysis Tools: Includes a script to programmatically compare the differences between generated compositions.

Tech Stack

  • โ€”Python 3.9+
  • โ€”TensorFlow / Keras for building and training the LSTM model.
  • โ€”Music21 for parsing and manipulating MIDI files.
  • โ€”NumPy for numerical operations.
  • โ€”Google Colab for GPU-accelerated training.
  • โ€”Flask & Gunicorn for the web application backend.
  • โ€”Hugging Face Spaces for deployment.

Setup and Installation

To run this project locally, follow these steps:

  1. 1.Clone the repository:
bash
    git clone [https://github.com/vivekrsingh10/AI-Music-Composer.git](https://github.com/vivekrsingh10/AI-Music-Composer.git)
    cd AI-Music-Composer
  1. 1.Create a virtual environment (recommended):
bash
    python -m venv myenv
    source myenv/bin/activate  # On Windows, use `myenv\Scripts\activate`
  1. 1.Install dependencies: (Note: You'll need to create a `requirements.txt` file containing `tensorflow`, `music21`, and `numpy`)
bash
    pip install -r requirements.txt
  1. 1.Download the Training Data: The model was trained on the "Classical Music MIDI" dataset from Kaggle.
  2. 2.Download the dataset from this link.
  3. 3.Create a folder named midi_files in the project directory.
  4. 4.Place all the .mid files from the dataset into the midi_files folder.

Usage

The project is structured within the main Colab notebook (AI_Music_Composer.ipynb) or a Python script.

Generating Music (Using the Pre-trained Model)

The repository includes a pre-trained model (music_model.h5) and the necessary data file (data/notes). To generate a new piece:

  1. 1.Ensure the music_model.h5 and data/notes files are present.
  2. 2.Open the notebook or script and call the generate() function. A new, unique MIDI file will be created in the root directory.

Training a New Model

To train the model from scratch on your own dataset:

  1. 1.Make sure your custom MIDI files are in the midi_files folder.
  2. 2.Call the train_network() function. This process is computationally intensive and is best run in a GPU-accelerated environment like Google Colab.
  3. 3.A new music_model.h5 and data/notes file will be generated upon completion.

Sample Output

Listen to a sample composition generated by this model:

โ–ถ๏ธ [sample_output.mid](https://github.com/vivekrsingh10/AI-Music-Composer/blob/main/sample_output_1.mid) โ–ถ๏ธ [sample_output.mid](https://github.com/vivekrsingh10/AI-Music-Composer/blob/main/sample_output_2.mid)


Future Improvements

  • โ€”Implement a Transformer Model: Explore using a more modern Transformer architecture with attention mechanisms for potentially more complex and long-range musical structures.
  • โ€”Add More Musical Nuance: Extend the model to learn and predict note duration and velocity (volume) for more expressive compositions.
  • โ€”Improve Web App UI: Enhance the user interface, possibly using a framework like Gradio or Streamlit, to allow for more user interaction, such as selecting a "priming" note to start the composition.

License

This project is licensed under the MIT License - see the LICENSE file for details.