Upload 3 files
Browse files- Dockerfile +10 -0
- app.py +39 -0
- requirements.txt +9 -0
Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
import torch
|
| 3 |
+
import uuid
|
| 4 |
+
import os
|
| 5 |
+
import soundfile as sf
|
| 6 |
+
|
| 7 |
+
from diffusers import StableAudioPipeline
|
| 8 |
+
|
| 9 |
+
app = FastAPI()
|
| 10 |
+
|
| 11 |
+
OUTPUT_DIR = "outputs"
|
| 12 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 13 |
+
|
| 14 |
+
print("Loading Stable Audio Open...")
|
| 15 |
+
pipe = StableAudioPipeline.from_pretrained(
|
| 16 |
+
"stabilityai/stable-audio-open-1.0",
|
| 17 |
+
torch_dtype=torch.float16
|
| 18 |
+
)
|
| 19 |
+
pipe.to("cuda")
|
| 20 |
+
|
| 21 |
+
@app.post("/generate")
|
| 22 |
+
async def generate(prompt: str, duration: float = 10.0):
|
| 23 |
+
audio = pipe(
|
| 24 |
+
prompt,
|
| 25 |
+
duration=duration,
|
| 26 |
+
guidance_scale=7.5,
|
| 27 |
+
num_inference_steps=200
|
| 28 |
+
).audios[0]
|
| 29 |
+
|
| 30 |
+
filename = f"{uuid.uuid4().hex}.wav"
|
| 31 |
+
path = os.path.join(OUTPUT_DIR, filename)
|
| 32 |
+
|
| 33 |
+
sf.write(path, audio, samplerate=44100)
|
| 34 |
+
|
| 35 |
+
return {
|
| 36 |
+
"prompt": prompt,
|
| 37 |
+
"duration": duration,
|
| 38 |
+
"file": filename
|
| 39 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
torch
|
| 4 |
+
torchaudio
|
| 5 |
+
diffusers
|
| 6 |
+
transformers
|
| 7 |
+
accelerate
|
| 8 |
+
soundfile
|
| 9 |
+
scipy
|