-
Notifications
You must be signed in to change notification settings - Fork 59
/
app_gradio.py
55 lines (46 loc) · 2.12 KB
/
app_gradio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Adapted from https://huggingface.co/spaces/stabilityai/stable-diffusion
"""
import torch
import time
import gradio as gr
from diffusers import StableDiffusionPanoramaPipeline, DDIMScheduler
model_ckpt = "stabilityai/stable-diffusion-2-base"
scheduler = DDIMScheduler.from_pretrained(model_ckpt, subfolder="scheduler")
pipe = StableDiffusionPanoramaPipeline.from_pretrained(
model_ckpt, scheduler=scheduler, torch_dtype=torch.float16
)
# pipe = StableDiffusionPanoramaPipeline.from_pretrained(
# model_ckpt, scheduler=scheduler
# )
pipe = pipe.to(torch.device("cuda" if torch.cuda.is_available() else "cpu"))
def generate_image_fn(prompt: str, img_width: int, img_height=512) -> list:
start_time = time.time()
image = pipe(prompt, height=img_height, width=img_width).images
end_time = time.time()
print(f"Time taken: {end_time - start_time} seconds.")
return image
description = """This Space demonstrates MultiDiffusion Text2Panorama using Stable Diffusion model. To get started, either enter a prompt or pick one from the examples below. For details, please visit [the project page](https://multidiffusion.github.io/).
<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.
<br/>
<a href="https://huggingface.co/spaces/weizmannscience/MultiDiffusion?duplicate=true">
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
<p/>"""
article = "This Space leverages a A10 GPU to run the predictions. We use mixed-precision to speed up the inference latency."
gr.Interface(
generate_image_fn,
inputs=[
gr.Textbox(
label="Enter your prompt",
max_lines=1,
placeholder="a photo of the dolomites",
),
gr.Slider(value=4096, minimum=512, maximum=4608, step=128),
],
outputs=gr.Gallery().style(grid=[2], height="auto"),
title="Generate a panoramic image!",
description=description,
article=article,
examples=[["a photo of the dolomites", 4096]],
allow_flagging=False,
).launch(enable_queue=True)