Spaces:
Running on Zero
Running on Zero
Commit ·
e337419
1
Parent(s): 37754dc
feat: add examples and image cropping method
Browse files- .gitattributes +1 -0
- app.py +16 -0
- examples/.gitkeep +0 -0
- examples/Example1.png +3 -0
- examples/Example2.png +3 -0
- examples/Example3.png +3 -0
- examples/Example4.png +3 -0
- examples/Example5.png +3 -0
- image_utils.py +5 -5
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import spaces # Must be before any CUDA/torch imports
|
| 2 |
import gradio as gr
|
| 3 |
|
|
@@ -5,6 +7,14 @@ import abc_utils
|
|
| 5 |
import config
|
| 6 |
from inference import inference
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
with gr.Blocks(theme=gr.themes.Soft(), title="LEGATO OMR Demo") as demo:
|
| 9 |
gr.Markdown("""
|
| 10 |
# 🎼 LEGATO: Large-scale End-to-end Generalizable Approach to Typeset OMR
|
|
@@ -33,6 +43,12 @@ with gr.Blocks(theme=gr.themes.Soft(), title="LEGATO OMR Demo") as demo:
|
|
| 33 |
|
| 34 |
gr.Markdown("### ✨ Try it")
|
| 35 |
inp = gr.Image(type="pil", label="📤 Upload score image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
with gr.Row():
|
| 37 |
out = gr.Textbox(label="📝 ABC transcription", lines=10, buttons=["copy"])
|
| 38 |
with gr.Accordion("🎵 Rendered ABC notation", open=True):
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
import spaces # Must be before any CUDA/torch imports
|
| 4 |
import gradio as gr
|
| 5 |
|
|
|
|
| 7 |
import config
|
| 8 |
from inference import inference
|
| 9 |
|
| 10 |
+
_EXAMPLE_EXTENSIONS = (".png", ".jpg", ".jpeg", ".webp")
|
| 11 |
+
_examples_dir = os.path.join(config.APP_DIR, "examples")
|
| 12 |
+
_example_paths = []
|
| 13 |
+
if os.path.isdir(_examples_dir):
|
| 14 |
+
for name in sorted(os.listdir(_examples_dir)):
|
| 15 |
+
if name.lower().endswith(_EXAMPLE_EXTENSIONS):
|
| 16 |
+
_example_paths.append([os.path.join(_examples_dir, name)])
|
| 17 |
+
|
| 18 |
with gr.Blocks(theme=gr.themes.Soft(), title="LEGATO OMR Demo") as demo:
|
| 19 |
gr.Markdown("""
|
| 20 |
# 🎼 LEGATO: Large-scale End-to-end Generalizable Approach to Typeset OMR
|
|
|
|
| 43 |
|
| 44 |
gr.Markdown("### ✨ Try it")
|
| 45 |
inp = gr.Image(type="pil", label="📤 Upload score image")
|
| 46 |
+
if _example_paths:
|
| 47 |
+
gr.Examples(
|
| 48 |
+
examples=_example_paths,
|
| 49 |
+
inputs=[inp],
|
| 50 |
+
label="Example scores",
|
| 51 |
+
)
|
| 52 |
with gr.Row():
|
| 53 |
out = gr.Textbox(label="📝 ABC transcription", lines=10, buttons=["copy"])
|
| 54 |
with gr.Accordion("🎵 Rendered ABC notation", open=True):
|
examples/.gitkeep
ADDED
|
File without changes
|
examples/Example1.png
ADDED
|
Git LFS Details
|
examples/Example2.png
ADDED
|
Git LFS Details
|
examples/Example3.png
ADDED
|
Git LFS Details
|
examples/Example4.png
ADDED
|
Git LFS Details
|
examples/Example5.png
ADDED
|
Git LFS Details
|
image_utils.py
CHANGED
|
@@ -5,12 +5,12 @@ from config import LETTER_ASPECT
|
|
| 5 |
|
| 6 |
def pad_to_portrait_letter(pil_image: Image.Image) -> Image.Image:
|
| 7 |
"""If aspect ratio is wider than letter, pad at the bottom to match letter aspect."""
|
| 8 |
-
w, h = pil_image.size
|
| 9 |
-
if w / h < LETTER_ASPECT:
|
| 10 |
-
return pil_image
|
| 11 |
-
new_h = int(round(w / LETTER_ASPECT))
|
| 12 |
-
canvas = Image.new("RGB", (w, new_h), (255, 255, 255))
|
| 13 |
if pil_image.mode != "RGB":
|
| 14 |
pil_image = pil_image.convert("RGB")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
canvas.paste(pil_image, (0, 0))
|
| 16 |
return canvas
|
|
|
|
| 5 |
|
| 6 |
def pad_to_portrait_letter(pil_image: Image.Image) -> Image.Image:
|
| 7 |
"""If aspect ratio is wider than letter, pad at the bottom to match letter aspect."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
if pil_image.mode != "RGB":
|
| 9 |
pil_image = pil_image.convert("RGB")
|
| 10 |
+
w, h = pil_image.size
|
| 11 |
+
pil_image = pil_image.resize((1050, 1050*h//w))
|
| 12 |
+
if pil_image.height >= 1485:
|
| 13 |
+
return pil_image
|
| 14 |
+
canvas = Image.new("RGB", (1050, 1485), (255, 255, 255))
|
| 15 |
canvas.paste(pil_image, (0, 0))
|
| 16 |
return canvas
|