from diffusers import DiffusionPipeline import gradio as gr import torch import time import psutil start_time = time.time() device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶" def error_str(error, title="Error"): return ( f"""#### {title} {error}""" if error else "" ) def inference( repo_id, discuss_nr, prompt, ): print(psutil.virtual_memory()) # print memory usage seed = 0 torch_device = "cuda" if "GPU" in device else "cpu" generator = torch.Generator(torch_device).manual_seed(seed) dtype = torch.float16 if torch_device == "cuda" else torch.float32 try: revision = f"refs/pr/{discuss_nr}" pipe = DiffusionPipeline.from_pretrained(repo_id, revision=revision, torch_dtype=dtype) pipe.to(torch_device) return pipe(prompt, generator=generator, num_inference_steps=25).images, f"Done. Seed: {seed}" except Exception as e: url = f"https://huggingface.co/{repo_id}/discussions/{discuss_nr}" message = f"There is a problem with your diffusers weights of the PR: {url}. Error message: \n" return None, error_str(message + e) with gr.Blocks(css="style.css") as demo: gr.HTML( f"""
Space to test whether `diffusers` PRs work.
Running on {device}