music-ai / model2.py
Zeroxdesignart's picture
Create model2.py
47c3e14 verified
raw
history blame contribute delete
646 Bytes
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load the generator model
melody_model = AutoModelForCausalLM.from_pretrained("your_model_repo/multi-model-music-generator")
tokenizer = AutoTokenizer.from_pretrained("gpt2")
# Define a prompt for generating music
prompt = "A smooth jazz melody with a lively rhythm"
# Tokenize input and generate music
inputs = tokenizer(prompt, return_tensors="pt")
outputs = melody_model.generate(inputs['input_ids'], max_length=200)
# Decode to text or MIDI, based on the final setup
generated_music = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_music)