""" Adapted from https://huggingface.co/spaces/stabilityai/stable-diffusion """ import torch import time import gradio as gr from constants import css, examples, img_height, img_width, num_images_to_gen from share_btn import community_icon_html, loading_icon_html, share_js 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() prompt = "a photo of the dolomites" 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 and pick one from the examples below. For details, please visit [the project page](https://multidiffusion.github.io/).
For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.