Views
No views yet
1conda create -n ScrapeGoatMusic python=3.8
2conda activate ScrapeGoatMusicconda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia1pip install descript-audio-codec
2pip install npy_append_array soundfile
3pip install fastapi uvicorn python-multipart
4pip install flash-attn --no-build-isolation1cd inference/xcodec_mini_infer
2git clone https://github.com/mct10/RepCodec.git
3cd RepCodec
4pip install .1# Download models from Hugging Face
2git lfs install
3cd inference
4git clone scrapegoat/Neural-Audio-Codecapi.py:1from fastapi import FastAPI, UploadFile, File, Form
2from fastapi.responses import FileResponse
3import uvicorn
4import torch
5import os
6import argparse
7from pathlib import Path
8import uuid
9from typing import Optional
10
11app = FastAPI(title="ScrapeGoatMusic Generation API")
12
13# Initialize models and configurations
14def init_models():
15 parser = argparse.ArgumentParser()
16 # Add all your existing arguments here
17 args = parser.parse_args([])
18 args.stage1_model = "scrapegoat/ScrapeGoat-Music-Stage1"
19 args.stage2_model = "scrapegoat/ScrapeGoat-Music-Stage1"
20 args.max_new_tokens = 3000
21 args.run_n_segments = 2
22 args.stage2_batch_size = 4
23 args.output_dir = "./output"
24 args.cuda_idx = 0
25 # Add other default arguments
26 return args
27
28@app.on_event("startup")
29async def startup_event():
30 global args
31 args = init_models()
32 os.makedirs(args.output_dir, exist_ok=True)
33
34@app.post("/generate")
35async def generate_music(
36 genre_file: UploadFile = File(...),
37 lyrics_file: UploadFile = File(...),
38 audio_prompt: Optional[UploadFile] = File(None),
39 prompt_start_time: float = Form(0.0),
40 prompt_end_time: float = Form(30.0)
41):
42 # Create unique session ID
43 session_id = str(uuid.uuid4())
44 session_dir = Path(args.output_dir) / session_id
45 os.makedirs(session_dir, exist_ok=True)
46
47 # Save uploaded files
48 genre_path = session_dir / "genre.txt"
49 lyrics_path = session_dir / "lyrics.txt"
50
51 with open(genre_path, "wb") as f:
52 f.write(await genre_file.read())
53 with open(lyrics_path, "wb") as f:
54 f.write(await lyrics_file.read())
55
56 # Handle optional audio prompt
57 audio_prompt_path = None
58 if audio_prompt:
59 audio_prompt_path = session_dir / "audio_prompt.wav"
60 with open(audio_prompt_path, "wb") as f:
61 f.write(await audio_prompt.read())
62
63 # Run inference
64 try:
65 # Import your inference code here
66 from infer import run_inference
67 output_path = run_inference(
68 args,
69 str(genre_path),
70 str(lyrics_path),
71 str(audio_prompt_path) if audio_prompt_path else None,
72 prompt_start_time,
73 prompt_end_time
74 )
75
76 return FileResponse(
77 output_path,
78 media_type="audio/mpeg",
79 filename=f"generated_music_{session_id}.mp3"
80 )
81 except Exception as e:
82 return {"error": str(e)}
83
84if __name__ == "__main__":
85 uvicorn.run(app, host="0.0.0.0", port=8000)infer.py with your existing inference code, modified to be imported as a module.python api.pyhttp://localhost:8000genre_file: Text file containing genre tags (Required)lyrics_file: Text file containing lyrics (Required)audio_prompt: Audio file for prompt (Optional)prompt_start_time: Start time for audio prompt (Default: 0.0)prompt_end_time: End time for audio prompt (Default: 30.0)1curl -X POST "http://localhost:8000/generate" \
2 -H "accept: application/json" \
3 -H "Content-Type: multipart/form-data" \
4 -F "genre_file=@/path/to/genre.txt" \
5 -F "lyrics_file=@/path/to/lyrics.txt" \
6 -F "prompt_start_time=0.0" \
7 -F "prompt_end_time=30.0"instrumental pop energetic female vocals[verse]
Your lyrics here
[chorus]
Your chorus here1model = AutoModelForCausalLM.from_pretrained(
2 stage1_model,
3 torch_dtype=torch.bfloat16,
4 attn_implementation="flash_attention_2"
5)1# Add to your inference configuration
2torch.cuda.set_device(0) # Use first H100
3torch.backends.cudnn.benchmark = Truecuda_idx in the API configuration.http://localhost:8000/docs for testing and monitoring endpoints.stage2_batch_sizemax_new_tokenspython prepare_training_data.pytraining_data/
├── audio_tracks/ # 16kHz mono WAV files
├── lyrics/ # Corresponding lyrics files
└── genres/ # Genre tag filespip install accelerate datasets transformers1# For Stage 1 model (7B)
2export MODEL_PATH="scrapegoat/ScrapeGoat-Music-Stage1"
3export OUTPUT_DIR="./fine_tuned_model_s1"
4
5# For Stage 2 model (1B)
6export MODEL_PATH="scrapegoat/ScrapeGoat-Music-Stage2"
7export OUTPUT_DIR="./fine_tuned_model_s2"1python train.py \
2 --model_name_or_path $MODEL_PATH \
3 --output_dir $OUTPUT_DIR \
4 --num_train_epochs 3 \
5 --per_device_train_batch_size 4 \
6 --gradient_accumulation_steps 4 \
7 --learning_rate 1e-5 \
8 --warmup_steps 500 \
9 --logging_steps 100 \
10 --save_steps 1000 \
11 --evaluation_strategy steps \
12 --load_best_model_at_end \
13 --gradient_checkpointing true