Spaces:
Runtime error
Runtime error
Commit
·
fcd19a0
1
Parent(s):
2f69c98
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,33 @@ model.load_state_dict(torch.load('another_epoch_1.75total.ckpt', map_location=de
|
|
22 |
stoi = pickle.load(open('stoi.pkl', 'rb'))
|
23 |
itos = pickle.load(open('itos.pkl', 'rb'))
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
# Generate function
|
26 |
def generate_song(randomize, title, nu, ks, key):
|
27 |
# Start sequence
|
@@ -56,7 +83,7 @@ demo = gr.Blocks()
|
|
56 |
with demo:
|
57 |
gr.Markdown("Quick demo for [WhistleGen v2](https://wandb.ai/johnowhitaker/whistlegen_v2/reports/WhistleGen-v2--VmlldzoyMTAwNjAz) which lets you generate folk music using a transformer model. I can't get the javascript needed for rendering and playback working with gradio, so this shows the raw ABC notation from the model and a link to view it properly in an external editor.")
|
58 |
with gr.Row():
|
59 |
-
title = gr.Text(label='Title', value='The
|
60 |
with gr.Column():
|
61 |
nu = gr.Text(label='Note unit', value='1/8')
|
62 |
with gr.Row():
|
@@ -66,7 +93,7 @@ with demo:
|
|
66 |
with gr.Row():
|
67 |
randomize = gr.Checkbox(label='Randomize (ignores settings above)', value=True)
|
68 |
with gr.Row():
|
69 |
-
out = gr.HTML(label="Output", value='Output
|
70 |
btn = gr.Button("Run")
|
71 |
btn.click(fn=generate_song, inputs=[randomize, title, nu, key_signature, key], outputs=out)
|
72 |
|
|
|
22 |
stoi = pickle.load(open('stoi.pkl', 'rb'))
|
23 |
itos = pickle.load(open('itos.pkl', 'rb'))
|
24 |
|
25 |
+
# Post-process generation
|
26 |
+
# Completion
|
27 |
+
def completion_to_song(c):
|
28 |
+
lines = c.split('\n')
|
29 |
+
kept_lines = []
|
30 |
+
notes = False
|
31 |
+
for l in lines:
|
32 |
+
|
33 |
+
# Record if we've hit music
|
34 |
+
if '|' in l:
|
35 |
+
notes = True
|
36 |
+
|
37 |
+
# Stop if we then go back to the start of another song
|
38 |
+
if 'T' in l and notes:
|
39 |
+
break
|
40 |
+
if 'T' in l and notes:
|
41 |
+
break
|
42 |
+
|
43 |
+
# Stop on an empty line
|
44 |
+
if len(l.strip()) < 2 and notes:
|
45 |
+
break
|
46 |
+
|
47 |
+
# Otherwise keep the line
|
48 |
+
kept_lines.append(l)
|
49 |
+
|
50 |
+
return '\n'.join(kept_lines)
|
51 |
+
|
52 |
# Generate function
|
53 |
def generate_song(randomize, title, nu, ks, key):
|
54 |
# Start sequence
|
|
|
83 |
with demo:
|
84 |
gr.Markdown("Quick demo for [WhistleGen v2](https://wandb.ai/johnowhitaker/whistlegen_v2/reports/WhistleGen-v2--VmlldzoyMTAwNjAz) which lets you generate folk music using a transformer model. I can't get the javascript needed for rendering and playback working with gradio, so this shows the raw ABC notation from the model and a link to view it properly in an external editor.")
|
85 |
with gr.Row():
|
86 |
+
title = gr.Text(label='Title', value='The March of AI')
|
87 |
with gr.Column():
|
88 |
nu = gr.Text(label='Note unit', value='1/8')
|
89 |
with gr.Row():
|
|
|
93 |
with gr.Row():
|
94 |
randomize = gr.Checkbox(label='Randomize (ignores settings above)', value=True)
|
95 |
with gr.Row():
|
96 |
+
out = gr.HTML(label="Output", value='Output should appear here (takes ~30s)')
|
97 |
btn = gr.Button("Run")
|
98 |
btn.click(fn=generate_song, inputs=[randomize, title, nu, key_signature, key], outputs=out)
|
99 |
|