-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from chenxwh/main
Add Replicate demo and API
- Loading branch information
Showing
4 changed files
with
190 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Configuration for Cog ⚙️ | ||
# Reference: https://github.com/replicate/cog/blob/main/docs/yaml.md | ||
|
||
build: | ||
gpu: true | ||
python_version: "3.11" | ||
python_packages: | ||
- torch==2.0.1 | ||
- torchaudio==2.0.2 | ||
- transformers==4.27.0 | ||
- accelerate==0.18.0 | ||
- datasets==2.1.0 | ||
- einops==0.6.1 | ||
- huggingface_hub==0.13.3 | ||
- importlib_metadata==6.3.0 | ||
- librosa==0.9.2 | ||
- matplotlib==3.5.2 | ||
- omegaconf==2.3.0 | ||
- packaging==23.1 | ||
- progressbar33==2.4 | ||
- protobuf==3.20.* | ||
- resampy==0.4.2 | ||
- scikit_image==0.22.0 | ||
- scikit_learn==1.2.2 | ||
- scipy==1.11.3 | ||
- soundfile==0.12.1 | ||
- ssr_eval==0.0.6 | ||
- torchlibrosa==0.1.0 | ||
- tqdm==4.63.1 | ||
- sentencepiece==0.1.99 | ||
- diffusers==0.15.0 | ||
predict: "predict.py:Predictor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Prediction interface for Cog ⚙️ | ||
# https://github.com/replicate/cog/blob/main/docs/python.md | ||
|
||
import subprocess | ||
|
||
subprocess.run("cd diffusers && pip install . && cd ..", shell=True, check=True) | ||
|
||
import soundfile as sf | ||
from cog import BasePredictor, Input, Path | ||
from mustango import Mustango | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def setup(self) -> None: | ||
"""Load the model into memory to make running multiple predictions efficient""" | ||
cache_dir = "model_cache" | ||
local_files_only = True # set to True if models are cached in cache_dir | ||
self.model = Mustango( | ||
"declare-lab/mustango", cache_dir=cache_dir, local_files_only=local_files_only | ||
) | ||
|
||
def predict( | ||
self, | ||
prompt: str = Input( | ||
description="Input prompt.", | ||
default="This is a new age piece. There is a flute playing the main melody with a lot of staccato notes. The rhythmic background consists of a medium tempo electronic drum beat with percussive elements all over the spectrum. There is a playful atmosphere to the piece. This piece can be used in the soundtrack of a children's TV show or an advertisement jingle.", | ||
), | ||
steps: int = Input(description="inferene steps", default=100), | ||
guidance: float = Input(description="guidance scale", default=3), | ||
) -> Path: | ||
"""Run a single prediction on the model""" | ||
|
||
music = self.model.generate(prompt, steps=steps, guidance=guidance) | ||
out = "/tmp/output.wav" | ||
sf.write(out, music, samplerate=16000) | ||
return Path(out) |