Spaces:
Runtime error
Runtime error
Commit
•
1d4c0d9
1
Parent(s):
6e8f7f3
WIP
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import DiffusionPipeline
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
import math
|
5 |
+
|
6 |
+
orig_start_prompt = "a photograph of an adult lion"
|
7 |
+
orig_end_prompt = "a photograph of a lion cub"
|
8 |
+
|
9 |
+
if torch.cuda.is_available():
|
10 |
+
device = "cuda"
|
11 |
+
dtype = torch.float16
|
12 |
+
else:
|
13 |
+
device = "cpu"
|
14 |
+
dtype = torch.bfloat16
|
15 |
+
|
16 |
+
pipe = DiffusionPipeline.from_pretrained("kakaobrain/karlo-v1-alpha-image-variations", torch_dtype=dtype, custom_pipeline='unclip_image_interpolation')
|
17 |
+
pipe.to(device)
|
18 |
+
|
19 |
+
def unclip_text_interpolation(
|
20 |
+
start_prompt,
|
21 |
+
end_prompt,
|
22 |
+
steps,
|
23 |
+
seed
|
24 |
+
):
|
25 |
+
generator = torch.Generator()
|
26 |
+
generator.manual_seed(seed)
|
27 |
+
|
28 |
+
output = pipe(start_prompt, end_prompt, steps, enable_sequential_cpu_offload=False, generator=generator)
|
29 |
+
return output.images
|
30 |
+
|
31 |
+
inputs = [
|
32 |
+
gr.Image(lines=2, default=orig_start_prompt, label="Start Prompt"),
|
33 |
+
gr.Image(lines=2, default=orig_end_prompt, label="End Prompt"),
|
34 |
+
gr.Slider(minimum=2, maximum=12, default=5, step=1, label="Steps"),
|
35 |
+
gr.Number(0, label="Seed", precision=0)
|
36 |
+
]
|
37 |
+
|
38 |
+
output = gr.Gallery(
|
39 |
+
label="Generated images", show_label=False, elem_id="gallery"
|
40 |
+
).style(grid=[2], height="auto")
|
41 |
+
|
42 |
+
examples = [
|
43 |
+
[orig_start_prompt, orig_end_prompt, 5, 42],
|
44 |
+
["a photo of a landscape in winter","a photo of a landscape in fall", 5, 20],
|
45 |
+
["a photo of a victorian house", "a photo of a modern house", 5, 20]
|
46 |
+
]
|
47 |
+
|
48 |
+
title = "UnClip Image Interpolation Pipeline"
|
49 |
+
|
50 |
+
demo_app = gr.Interface(
|
51 |
+
fn=unclip_text_interpolation,
|
52 |
+
inputs=inputs,
|
53 |
+
outputs=output,
|
54 |
+
title=title,
|
55 |
+
theme='huggingface',
|
56 |
+
examples=examples,
|
57 |
+
cache_examples=True
|
58 |
+
)
|
59 |
+
demo_app.launch(debug=True, enable_queue=True)
|