osanseviero commited on
Commit
dc21b67
·
1 Parent(s): d21df2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -115,17 +115,17 @@ def process(text):
115
  input_ids = tokenizer.encode(text, return_tensors="pt")
116
  generated_ids = model.generate(input_ids, max_length=500)
117
  generated_sequence = tokenizer.decode(generated_ids[0])
118
- print(generated_sequence)
119
 
120
  # Convert text of notes to audio
121
  note_sequence = token_sequence_to_note_sequence(generated_sequence)
122
  synth = note_seq.midi_synth.synthesize
123
  array_of_floats = synth(note_sequence, sample_rate=SAMPLE_RATE)
124
- note_plot = note_seq.plot_sequence(note_sequence, False)
125
  html = file_html(note_plot, CDN)
126
 
127
- scipy.io.wavfile.write("tmp_output.wav", SAMPLE_RATE, array_of_floats)
128
- return "tmp_output.wav", html
 
129
 
130
  title = "Music generation with GPT-2"
131
 
 
115
  input_ids = tokenizer.encode(text, return_tensors="pt")
116
  generated_ids = model.generate(input_ids, max_length=500)
117
  generated_sequence = tokenizer.decode(generated_ids[0])
 
118
 
119
  # Convert text of notes to audio
120
  note_sequence = token_sequence_to_note_sequence(generated_sequence)
121
  synth = note_seq.midi_synth.synthesize
122
  array_of_floats = synth(note_sequence, sample_rate=SAMPLE_RATE)
123
+ note_plot = note_seq.plot_sequence(note_sequence, True)
124
  html = file_html(note_plot, CDN)
125
 
126
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
127
+ scipy.io.wavfile.write(fp.name, SAMPLE_RATE, array_of_floats)
128
+ return fp.name, html
129
 
130
  title = "Music generation with GPT-2"
131