Spaces:
Runtime error
Runtime error
hrishikesh
commited on
Commit
·
9f9fc69
1
Parent(s):
a26c9c1
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Image & Music Generator.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1TBH0E9wF716_A8o_yT68mSp_IFnb14_F
|
8 |
+
"""
|
9 |
+
|
10 |
+
!nvidia-smi
|
11 |
+
|
12 |
+
pip install accelerate
|
13 |
+
|
14 |
+
!pip install -q https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.15/xformers-0.0.15.dev0+189828c.d20221207-cp38-cp38-linu
|
15 |
+
|
16 |
+
! pip install -U transformers diffusers gradio ftfy pydub -q
|
17 |
+
|
18 |
+
!wget https://raw.githubusercontent.com/hmartiro/riffusion-inference/main/riffusion/audio.py
|
19 |
+
|
20 |
+
import gradio as gr
|
21 |
+
|
22 |
+
import torch
|
23 |
+
from diffusers import StableDiffusionPipeline
|
24 |
+
from audio import wav_bytes_from_spectrogram_image
|
25 |
+
|
26 |
+
model_id = "riffusion/riffusion-model-v1"
|
27 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
28 |
+
|
29 |
+
pipe = pipe.to("cuda")
|
30 |
+
#pipe.enable_xformers_memory_efficient_attention()
|
31 |
+
|
32 |
+
import random
|
33 |
+
COLORS = [
|
34 |
+
["#ff0000", "#00ff00"],
|
35 |
+
["#00ff00", "#0000ff"],
|
36 |
+
["#0000ff", "#ff0000"],
|
37 |
+
]
|
38 |
+
|
39 |
+
from diffusers import StableDiffusionPipeline
|
40 |
+
import torch
|
41 |
+
|
42 |
+
img_model_id = "runwayml/stable-diffusion-v1-5"
|
43 |
+
img_pipe = StableDiffusionPipeline.from_pretrained(img_model_id, torch_dtype=torch.float16, revision="fp16")
|
44 |
+
img_pipe = img_pipe.to("cuda")
|
45 |
+
#img_pipe.enable_xformers_memory_efficient_attention()
|
46 |
+
|
47 |
+
prompt = 'morning sunshine'
|
48 |
+
|
49 |
+
spectogram = pipe(prompt).images[0]
|
50 |
+
wav = wav_bytes_from_spectrogram_image(spectogram)
|
51 |
+
with open("output.wav", "wb") as f:
|
52 |
+
f.write(wav[0].getbuffer())
|
53 |
+
|
54 |
+
def audio_gen(prompt):
|
55 |
+
spectogram = pipe(prompt).images[0]
|
56 |
+
wav = wav_bytes_from_spectrogram_image(spectogram)
|
57 |
+
with open("output.wav", "wb") as f:
|
58 |
+
f.write(wav[0].getbuffer())
|
59 |
+
print("audio saved")
|
60 |
+
|
61 |
+
return ('output.wav',)
|
62 |
+
|
63 |
+
audio_gen("lazy nights")
|
64 |
+
|
65 |
+
gr.Interface(
|
66 |
+
audio_gen,
|
67 |
+
inputs=[gr.Textbox(label="prompt")],
|
68 |
+
outputs=[
|
69 |
+
gr.Audio(type='filepath')
|
70 |
+
|
71 |
+
],
|
72 |
+
title = 'Music Generator'
|
73 |
+
).launch(debug = True)
|
74 |
+
|
75 |
+
|
76 |
+
|