Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
07e756d
1
Parent(s):
4504581
giving generated midi a unique name
Browse files
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 😻
|
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
short_description: Wrapped text2midi model from amaai-lab into HARP V3
|
|
|
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.28.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
short_description: Wrapped text2midi model from amaai-lab into HARP V3
|
app.py
CHANGED
|
@@ -8,6 +8,8 @@ import gradio as gr
|
|
| 8 |
from dataclasses import asdict
|
| 9 |
from transformers import T5Tokenizer
|
| 10 |
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
| 11 |
|
| 12 |
from transformer_model import Transformer
|
| 13 |
from pyharp.core import ModelCard, build_endpoint
|
|
@@ -34,6 +36,11 @@ def save_wav(midi_path: str) -> str:
|
|
| 34 |
subprocess.run(cmd, shell=True, check=False)
|
| 35 |
return wav_filepath
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# Core Text -> MIDI
|
| 39 |
def generate_midi(prompt: str, temperature: float = 0.9, max_len: int = 500) -> str:
|
|
@@ -70,7 +77,7 @@ def generate_midi(prompt: str, temperature: float = 0.9, max_len: int = 500) ->
|
|
| 70 |
output_list = output[0].tolist()
|
| 71 |
generated_midi = r_tokenizer.decode(output_list)
|
| 72 |
|
| 73 |
-
midi_path = "
|
| 74 |
generated_midi.dump_midi(midi_path)
|
| 75 |
return midi_path
|
| 76 |
|
|
|
|
| 8 |
from dataclasses import asdict
|
| 9 |
from transformers import T5Tokenizer
|
| 10 |
from huggingface_hub import hf_hub_download
|
| 11 |
+
from time import time_ns
|
| 12 |
+
from uuid import uuid4
|
| 13 |
|
| 14 |
from transformer_model import Transformer
|
| 15 |
from pyharp.core import ModelCard, build_endpoint
|
|
|
|
| 36 |
subprocess.run(cmd, shell=True, check=False)
|
| 37 |
return wav_filepath
|
| 38 |
|
| 39 |
+
# Helpers
|
| 40 |
+
def _unique_path(ext: str) -> str:
|
| 41 |
+
"""Create a unique file path in /tmp to avoid naming collisions."""
|
| 42 |
+
return os.path.join("/tmp", f"t2m_{time_ns()}_{uuid4().hex[:8]}{ext}")
|
| 43 |
+
|
| 44 |
|
| 45 |
# Core Text -> MIDI
|
| 46 |
def generate_midi(prompt: str, temperature: float = 0.9, max_len: int = 500) -> str:
|
|
|
|
| 77 |
output_list = output[0].tolist()
|
| 78 |
generated_midi = r_tokenizer.decode(output_list)
|
| 79 |
|
| 80 |
+
midi_path = _unique_path(".mid")
|
| 81 |
generated_midi.dump_midi(midi_path)
|
| 82 |
return midi_path
|
| 83 |
|