Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
from transformers import AutoProcessor, VisionEncoderDecoderModel
|
4 |
+
|
5 |
+
# Load model
|
6 |
+
processor = AutoProcessor.from_pretrained("truelitmus/omr-crnn")
|
7 |
+
model = VisionEncoderDecoderModel.from_pretrained("truelitmus/omr-crnn")
|
8 |
+
|
9 |
+
# Study course generator
|
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)": [note_list[i:i+4] for i in range(0, len(note_list)-3, 4)],
|
21 |
+
"Finger Exercises": [f"{note} Arpeggio" for note in unique_notes]
|
22 |
+
}
|
23 |
+
}
|
24 |
+
return course
|
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 |
+
demo.launch()
|