Spaces:
Runtime error
Runtime error
Commit
·
eaf3deb
1
Parent(s):
035c0da
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
model_list = ["kakaobrain/karlo-v1-alpha"]
|
9 |
+
|
10 |
+
def unclip_text_interpolation(
|
11 |
+
model_path,
|
12 |
+
start_prompt,
|
13 |
+
end_prompt,
|
14 |
+
steps,
|
15 |
+
num_inference_steps
|
16 |
+
):
|
17 |
+
|
18 |
+
pipe = DiffusionPipeline.from_pretrained(model_list, torch_dtype=torch.bfloat16, custom_pipeline='unclip_text_interpolation')
|
19 |
+
|
20 |
+
images = pipe(start_prompt, end_prompt, steps, num_inference_steps=num_inference_steps)
|
21 |
+
|
22 |
+
return images
|
23 |
+
|
24 |
+
inputs = [
|
25 |
+
gr.Dropdown(model_list, value=model_list[0], label="Model"),
|
26 |
+
gr.inputs.Textbox(lines=5, default=orig_prompt, label="Start Prompt"),
|
27 |
+
gr.inputs.Textbox(lines=1, default=orig_negative_prompt, label="End Prompt"),
|
28 |
+
gr.inputs.Slider(minimum=2, maximum=12, default=5, step=1, label="Steps")
|
29 |
+
]
|
30 |
+
|
31 |
+
output = gr.Gallery(
|
32 |
+
label="Generated images", show_label=False, elem_id="gallery"
|
33 |
+
).style(grid=[int(math.ceil(steps/2))], height="auto")
|
34 |
+
|
35 |
+
examples = [
|
36 |
+
["kakaobrain/karlo-v1-alpha", orig_start_prompt, orig_end_prompt, 6],
|
37 |
+
]
|
38 |
+
|
39 |
+
title = "UnClip Text Interpolation Pipeline"
|
40 |
+
description = """<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.
|
41 |
+
<br/>
|
42 |
+
<a href="https://huggingface.co/spaces/kadirnar/stable-diffusion-2-infinite-zoom-out?duplicate=true">
|
43 |
+
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
44 |
+
<p/>"""
|
45 |
+
|
46 |
+
demo_app = gr.Interface(
|
47 |
+
fn=unclip_text_interpolation,
|
48 |
+
description=description,
|
49 |
+
inputs=inputs,
|
50 |
+
outputs=output,
|
51 |
+
title=title,
|
52 |
+
theme='huggingface',
|
53 |
+
examples=examples,
|
54 |
+
cache_examples=True
|
55 |
+
)
|
56 |
+
demo_app.launch(debug=True, enable_queue=True)
|