Spaces:
Runtime error
Runtime error
omerbartal
commited on
Commit
•
7e447d2
1
Parent(s):
c2eaf30
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Adapted from https://huggingface.co/spaces/stabilityai/stable-diffusion
|
3 |
+
"""
|
4 |
+
|
5 |
+
import torch
|
6 |
+
|
7 |
+
import time
|
8 |
+
|
9 |
+
import gradio as gr
|
10 |
+
|
11 |
+
from constants import css, examples, img_height, img_width, num_images_to_gen
|
12 |
+
from share_btn import community_icon_html, loading_icon_html, share_js
|
13 |
+
|
14 |
+
from diffusers import StableDiffusionPanoramaPipeline, DDIMScheduler
|
15 |
+
|
16 |
+
model_ckpt = "stabilityai/stable-diffusion-2-base"
|
17 |
+
scheduler = DDIMScheduler.from_pretrained(model_ckpt, subfolder="scheduler")
|
18 |
+
pipe = StableDiffusionPanoramaPipeline.from_pretrained(
|
19 |
+
model_ckpt, scheduler=scheduler, torch_dtype=torch.float16
|
20 |
+
)
|
21 |
+
|
22 |
+
pipe = pipe.to(torch.device("cuda" if torch.cuda.is_available() else "cpu"))
|
23 |
+
|
24 |
+
def generate_image_fn(prompt: str, guidance_scale: float) -> list:
|
25 |
+
start_time = time.time()
|
26 |
+
prompt = "a photo of the dolomites"
|
27 |
+
image = pipe(prompt, guidance_scale=guidance_scale).images
|
28 |
+
end_time = time.time()
|
29 |
+
print(f"Time taken: {end_time - start_time} seconds.")
|
30 |
+
return image
|
31 |
+
|
32 |
+
|
33 |
+
description = "This Space demonstrates MultiDiffusion Text2Panorama using Stable Diffusion model. You can use it for generating custom pokemons. To get started, either enter a prompt and pick one from the examples below. For details on the fine-tuning procedure, refer to [this repository]()."
|
34 |
+
article = "This Space leverages a T4 GPU to run the predictions. We use mixed-precision to speed up the inference latency."
|
35 |
+
gr.Interface(
|
36 |
+
generate_image_fn,
|
37 |
+
inputs=[
|
38 |
+
gr.Textbox(
|
39 |
+
label="Enter your prompt",
|
40 |
+
max_lines=1,
|
41 |
+
placeholder="a photo of the dolomites",
|
42 |
+
),
|
43 |
+
gr.Slider(value=40, minimum=8, maximum=50, step=1),
|
44 |
+
],
|
45 |
+
outputs=gr.Gallery().style(grid=[2], height="auto"),
|
46 |
+
title="Generate custom pokemons",
|
47 |
+
description=description,
|
48 |
+
article=article,
|
49 |
+
examples=[["a photo of the dolomites", 40]],
|
50 |
+
allow_flagging=False,
|
51 |
+
).launch(enable_queue=True)
|