Spaces:
Runtime error
Runtime error
hf-lin
commited on
Commit
•
4c43480
1
Parent(s):
17d9f3a
docker test
Browse files- .gitattributes +1 -0
- Dockerfile +14 -0
- MuseScore-4.1.1.232071203-x86_64.AppImage +3 -0
- app.py +57 -0
.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 |
+
*.AppImage filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./requirements.txt /code/requirements.txt
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
RUN apt-get install fuse libfuse2
|
9 |
+
|
10 |
+
|
11 |
+
COPY . .
|
12 |
+
RUN chmod +x MuseScore-4.1.1.232071203-x86_64.AppImage
|
13 |
+
|
14 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
MuseScore-4.1.1.232071203-x86_64.AppImage
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8658d29db937fe07d76b595d28a0d89b18b85b9e66040fc2b51b4714d36304cf
|
3 |
+
size 169133248
|
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import re
|
4 |
+
import subprocess
|
5 |
+
import time
|
6 |
+
from symusic import Score, Synthesizer
|
7 |
+
import torchaudio
|
8 |
+
import torch
|
9 |
+
|
10 |
+
# for rendering abc notation
|
11 |
+
os.environ['QT_QPA_PLATFORM']='offscreen'
|
12 |
+
os.system("apt-get install fuse libfuse2")
|
13 |
+
os.system("chmod +x MuseScore-4.1.1.232071203-x86_64.AppImage")
|
14 |
+
|
15 |
+
default_abc = """
|
16 |
+
X:1
|
17 |
+
L:1/8
|
18 |
+
M:2/4
|
19 |
+
K:G
|
20 |
+
|:"G" G>A Bc | dB dB |"C" ce ce |"D7" dB A2 |"G" G>A Bc | dB dB |"Am" cA"D7" FA |"G" AG G2 ::
|
21 |
+
"Em" g2"D" f>e | de Bd |"C" ce ce |"D7" dB A2 |"G" g2"D" f>e | de Bd |"Am" cA"D7" FA |"G" AG G2 :|
|
22 |
+
"""
|
23 |
+
|
24 |
+
def parse_abc_notation(text='', conversation_id='debug'):
|
25 |
+
# os.makedirs(f"tmp/", exist_ok=True)
|
26 |
+
ts = time.time()
|
27 |
+
abc_pattern = r'(X:\d+\n(?:[^\n]*\n)+)'
|
28 |
+
abc_notation = re.findall(abc_pattern, text+'\n')
|
29 |
+
print(f'extract abc block: {abc_notation}')
|
30 |
+
if abc_notation:
|
31 |
+
# Convert ABC to midi
|
32 |
+
s = Score.from_abc(abc_notation[0])
|
33 |
+
wav_file = f'{ts}.mp3'
|
34 |
+
audio = Synthesizer().render(s, stereo=True)
|
35 |
+
torchaudio.save(wav_file, torch.FloatTensor(audio), 44100)
|
36 |
+
|
37 |
+
# Convert abc notation to SVG
|
38 |
+
tmp_midi = f'{ts}.mid'
|
39 |
+
s.dump_midi(tmp_midi)
|
40 |
+
svg_file = f'{ts}.svg'
|
41 |
+
subprocess.run(["./MuseScore-4.1.1.232071203-x86_64.AppImage", "-f", "-o", svg_file, tmp_midi])
|
42 |
+
return svg_file, wav_file
|
43 |
+
else:
|
44 |
+
return None, None
|
45 |
+
|
46 |
+
|
47 |
+
if __name__ == "__main__":
|
48 |
+
|
49 |
+
gradio_app = gr.Interface(
|
50 |
+
parse_abc_notation,
|
51 |
+
inputs=["text"],
|
52 |
+
outputs=[gr.Image(label="svg"), gr.Audio(label="audio")],
|
53 |
+
title="ABC notation parse",
|
54 |
+
examples=[default_abc]
|
55 |
+
)
|
56 |
+
|
57 |
+
gradio_app.launch()
|