Spaces:
Sleeping
Sleeping
Fix codes issues around playback
Browse files- .vscode/launch.json +17 -0
- app.py +0 -7
- processor.py +3 -3
.vscode/launch.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
// Use IntelliSense to learn about possible attributes.
|
| 3 |
+
// Hover to view descriptions of existing attributes.
|
| 4 |
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
| 5 |
+
"version": "0.2.0",
|
| 6 |
+
"configurations": [
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
{
|
| 10 |
+
"name": "Python Debugger: Current File",
|
| 11 |
+
"type": "debugpy",
|
| 12 |
+
"request": "launch",
|
| 13 |
+
"program": "${file}",
|
| 14 |
+
"console": "integratedTerminal"
|
| 15 |
+
}
|
| 16 |
+
]
|
| 17 |
+
}
|
app.py
CHANGED
|
@@ -19,13 +19,6 @@ with gr.Blocks(title="MIDI Jam Session") as demo:
|
|
| 19 |
5. **""" + model_location_repo + """** - The MIDI is processed using a transformer model to generate new content based on your input
|
| 20 |
6. **Listen to the result** - The generated MIDI content is played back
|
| 21 |
|
| 22 |
-
## How it works
|
| 23 |
-
|
| 24 |
-
- The frontend uses the **Web MIDI API** to capture live MIDI input
|
| 25 |
-
- After 5 seconds of inactivity, the recording is converted to a MIDI file using **@tonejs/midi**
|
| 26 |
-
- The backend receives the MIDI file and can process the midi however you like.
|
| 27 |
-
- In this case it uses a transformer model to generate new MIDI content based on the input
|
| 28 |
-
- The processed MIDI is sent back and played on your selected output device
|
| 29 |
""")
|
| 30 |
|
| 31 |
midi_session = MIDIBridge(
|
|
|
|
| 19 |
5. **""" + model_location_repo + """** - The MIDI is processed using a transformer model to generate new content based on your input
|
| 20 |
6. **Listen to the result** - The generated MIDI content is played back
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
""")
|
| 23 |
|
| 24 |
midi_session = MIDIBridge(
|
processor.py
CHANGED
|
@@ -58,7 +58,7 @@ class Processor:
|
|
| 58 |
input_ids = input_ids[-max_len:]
|
| 59 |
|
| 60 |
tensor_sequence = torch.tensor([input_ids], dtype=torch.long)
|
| 61 |
-
print(f"
|
| 62 |
input_token_length = tensor_sequence.shape[1]
|
| 63 |
|
| 64 |
# Generate the new token sequence
|
|
@@ -67,12 +67,12 @@ class Processor:
|
|
| 67 |
generation_config=self.generation_config)
|
| 68 |
|
| 69 |
print("Generated Output Shape", res.shape)
|
| 70 |
-
print(f"New tokens length: {
|
| 71 |
|
| 72 |
# Decode the generated tokens (excluding the input part)
|
| 73 |
decoded = self.tokenizer.decode([res[0][input_token_length:]])
|
| 74 |
|
| 75 |
-
return decoded.
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
print(f"Error processing MIDI: {e}")
|
|
|
|
| 58 |
input_ids = input_ids[-max_len:]
|
| 59 |
|
| 60 |
tensor_sequence = torch.tensor([input_ids], dtype=torch.long)
|
| 61 |
+
print(f"input tensor shape: {tensor_sequence.shape}")
|
| 62 |
input_token_length = tensor_sequence.shape[1]
|
| 63 |
|
| 64 |
# Generate the new token sequence
|
|
|
|
| 67 |
generation_config=self.generation_config)
|
| 68 |
|
| 69 |
print("Generated Output Shape", res.shape)
|
| 70 |
+
print(f"New tokens length: {res.shape[1] - input_token_length}")
|
| 71 |
|
| 72 |
# Decode the generated tokens (excluding the input part)
|
| 73 |
decoded = self.tokenizer.decode([res[0][input_token_length:]])
|
| 74 |
|
| 75 |
+
return decoded.dumps_midi()
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
print(f"Error processing MIDI: {e}")
|