Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
from transformers import AutoProcessor, VisionEncoderDecoderModel
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
-
|
10 |
-
def generate_study_course(note_string):
|
11 |
-
note_list = note_string.split()
|
12 |
-
unique_notes = sorted(set(note_list))
|
13 |
-
|
14 |
-
course = {
|
15 |
"Scales": {
|
16 |
"All Notes": unique_notes,
|
17 |
"Suggested Practice": [f"{note} Major Scale" for note in unique_notes]
|
18 |
},
|
19 |
"Practice Exercises": {
|
20 |
-
"Sight Reading (4-note chunks)": [
|
21 |
"Finger Exercises": [f"{note} Arpeggio" for note in unique_notes]
|
22 |
}
|
23 |
}
|
24 |
-
return
|
25 |
-
|
26 |
-
# Main function
|
27 |
-
def process_sheet(image: Image.Image):
|
28 |
-
inputs = processor(images=image.convert("RGB"), return_tensors="pt")
|
29 |
-
output = model.generate(**inputs)
|
30 |
-
notes = processor.batch_decode(output, skip_special_tokens=True)[0]
|
31 |
-
return generate_study_course(notes)
|
32 |
-
|
33 |
-
# Gradio interface
|
34 |
-
demo = gr.Interface(
|
35 |
-
fn=process_sheet,
|
36 |
-
inputs=gr.Image(type="pil", label="Upload Sheet Music Image"),
|
37 |
-
outputs=gr.JSON(label="Generated Study Course"),
|
38 |
-
title="🎼 Sheet Music Study AI",
|
39 |
-
description="Upload a sheet music image to detect notes and receive a structured study course with scales and practice suggestions.",
|
40 |
-
)
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from music21 import converter
|
|
|
3 |
|
4 |
+
def process_musicxml(file):
|
5 |
+
score = converter.parse(file.name)
|
6 |
+
notes = [str(n.pitch) for n in score.flat.notes if n.isNote]
|
7 |
+
unique_notes = sorted(set(notes))
|
8 |
|
9 |
+
study_plan = {
|
|
|
|
|
|
|
|
|
|
|
10 |
"Scales": {
|
11 |
"All Notes": unique_notes,
|
12 |
"Suggested Practice": [f"{note} Major Scale" for note in unique_notes]
|
13 |
},
|
14 |
"Practice Exercises": {
|
15 |
+
"Sight Reading (4-note chunks)": [notes[i:i+4] for i in range(0, len(notes)-3, 4)],
|
16 |
"Finger Exercises": [f"{note} Arpeggio" for note in unique_notes]
|
17 |
}
|
18 |
}
|
19 |
+
return study_plan
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
gr.Interface(
|
22 |
+
fn=process_musicxml,
|
23 |
+
inputs=gr.File(file_types=[".musicxml", ".xml"], label="Upload MusicXML File"),
|
24 |
+
outputs=gr.JSON(label="Study Plan"),
|
25 |
+
title="🎼 MusicXML Study Generator",
|
26 |
+
description="Upload a MusicXML file to generate scales and practice routines."
|
27 |
+
).launch()
|