agent404 commited on
Commit
d8d9ed1
·
1 Parent(s): 5adabf3

first commit

Browse files
Files changed (3) hide show
  1. app.py +51 -0
  2. packages.txt +0 -0
  3. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import time
4
+ import subprocess
5
+ import gradio as gr
6
+
7
+ os.environ['QT_QPA_PLATFORM']='offscreen'
8
+ # os.environ['MPLCONFIGDIR'] = os.getcwd() + "/configs/"
9
+
10
+ # for rendering abc notation
11
+ default_abc = """
12
+ X:1
13
+ L:1/8
14
+ M:2/4
15
+ K:G
16
+ |:"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 ::
17
+ "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 :|
18
+ """
19
+
20
+ def parse_abc_notation(text='', conversation_id='debug'):
21
+ os.makedirs(f"tmp/{conversation_id}", exist_ok=True)
22
+ abc_pattern = r'(X:\d+\n(?:[^\n]*\n)+)'
23
+ abc_notation = re.findall(abc_pattern, text+'\n')
24
+ print(f'extract abc block: {abc_notation}')
25
+ if abc_notation:
26
+ ts = time.time()
27
+ # Write the ABC text to a temporary file
28
+ tmp_abc = f"tmp/{conversation_id}/{ts}.abc"
29
+ with open(tmp_abc, "w") as abc_file:
30
+ abc_file.write(abc_notation[0])
31
+ # Convert abc notation to midi
32
+ tmp_midi = f'tmp/{conversation_id}/{ts}.mid'
33
+ subprocess.run(["abc2midi", str(tmp_abc), "-o", tmp_midi])
34
+ # Convert abc notation to SVG
35
+ svg_file = f'tmp/{conversation_id}/{ts}.svg'
36
+ audio_file = f'tmp/{conversation_id}/{ts}.mp3'
37
+ subprocess.run(["./MuseScore-4.1.1.232071203-x86_64.AppImage", "-f", "-o", svg_file, tmp_midi])
38
+ subprocess.run(["./MuseScore-4.1.1.232071203-x86_64.AppImage", "-f", "-o", audio_file, tmp_midi])
39
+ return svg_file, audio_file
40
+ else:
41
+ return None, None
42
+
43
+ gradio_app = gr.Interface(
44
+ parse_abc_notation,
45
+ inputs=["text"],
46
+ outputs=[gr.Image(label="svg"), gr.Audio(label="audio")],
47
+ title="ABC notation parse",
48
+ examples=[default_abc]
49
+ )
50
+
51
+ gradio_app.launch()
packages.txt ADDED
File without changes
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==4.19.2
2
+ transformers==4.32.0