run formatter
This commit is contained in:
@@ -65,7 +65,7 @@ Both scripts share the same arguments (except for `--fp8` quantization, which on
|
|||||||
### Example 1: Single prompt (use transformers)
|
### Example 1: Single prompt (use transformers)
|
||||||
```bash
|
```bash
|
||||||
python generate_transformers.py \
|
python generate_transformers.py \
|
||||||
--prompt "A cheerful piano melody"
|
--prompt "A cheerful rock song with bright electric guitars"
|
||||||
```
|
```
|
||||||
Outputs 4 MIDIs (and synthesized MP3s) conditioned on the same prompt by default.
|
Outputs 4 MIDIs (and synthesized MP3s) conditioned on the same prompt by default.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
Rock piece suitable for a hero's epic battle against a dark villain. The music is rich with synth leads, brass section, and heavy drums.
|
|
||||||
A sad and emotional song featuring relentless, heartbreaking acoustic guitars.
|
|
||||||
Slow and loving music that is best for a romantic film. The piano and string ensemble give a classical vibe.
|
|
||||||
An energetic and motivating pop song you love to hear on a long road trip.
|
|
||||||
Upbeat and playful jazz music with lively saxophones, like you're going out on a Sunday picnic.
|
|
||||||
+31
-32
@@ -222,7 +222,7 @@ Examples:
|
|||||||
--prompts_file prompts.txt
|
--prompts_file prompts.txt
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
# Required arguments
|
# Required arguments
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--model",
|
"--model",
|
||||||
@@ -230,7 +230,7 @@ Examples:
|
|||||||
default="slseanwu/MIDI-LLM_Llama-3.2-1B",
|
default="slseanwu/MIDI-LLM_Llama-3.2-1B",
|
||||||
help="Path to MIDI-LLM model checkpoint, can be HuggingFace model ID or local path (default: slseanwu/MIDI-LLM_Llama-3.2-1B)"
|
help="Path to MIDI-LLM model checkpoint, can be HuggingFace model ID or local path (default: slseanwu/MIDI-LLM_Llama-3.2-1B)"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Input arguments (not required if using --interactive only)
|
# Input arguments (not required if using --interactive only)
|
||||||
input_group = parser.add_mutually_exclusive_group(required=False)
|
input_group = parser.add_mutually_exclusive_group(required=False)
|
||||||
input_group.add_argument(
|
input_group.add_argument(
|
||||||
@@ -243,7 +243,7 @@ Examples:
|
|||||||
type=str,
|
type=str,
|
||||||
help="Path to file containing prompts (one per line)"
|
help="Path to file containing prompts (one per line)"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Output arguments
|
# Output arguments
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--output_root",
|
"--output_root",
|
||||||
@@ -257,7 +257,7 @@ Examples:
|
|||||||
default=DEFAULT_N_OUTPUTS,
|
default=DEFAULT_N_OUTPUTS,
|
||||||
help=f"Number of outputs to generate per prompt (default: {DEFAULT_N_OUTPUTS})"
|
help=f"Number of outputs to generate per prompt (default: {DEFAULT_N_OUTPUTS})"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Synthesis arguments
|
# Synthesis arguments
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--no-synthesize",
|
"--no-synthesize",
|
||||||
@@ -272,7 +272,7 @@ Examples:
|
|||||||
default="./soundfonts/FluidR3_GM/FluidR3_GM.sf2",
|
default="./soundfonts/FluidR3_GM/FluidR3_GM.sf2",
|
||||||
help="Path to SoundFont file for synthesis (default: ./soundfonts/FluidR3_GM/FluidR3_GM.sf2)"
|
help="Path to SoundFont file for synthesis (default: ./soundfonts/FluidR3_GM/FluidR3_GM.sf2)"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generation parameters
|
# Generation parameters
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--temperature",
|
"--temperature",
|
||||||
@@ -292,7 +292,7 @@ Examples:
|
|||||||
default=DEFAULT_MAX_TOKENS,
|
default=DEFAULT_MAX_TOKENS,
|
||||||
help=f"Maximum tokens to generate (default: {DEFAULT_MAX_TOKENS})"
|
help=f"Maximum tokens to generate (default: {DEFAULT_MAX_TOKENS})"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Model arguments
|
# Model arguments
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--cache_dir",
|
"--cache_dir",
|
||||||
@@ -305,13 +305,13 @@ Examples:
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Enter interactive mode after initial generation (keep generating until empty prompt)"
|
help="Enter interactive mode after initial generation (keep generating until empty prompt)"
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Validate that either prompts are provided or interactive mode is enabled
|
# Validate that either prompts are provided or interactive mode is enabled
|
||||||
if not args.prompt and not args.prompts_file and not args.interactive:
|
if not args.prompt and not args.prompts_file and not args.interactive:
|
||||||
parser.error("Either --prompt, --prompts_file, or --interactive must be specified")
|
parser.error("Either --prompt, --prompts_file, or --interactive must be specified")
|
||||||
|
|
||||||
# Load prompts (if provided)
|
# Load prompts (if provided)
|
||||||
prompts = []
|
prompts = []
|
||||||
if args.prompt:
|
if args.prompt:
|
||||||
@@ -320,7 +320,7 @@ Examples:
|
|||||||
with open(args.prompts_file, "r") as f:
|
with open(args.prompts_file, "r") as f:
|
||||||
prompts = [line.strip() for line in f if line.strip()]
|
prompts = [line.strip() for line in f if line.strip()]
|
||||||
print(f"Loaded {len(prompts)} prompts from {args.prompts_file}")
|
print(f"Loaded {len(prompts)} prompts from {args.prompts_file}")
|
||||||
|
|
||||||
# Check synthesis requirements
|
# Check synthesis requirements
|
||||||
if args.synthesize:
|
if args.synthesize:
|
||||||
soundfont_path = Path(args.soundfont)
|
soundfont_path = Path(args.soundfont)
|
||||||
@@ -329,31 +329,31 @@ Examples:
|
|||||||
print("Please download a SoundFont or disable synthesis")
|
print("Please download a SoundFont or disable synthesis")
|
||||||
import sys
|
import sys
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Create output root directory with timestamp
|
# Create output root directory with timestamp
|
||||||
output_root = Path(args.output_root)
|
output_root = Path(args.output_root)
|
||||||
session_timestamp = datetime.now().strftime("%Y-%m-%d_%H%M%S")
|
session_timestamp = datetime.now().strftime("%Y-%m-%d_%H%M%S")
|
||||||
output_dir = output_root / session_timestamp
|
output_dir = output_root / session_timestamp
|
||||||
output_dir.mkdir(parents=True, exist_ok=True)
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
print(f"Output directory: {output_dir.absolute()}\n")
|
print(f"Output directory: {output_dir.absolute()}\n")
|
||||||
|
|
||||||
# Load tokenizer from the model checkpoint
|
# Load tokenizer from the model checkpoint
|
||||||
print("Loading tokenizer...")
|
print("Loading tokenizer and model...")
|
||||||
tokenizer = AutoTokenizer.from_pretrained(
|
tokenizer = AutoTokenizer.from_pretrained(
|
||||||
args.model,
|
args.model,
|
||||||
cache_dir=args.cache_dir,
|
cache_dir=args.cache_dir,
|
||||||
pad_token="<|eot_id|>",
|
pad_token="<|eot_id|>",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load model
|
# Load model
|
||||||
model = prepare_hf_model(model_path=args.model)
|
model = prepare_hf_model(model_path=args.model)
|
||||||
|
|
||||||
# Generate from initial prompts (if provided)
|
# Generate from initial prompts (if provided)
|
||||||
if prompts:
|
if prompts:
|
||||||
print(f"Starting generation for {len(prompts)} prompt(s)...\n")
|
print(f"Starting generation for {len(prompts)} prompt(s)...\n")
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
stats = generate_from_prompts_hf(
|
stats = generate_from_prompts_hf(
|
||||||
model=model,
|
model=model,
|
||||||
tokenizer=tokenizer,
|
tokenizer=tokenizer,
|
||||||
@@ -367,9 +367,9 @@ Examples:
|
|||||||
max_tokens=args.max_tokens,
|
max_tokens=args.max_tokens,
|
||||||
n_outputs=args.n_outputs
|
n_outputs=args.n_outputs
|
||||||
)
|
)
|
||||||
|
|
||||||
total_time = time.time() - start_time
|
total_time = time.time() - start_time
|
||||||
|
|
||||||
# Print summary
|
# Print summary
|
||||||
print(f"\n{'='*70}")
|
print(f"\n{'='*70}")
|
||||||
print("Generation Summary")
|
print("Generation Summary")
|
||||||
@@ -378,22 +378,22 @@ Examples:
|
|||||||
print(f"Successful generations: {stats['successful_generations']}")
|
print(f"Successful generations: {stats['successful_generations']}")
|
||||||
print(f"Failed generations: {stats['failed_generations']}")
|
print(f"Failed generations: {stats['failed_generations']}")
|
||||||
print(f"Total time: {total_time:.2f}s")
|
print(f"Total time: {total_time:.2f}s")
|
||||||
|
|
||||||
if stats['generation_times']:
|
if stats['generation_times']:
|
||||||
avg_time = sum(stats['generation_times']) / len(stats['generation_times'])
|
avg_time = sum(stats['generation_times']) / len(stats['generation_times'])
|
||||||
print(f"Average generation time: {avg_time:.2f}s (excluding warmup)")
|
print(f"Average generation time: {avg_time:.2f}s (excluding warmup)")
|
||||||
|
|
||||||
print(f"\nOutputs saved to: {output_dir.absolute()}")
|
print(f"\nOutputs saved to: {output_dir.absolute()}")
|
||||||
|
|
||||||
# Print generated files
|
# Print generated files
|
||||||
if stats['output_files']:
|
if stats['output_files']:
|
||||||
print(f"\nGenerated files:")
|
print(f"\nGenerated files:")
|
||||||
for file_path in stats['output_files']:
|
for file_path in stats['output_files']:
|
||||||
file_type = "🎵 MIDI" if file_path.endswith('.mid') else "🎧 Audio"
|
file_type = "🎵 MIDI" if file_path.endswith('.mid') else "🎧 Audio"
|
||||||
print(f" {file_type}: {file_path}")
|
print(f" {file_type}: {file_path}")
|
||||||
|
|
||||||
print(f"{'='*70}\n")
|
print(f"{'='*70}\n")
|
||||||
|
|
||||||
# Save stats to JSON
|
# Save stats to JSON
|
||||||
stats_file = output_dir / "generation_stats.json"
|
stats_file = output_dir / "generation_stats.json"
|
||||||
with open(stats_file, "w") as f:
|
with open(stats_file, "w") as f:
|
||||||
@@ -411,7 +411,7 @@ Examples:
|
|||||||
}, f, indent=2)
|
}, f, indent=2)
|
||||||
else:
|
else:
|
||||||
print(f"No initial prompts provided. Starting in interactive mode...\n")
|
print(f"No initial prompts provided. Starting in interactive mode...\n")
|
||||||
|
|
||||||
# Interactive mode
|
# Interactive mode
|
||||||
if args.interactive:
|
if args.interactive:
|
||||||
print(f"\n{'='*70}")
|
print(f"\n{'='*70}")
|
||||||
@@ -419,17 +419,17 @@ Examples:
|
|||||||
print(f"{'='*70}")
|
print(f"{'='*70}")
|
||||||
print("Enter prompts to generate more MIDI files.")
|
print("Enter prompts to generate more MIDI files.")
|
||||||
print("Press Enter with empty prompt to exit.\n")
|
print("Press Enter with empty prompt to exit.\n")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
# Get user input
|
# Get user input
|
||||||
user_prompt = input("Prompt: ").strip()
|
user_prompt = input("Prompt: ").strip()
|
||||||
|
|
||||||
# Exit if empty
|
# Exit if empty
|
||||||
if not user_prompt:
|
if not user_prompt:
|
||||||
print("\nExiting interactive mode. Goodbye!")
|
print("\nExiting interactive mode. Goodbye!")
|
||||||
break
|
break
|
||||||
|
|
||||||
# Generate from the new prompt
|
# Generate from the new prompt
|
||||||
print()
|
print()
|
||||||
interactive_stats = generate_from_prompts_hf(
|
interactive_stats = generate_from_prompts_hf(
|
||||||
@@ -448,19 +448,19 @@ Examples:
|
|||||||
|
|
||||||
# Print input prompt
|
# Print input prompt
|
||||||
print(f"Input prompt: {user_prompt}")
|
print(f"Input prompt: {user_prompt}")
|
||||||
|
|
||||||
# Print mini summary
|
# Print mini summary
|
||||||
print(f"\n✓ Generated {interactive_stats['successful_generations']}/{args.n_outputs} outputs")
|
print(f"\n✓ Generated {interactive_stats['successful_generations']}/{args.n_outputs} outputs")
|
||||||
if interactive_stats['generation_times']:
|
if interactive_stats['generation_times']:
|
||||||
print(f" Generation time: {interactive_stats['generation_times'][0]:.2f}s")
|
print(f" Generation time: {interactive_stats['generation_times'][0]:.2f}s")
|
||||||
|
|
||||||
# Print file paths
|
# Print file paths
|
||||||
if interactive_stats['output_files']:
|
if interactive_stats['output_files']:
|
||||||
for file_path in interactive_stats['output_files']:
|
for file_path in interactive_stats['output_files']:
|
||||||
file_type = "🎵" if file_path.endswith('.mid') else "🎧"
|
file_type = "🎵" if file_path.endswith('.mid') else "🎧"
|
||||||
print(f" {file_type} {file_path}")
|
print(f" {file_type} {file_path}")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\n\nInterrupted. Exiting interactive mode.")
|
print("\n\nInterrupted. Exiting interactive mode.")
|
||||||
break
|
break
|
||||||
@@ -471,4 +471,3 @@ Examples:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
+32
-32
@@ -232,7 +232,7 @@ Examples:
|
|||||||
--top_p 0.98
|
--top_p 0.98
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
# Required arguments
|
# Required arguments
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--model",
|
"--model",
|
||||||
@@ -240,7 +240,7 @@ Examples:
|
|||||||
default="slseanwu/MIDI-LLM_Llama-3.2-1B",
|
default="slseanwu/MIDI-LLM_Llama-3.2-1B",
|
||||||
help="Path to MIDI-LLM model checkpoint, can be HuggingFace model ID or local path (default: slseanwu/MIDI-LLM_Llama-3.2-1B)"
|
help="Path to MIDI-LLM model checkpoint, can be HuggingFace model ID or local path (default: slseanwu/MIDI-LLM_Llama-3.2-1B)"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Input arguments (not required if using --interactive only)
|
# Input arguments (not required if using --interactive only)
|
||||||
input_group = parser.add_mutually_exclusive_group(required=False)
|
input_group = parser.add_mutually_exclusive_group(required=False)
|
||||||
input_group.add_argument(
|
input_group.add_argument(
|
||||||
@@ -253,7 +253,7 @@ Examples:
|
|||||||
type=str,
|
type=str,
|
||||||
help="Path to file containing prompts (one per line)"
|
help="Path to file containing prompts (one per line)"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Output arguments
|
# Output arguments
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--output_root",
|
"--output_root",
|
||||||
@@ -267,7 +267,7 @@ Examples:
|
|||||||
default=DEFAULT_N_OUTPUTS,
|
default=DEFAULT_N_OUTPUTS,
|
||||||
help=f"Number of outputs to generate per prompt (default: {DEFAULT_N_OUTPUTS})"
|
help=f"Number of outputs to generate per prompt (default: {DEFAULT_N_OUTPUTS})"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Synthesis arguments
|
# Synthesis arguments
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--no-synthesize",
|
"--no-synthesize",
|
||||||
@@ -282,7 +282,7 @@ Examples:
|
|||||||
default="./soundfonts/FluidR3_GM/FluidR3_GM.sf2",
|
default="./soundfonts/FluidR3_GM/FluidR3_GM.sf2",
|
||||||
help="Path to SoundFont file for synthesis (default: ./soundfonts/FluidR3_GM/FluidR3_GM.sf2)"
|
help="Path to SoundFont file for synthesis (default: ./soundfonts/FluidR3_GM/FluidR3_GM.sf2)"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generation parameters
|
# Generation parameters
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--temperature",
|
"--temperature",
|
||||||
@@ -302,7 +302,7 @@ Examples:
|
|||||||
default=DEFAULT_MAX_TOKENS,
|
default=DEFAULT_MAX_TOKENS,
|
||||||
help=f"Maximum tokens to generate (default: {DEFAULT_MAX_TOKENS})"
|
help=f"Maximum tokens to generate (default: {DEFAULT_MAX_TOKENS})"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Model arguments
|
# Model arguments
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--fp8",
|
"--fp8",
|
||||||
@@ -326,13 +326,13 @@ Examples:
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Enter interactive mode after initial generation (keep generating until empty prompt)"
|
help="Enter interactive mode after initial generation (keep generating until empty prompt)"
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Validate that either prompts are provided or interactive mode is enabled
|
# Validate that either prompts are provided or interactive mode is enabled
|
||||||
if not args.prompt and not args.prompts_file and not args.interactive:
|
if not args.prompt and not args.prompts_file and not args.interactive:
|
||||||
parser.error("Either --prompt, --prompts_file, or --interactive must be specified")
|
parser.error("Either --prompt, --prompts_file, or --interactive must be specified")
|
||||||
|
|
||||||
# Load prompts (if provided)
|
# Load prompts (if provided)
|
||||||
prompts = []
|
prompts = []
|
||||||
if args.prompt:
|
if args.prompt:
|
||||||
@@ -341,7 +341,7 @@ Examples:
|
|||||||
with open(args.prompts_file, "r") as f:
|
with open(args.prompts_file, "r") as f:
|
||||||
prompts = [line.strip() for line in f if line.strip()]
|
prompts = [line.strip() for line in f if line.strip()]
|
||||||
print(f"Loaded {len(prompts)} prompts from {args.prompts_file}")
|
print(f"Loaded {len(prompts)} prompts from {args.prompts_file}")
|
||||||
|
|
||||||
# Check synthesis requirements
|
# Check synthesis requirements
|
||||||
if args.synthesize:
|
if args.synthesize:
|
||||||
soundfont_path = Path(args.soundfont)
|
soundfont_path = Path(args.soundfont)
|
||||||
@@ -349,30 +349,30 @@ Examples:
|
|||||||
print(f"Error: SoundFont not found at {soundfont_path}")
|
print(f"Error: SoundFont not found at {soundfont_path}")
|
||||||
print("Please download a SoundFont or disable synthesis with --no-synthesize")
|
print("Please download a SoundFont or disable synthesis with --no-synthesize")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not SYNTHESIS_AVAILABLE:
|
if not SYNTHESIS_AVAILABLE:
|
||||||
print("Warning: Audio synthesis libraries not available.")
|
print("Warning: Audio synthesis libraries not available.")
|
||||||
print("Synthesis will be skipped. Install dependencies:")
|
print("Synthesis will be skipped. Install dependencies:")
|
||||||
print(" conda install conda-forge::fluidsynth conda-forge::ffmpeg")
|
print(" conda install conda-forge::fluidsynth conda-forge::ffmpeg")
|
||||||
print(" pip install midi2audio librosa soundfile")
|
print(" pip install midi2audio librosa soundfile")
|
||||||
args.synthesize = False
|
args.synthesize = False
|
||||||
|
|
||||||
# Create output root directory with timestamp
|
# Create output root directory with timestamp
|
||||||
output_root = Path(args.output_root)
|
output_root = Path(args.output_root)
|
||||||
session_timestamp = datetime.now().strftime("%Y-%m-%d_%H%M%S")
|
session_timestamp = datetime.now().strftime("%Y-%m-%d_%H%M%S")
|
||||||
output_dir = output_root / session_timestamp
|
output_dir = output_root / session_timestamp
|
||||||
output_dir.mkdir(parents=True, exist_ok=True)
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
print(f"Output directory: {output_dir.absolute()}\n")
|
print(f"Output directory: {output_dir.absolute()}\n")
|
||||||
|
|
||||||
# Load tokenizer from the model checkpoint (not base Llama!)
|
# Load tokenizer from the model checkpoint (not base Llama!)
|
||||||
print("Loading tokenizer...")
|
print("Loading tokenizer and model...")
|
||||||
tokenizer = AutoTokenizer.from_pretrained(
|
tokenizer = AutoTokenizer.from_pretrained(
|
||||||
args.model, # Use the model checkpoint path, not base Llama
|
args.model, # Use the model checkpoint path, not base Llama
|
||||||
cache_dir=args.cache_dir,
|
cache_dir=args.cache_dir,
|
||||||
pad_token="<|eot_id|>",
|
pad_token="<|eot_id|>",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load model
|
# Load model
|
||||||
model, sampling_params = prepare_vllm_model(
|
model, sampling_params = prepare_vllm_model(
|
||||||
model_path=args.model,
|
model_path=args.model,
|
||||||
@@ -383,12 +383,12 @@ Examples:
|
|||||||
do_fp8_quantization=args.fp8,
|
do_fp8_quantization=args.fp8,
|
||||||
gpu_memory_utilization=args.gpu_memory
|
gpu_memory_utilization=args.gpu_memory
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate from initial prompts (if provided)
|
# Generate from initial prompts (if provided)
|
||||||
if prompts:
|
if prompts:
|
||||||
print(f"Starting generation for {len(prompts)} prompt(s)...\n")
|
print(f"Starting generation for {len(prompts)} prompt(s)...\n")
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
stats = generate_from_prompts(
|
stats = generate_from_prompts(
|
||||||
model=model,
|
model=model,
|
||||||
tokenizer=tokenizer,
|
tokenizer=tokenizer,
|
||||||
@@ -398,9 +398,9 @@ Examples:
|
|||||||
soundfont_path=args.soundfont if args.synthesize else None,
|
soundfont_path=args.soundfont if args.synthesize else None,
|
||||||
synthesize=args.synthesize
|
synthesize=args.synthesize
|
||||||
)
|
)
|
||||||
|
|
||||||
total_time = time.time() - start_time
|
total_time = time.time() - start_time
|
||||||
|
|
||||||
# Print summary
|
# Print summary
|
||||||
print(f"\n{'='*70}")
|
print(f"\n{'='*70}")
|
||||||
print("Generation Summary")
|
print("Generation Summary")
|
||||||
@@ -409,22 +409,22 @@ Examples:
|
|||||||
print(f"Successful generations: {stats['successful_generations']}")
|
print(f"Successful generations: {stats['successful_generations']}")
|
||||||
print(f"Failed generations: {stats['failed_generations']}")
|
print(f"Failed generations: {stats['failed_generations']}")
|
||||||
print(f"Total time: {total_time:.2f}s")
|
print(f"Total time: {total_time:.2f}s")
|
||||||
|
|
||||||
if stats['generation_times']:
|
if stats['generation_times']:
|
||||||
avg_time = sum(stats['generation_times']) / len(stats['generation_times'])
|
avg_time = sum(stats['generation_times']) / len(stats['generation_times'])
|
||||||
print(f"Average generation time: {avg_time:.2f}s (excluding warmup)")
|
print(f"Average generation time: {avg_time:.2f}s (excluding warmup)")
|
||||||
|
|
||||||
print(f"\nOutputs saved to: {output_dir.absolute()}")
|
print(f"\nOutputs saved to: {output_dir.absolute()}")
|
||||||
|
|
||||||
# Print generated files
|
# Print generated files
|
||||||
if stats['output_files']:
|
if stats['output_files']:
|
||||||
print(f"\nGenerated files:")
|
print(f"\nGenerated files:")
|
||||||
for file_path in stats['output_files']:
|
for file_path in stats['output_files']:
|
||||||
file_type = "🎵 MIDI" if file_path.endswith('.mid') else "🎧 Audio"
|
file_type = "🎵 MIDI" if file_path.endswith('.mid') else "🎧 Audio"
|
||||||
print(f" {file_type}: {file_path}")
|
print(f" {file_type}: {file_path}")
|
||||||
|
|
||||||
print(f"{'='*70}\n")
|
print(f"{'='*70}\n")
|
||||||
|
|
||||||
# Save stats to JSON
|
# Save stats to JSON
|
||||||
stats_file = output_dir / "generation_stats.json"
|
stats_file = output_dir / "generation_stats.json"
|
||||||
with open(stats_file, "w") as f:
|
with open(stats_file, "w") as f:
|
||||||
@@ -443,7 +443,7 @@ Examples:
|
|||||||
}, f, indent=2)
|
}, f, indent=2)
|
||||||
else:
|
else:
|
||||||
print(f"No initial prompts provided. Starting in interactive mode...\n")
|
print(f"No initial prompts provided. Starting in interactive mode...\n")
|
||||||
|
|
||||||
# Interactive mode
|
# Interactive mode
|
||||||
if args.interactive:
|
if args.interactive:
|
||||||
print(f"\n{'='*70}")
|
print(f"\n{'='*70}")
|
||||||
@@ -451,17 +451,17 @@ Examples:
|
|||||||
print(f"{'='*70}")
|
print(f"{'='*70}")
|
||||||
print("Enter prompts to generate more MIDI files.")
|
print("Enter prompts to generate more MIDI files.")
|
||||||
print("Press Enter with empty prompt to exit.\n")
|
print("Press Enter with empty prompt to exit.\n")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
# Get user input
|
# Get user input
|
||||||
user_prompt = input("Prompt: ").strip()
|
user_prompt = input("Prompt: ").strip()
|
||||||
|
|
||||||
# Exit if empty
|
# Exit if empty
|
||||||
if not user_prompt:
|
if not user_prompt:
|
||||||
print("\nExiting interactive mode. Goodbye!")
|
print("\nExiting interactive mode. Goodbye!")
|
||||||
break
|
break
|
||||||
|
|
||||||
# Generate from the new prompt
|
# Generate from the new prompt
|
||||||
print()
|
print()
|
||||||
interactive_stats = generate_from_prompts(
|
interactive_stats = generate_from_prompts(
|
||||||
@@ -476,19 +476,19 @@ Examples:
|
|||||||
|
|
||||||
# Print input prompt
|
# Print input prompt
|
||||||
print(f"Input prompt: {user_prompt}")
|
print(f"Input prompt: {user_prompt}")
|
||||||
|
|
||||||
# Print mini summary
|
# Print mini summary
|
||||||
print(f"\n✓ Generated {interactive_stats['successful_generations']}/{args.n_outputs} outputs")
|
print(f"\n✓ Generated {interactive_stats['successful_generations']}/{args.n_outputs} outputs")
|
||||||
if interactive_stats['generation_times']:
|
if interactive_stats['generation_times']:
|
||||||
print(f" Generation time: {interactive_stats['generation_times'][0]:.2f}s")
|
print(f" Generation time: {interactive_stats['generation_times'][0]:.2f}s")
|
||||||
|
|
||||||
# Print file paths
|
# Print file paths
|
||||||
if interactive_stats['output_files']:
|
if interactive_stats['output_files']:
|
||||||
for file_path in interactive_stats['output_files']:
|
for file_path in interactive_stats['output_files']:
|
||||||
file_type = "🎵" if file_path.endswith('.mid') else "🎧"
|
file_type = "🎵" if file_path.endswith('.mid') else "🎧"
|
||||||
print(f" {file_type} {file_path}")
|
print(f" {file_type} {file_path}")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\n\nInterrupted. Exiting interactive mode.")
|
print("\n\nInterrupted. Exiting interactive mode.")
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user