saumyap29 commited on
Commit
65b3cc6
·
1 Parent(s): 04aef64

amt context history

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- import spaces # Enables ZeroGPU on Hugging Face
3
  import gradio as gr
4
  import torch
5
  from dataclasses import asdict
@@ -26,8 +26,8 @@ model_card = ModelCard(
26
  name="Anticipatory Music Transformer",
27
  description=(
28
  "Generate musical accompaniment for your existing vamp using the Anticipatory Music Transformer. "
29
- "Input: a MIDI file with a short accompaniment followed by a melody line. "
30
- "Output: a new MIDI file with extended accompaniment matching the melody. "
31
  "Use the sliders to choose model size and how much of the song is used as context."
32
  ),
33
  author="John Thickstun, David Hall, Chris Donahue, Percy Liang",
@@ -188,7 +188,7 @@ def auto_extract_melody(mid, debug=False):
188
 
189
  return events, melody
190
 
191
- @spaces.GPU
192
  # Core generation
193
  def generate_accompaniment(midi_path: str, model_choice: str, history_length: float):
194
  """
@@ -207,19 +207,23 @@ def generate_accompaniment(midi_path: str, model_choice: str, history_length: fl
207
  print("No melody detected; using all events")
208
  melody = all_events
209
 
210
- melody_time = mid.length # Mido computes total duration in seconds
211
- total_time = round(mid.length or ops.max_time(all_events, seconds=True))
 
 
212
 
213
  # History portion
214
- history = ops.clip(all_events, 0, history_length, clip_duration=False)
 
 
215
 
216
  # Generate accompaniment for the remaining duration
217
  accompaniment = generate(
218
  model,
219
  start_time=history_length, # start after history
220
  end_time=total_time, # go to end
221
- inputs=history,
222
- controls=melody,
223
  top_p=0.95,
224
  debug=False
225
  )
@@ -232,6 +236,8 @@ def generate_accompaniment(midi_path: str, model_choice: str, history_length: fl
232
  clip_duration=True
233
  )
234
 
 
 
235
  print(f"Generating from {history_length:.2f}s -> {total_time:.2f}s "
236
  f"(duration = {total_time - history_length:.2f}s)")
237
 
 
1
  import os
2
+ #import spaces # Enables ZeroGPU on Hugging Face
3
  import gradio as gr
4
  import torch
5
  from dataclasses import asdict
 
26
  name="Anticipatory Music Transformer",
27
  description=(
28
  "Generate musical accompaniment for your existing vamp using the Anticipatory Music Transformer. "
29
+ "Input: a MIDI file with a short accompaniment (vamp) followed by a melody line. "
30
+ "Output: a new MIDI file with extended accompaniment matching the melody continuation. "
31
  "Use the sliders to choose model size and how much of the song is used as context."
32
  ),
33
  author="John Thickstun, David Hall, Chris Donahue, Percy Liang",
 
188
 
189
  return events, melody
190
 
191
+ #@spaces.GPU
192
  # Core generation
193
  def generate_accompaniment(midi_path: str, model_choice: str, history_length: float):
194
  """
 
207
  print("No melody detected; using all events")
208
  melody = all_events
209
 
210
+ ## Compute total time
211
+ mid_time = mid.length or 0
212
+ ops_time = ops.max_time(all_events, seconds=True)
213
+ total_time = round(max(mid_time, ops_time))
214
 
215
  # History portion
216
+ #history = ops.clip(all_events, 0, history_length, clip_duration=False)
217
+ melody_history = ops.clip(all_events, 0, history_length, clip_duration=False)
218
+ melody_future = ops.clip(melody, history_length, total_time, clip_duration=False)
219
 
220
  # Generate accompaniment for the remaining duration
221
  accompaniment = generate(
222
  model,
223
  start_time=history_length, # start after history
224
  end_time=total_time, # go to end
225
+ inputs=melody_history,
226
+ controls=melody_future,
227
  top_p=0.95,
228
  debug=False
229
  )
 
236
  clip_duration=True
237
  )
238
 
239
+ print(f"[DEBUG] Context events: {len(melody_history)}, Future melody events: {len(melody_future)}")
240
+
241
  print(f"Generating from {history_length:.2f}s -> {total_time:.2f}s "
242
  f"(duration = {total_time - history_length:.2f}s)")
243