Spaces:
Build error
Build error
File size: 1,479 Bytes
49638b7 eb9378a 49638b7 eb9378a 49638b7 6d77e41 49638b7 6d77e41 4f6d9ee 49638b7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
import torch
import requests
import music21
import subprocess
from torchvision import transforms
from PIL import Image
DEFAULT_FILE_NAME = 'sheet_music'
# converting everything into the key of C major or A minor
def convert_to_key():
# major conversions
majors = dict(
[("A-", 4), ("A", 3), ("B-", 2), ("B", 1), ("C", 0), ("D-", -1), ("D", -2), ("E-", -3), ("E", -4), ("F", -5),
("G-", 6), ("G", 5)])
minors = dict(
[("A-", 1), ("A", 0), ("B-", -1), ("B", -2), ("C", -3), ("D-", -4), ("D", -5), ("E-", 6), ("E", 5), ("F", 4),
("G-", 3), ("G", 2)])
score = music21.converter.parse(f'{DEFAULT_FILE_NAME}.musicxml')
key = score.analyze('key')
file_name = 'C_file'
if key.mode == "major":
halfSteps = majors[key.tonic.name]
file_name = 'Am_file'
elif key.mode == "minor":
halfSteps = minors[key.tonic.name]
newscore = score.transpose(halfSteps)
# key = newscore.analyze('key')
# print(key.tonic.name, key.mode)
newscore.write('musicxml', f'{file_name}.musicxml')
# newscore.write('musicxml.pdf', fp="file.pdf")
return f'{file_name}.musicxml', f'{file_name}_teaser.png'
def predict(inp):
return inp
def run():
demo = gr.Interface(
fn=predict,
inputs='text',
outputs='text',
allow_flagging='never',
)
demo.launch(server_name="0.0.0.0", server_port=7860)
if __name__ == "__main__":
run() |