lllindsey0615 commited on
Commit
89a7215
·
1 Parent(s): 668f3fc

correct requirements.txt

Browse files
Files changed (3) hide show
  1. Dockerfile +13 -5
  2. app.py +0 -119
  3. requirements.txt +1 -0
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- # Use an official Python image
2
  FROM python:3.11
3
 
4
  # Set working directory
@@ -11,14 +11,22 @@ RUN apt-get update && apt-get install -y \
11
  fluid-soundfont-gm \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- # Install Python dependencies (including PyHARP from requirements.txt)
 
 
 
15
  COPY requirements.txt .
16
  RUN pip install --no-cache-dir -r requirements.txt
17
 
18
  # Clone and install Anticipation Music Transformer (AMT)
19
- RUN git clone https://github.com/jthickstun/anticipation.git && \
20
- pip install ./anticipation && \
21
- pip install -r anticipation/requirements.txt
 
 
 
 
 
22
 
23
  # Copy the application files into the container
24
  COPY . .
 
1
+ # Use Python 3.11
2
  FROM python:3.11
3
 
4
  # Set working directory
 
11
  fluid-soundfont-gm \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Upgrade pip before installing dependencies
15
+ RUN pip install --upgrade pip
16
+
17
+ # Copy and install Python dependencies first (before cloning anticipation)
18
  COPY requirements.txt .
19
  RUN pip install --no-cache-dir -r requirements.txt
20
 
21
  # Clone and install Anticipation Music Transformer (AMT)
22
+ RUN git clone https://github.com/jthickstun/anticipation.git
23
+
24
+ # Install AMT dependencies separately to avoid conflicts
25
+ RUN pip install -r anticipation/requirements.txt && \
26
+ pip install ./anticipation
27
+
28
+ # Debugging: Check installed packages
29
+ RUN pip list
30
 
31
  # Copy the application files into the container
32
  COPY . .
app.py CHANGED
@@ -111,122 +111,3 @@ demo.launch(share=True, show_error=True, debug=True)
111
 
112
 
113
 
114
- '''
115
-
116
- def extract_midi_events(input_midi_path):
117
- """
118
- Loads a MIDI file and extracts note/control events,
119
- ensuring compatibility with `midi_to_events()`.
120
-
121
- Args:
122
- input_midi_path (str): Path to the MIDI file.
123
-
124
- Returns:
125
- List of MIDI messages that can be passed directly to `midi_to_events()`.
126
- """
127
- try:
128
- midi_obj = mido.MidiFile(input_midi_path)
129
- midi_events = [
130
- msg for track in midi_obj.tracks
131
- for msg in track if msg.type in ["note_on", "note_off", "control_change"]
132
- ]
133
-
134
- return midi_events
135
-
136
- except Exception as e:
137
- raise RuntimeError(f"Error processing MIDI file: {str(e)}")
138
-
139
-
140
- # Generate Accompaniment Using ZeroGPU
141
- #@spaces.GPU
142
- def process_fn(input_midi_path, model_choice, selected_midi_program):
143
- start_time = time.time() # Track performance
144
-
145
- # Ensure MIDI file exists
146
- if not input_midi_path or not isinstance(input_midi_path, str):
147
- raise ValueError("Invalid MIDI input. Expected a valid file path.")
148
-
149
- if not os.path.exists(input_midi_path):
150
- raise FileNotFoundError(f"MIDI file not found: {input_midi_path}")
151
-
152
- print(f"[{time.time() - start_time:.2f}s] File check complete.")
153
-
154
- # Load AMT Model (Cached)
155
- model = load_amt_model(model_choice)
156
- print(f"[{time.time() - start_time:.2f}s] Model loaded.")
157
-
158
- # extract midi events
159
- midi_tokenize_time = time.time()
160
- midi_events = extract_midi_events(input_midi_path)
161
- print(f"[{time.time() - start_time:.2f}s] Tokenized MIDI file.")
162
-
163
- # Convert MIDI events to tokens
164
- events_conversion_time = time.time()
165
- events = midi_to_events(midi_events)
166
- print(f"[{time.time() - start_time:.2f}s] Converted MIDI to events.")
167
-
168
- total_time = round(ops.max_time(events, seconds=True))
169
- events, melody = extract_instruments(events, [selected_midi_program])
170
-
171
- # ✅ Fix: Convert `history` from list to tensor before sending to GPU
172
- history = ops.clip(events, 0, 5, clip_duration=False)
173
- history = torch.tensor(history, dtype=torch.long, device=device)
174
-
175
- # ✅ Debug: Ensure all token indices are within model's vocab size
176
- vocab_size = model.config.vocab_size # Get the model's vocabulary size
177
-
178
- if torch.any(history >= vocab_size) or torch.any(history < 0):
179
- raise ValueError(
180
- f"Invalid token indices detected! Ensure all tokens are in range [0, {vocab_size-1}]."
181
- )
182
-
183
- # ✅ Run inference on GPU
184
- model_inference_time = time.time()
185
- accompaniment = generate(model, 5, total_time, inputs=history, controls=None, top_p=0.95, debug=False)
186
- print(f"[{time.time() - start_time:.2f}s] Accompaniment generated.")
187
-
188
- # ✅ Combine accompaniment with melody
189
- output_events = ops.clip(ops.combine(accompaniment, melody), 0, total_time, clip_duration=True)
190
-
191
- # ✅ Convert back to MIDI
192
- midi_conversion_time = time.time()
193
- output_midi_path = save_midi(events_to_midi(output_events), None)
194
- print(f"[{time.time() - start_time:.2f}s] Converted events back to MIDI.")
195
-
196
- # ✅ Ensure MIDI output exists
197
- if not output_midi_path or not os.path.exists(output_midi_path):
198
- raise RuntimeError("Failed to generate output MIDI file.")
199
-
200
- print(f"Total inference time: {time.time() - start_time:.2f} seconds.")
201
-
202
- output_labels = LabelList()
203
- return output_midi_path, output_labels
204
- '''
205
-
206
-
207
- '''
208
-
209
- # === Build Gradio Endpoint ===
210
- with gr.Blocks() as demo:
211
- model_dropdown = gr.Dropdown(
212
- choices=[SMALL_MODEL, MEDIUM_MODEL, LARGE_MODEL],
213
- value=MEDIUM_MODEL,
214
- label="Select AMT Model (Faster vs. Higher Quality)"
215
- )
216
-
217
- selected_midi_program = gr.Slider(
218
- 0, 127, step=1, value=53, label="Select Melody Instrument (MIDI Program Number)"
219
- )
220
-
221
- # Enable Gradio queueing to prevent GPU task abortion
222
- demo.queue(max_size=10) # Allowing multiple users while reducing reloads
223
-
224
- # Build HARP App
225
- app = build_endpoint(
226
- model_card=model_card,
227
- components=[model_dropdown, selected_midi_program],
228
- process_fn=process_fn
229
- )
230
-
231
- demo.launch(share=True, show_error=True)
232
- '''
 
111
 
112
 
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -15,3 +15,4 @@ numpy<2
15
  scipy
16
  soundfile
17
  hydra-core>=1.1
 
 
15
  scipy
16
  soundfile
17
  hydra-core>=1.1
18
+ transformers