-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57b169f
commit f5d2c11
Showing
5 changed files
with
40 additions
and
4 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,33 @@ | ||
import gradio as gr | ||
import imagebind | ||
import torch | ||
from diffusers import StableUnCLIPImg2ImgPipeline | ||
import soundfile as sf | ||
|
||
device = "cuda:0" if torch.cuda.is_available() else "cpu" | ||
pipe = StableUnCLIPImg2ImgPipeline.from_pretrained( | ||
"stabilityai/stable-diffusion-2-1-unclip", torch_dtype=torch.float16, variation="fp16" | ||
) | ||
pipe = pipe.to(device) | ||
|
||
model = imagebind.imagebind_huge(pretrained=True) | ||
model.eval() | ||
model.to(device) | ||
|
||
@torch.no_grad() | ||
def anything2img(prompt, audio): | ||
sr, waveform = audio | ||
audio_path = 'tmp.wav' | ||
sf.write(audio_path, waveform, sr) | ||
audio_paths=[audio_path] | ||
embeddings = model.forward({ | ||
imagebind.ModalityType.AUDIO: imagebind.load_and_transform_audio_data(audio_paths, device), | ||
}) | ||
embeddings = embeddings[imagebind.ModalityType.AUDIO] | ||
images = pipe(prompt=prompt, image_embeds=embeddings.half()).images | ||
return images[0] | ||
|
||
|
||
demo = gr.Interface(fn=anything2img, inputs=["text", "audio"], outputs="image") | ||
# demo.launch(server_name='0.0.0.0', server_port=10051, share=True) | ||
demo.launch(server_name='0.0.0.0', server_port=10047, share=True) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 |
---|---|---|
|
@@ -8,4 +8,6 @@ ftfy | |
regex | ||
einops | ||
fvcore | ||
decord==0.6.0 | ||
decord==0.6.0 | ||
soundfile | ||
transformers |