import argparse import gradio as gr import numpy as np import torch from pulid import attention_processor as attention from pulid.pipeline_v1_1 import PuLIDPipeline from pulid.utils import resize_numpy_image_long torch.set_grad_enabled(False) parser = argparse.ArgumentParser() parser.add_argument( '--base', type=str, default='RunDiffusion/Juggernaut-XL-v9', choices=[ 'Lykon/dreamshaper-xl-lightning', # 'SG161222/RealVisXL_V4.0', will add it later 'RunDiffusion/Juggernaut-XL-v9', ], ) # parser.add_argument('--sampler', type=str, default='dpmpp_2m', choices=['dpmpp_sde', 'dpmpp_2m']) parser.add_argument('--port', type=int, default=7860) args = parser.parse_args() use_lightning_model = 'lightning' in args.base.lower() # currently we only support two commonly used sampler args.sampler = 'dpmpp_sde' if use_lightning_model else 'dpmpp_2m' if use_lightning_model: default_cfg = 2.0 default_steps = 5 else: default_cfg = 7.0 default_steps = 25 pipeline = PuLIDPipeline(sdxl_repo=args.base, sampler=args.sampler) # other params DEFAULT_NEGATIVE_PROMPT = ( 'flaws in the eyes, flaws in the face, flaws, lowres, non-HDRi, low quality, worst quality,' 'artifacts noise, text, watermark, glitch, deformed, mutated, ugly, disfigured, hands, ' 'low resolution, partially rendered objects, deformed or partially rendered eyes, ' 'deformed, deformed eyeballs, cross-eyed,blurry' ) dreamshaper_example_inps = [ ['portrait, blacklight', 'example_inputs/liuyifei.png', 42, 0.8, 10], ['pixel art, 1boy', 'example_inputs/lecun.jpg', 42, 0.8, 10], [ 'cinematic film still, close up, photo of redheaded girl near grasses, fictional landscapes, (intense sunlight:1.4), realist detail, brooding mood, ue5, detailed character expressions, light amber and red, amazing quality, wallpaper, analog film grain', 'example_inputs/liuyifei.png', 42, 0.8, 10, ], [ 'A minimalist line art depiction of an Artificial Intelligence being\'s thought process, lines and nodes forming intricate patterns.', 'example_inputs/hinton.jpeg', 42, 0.8, 10, ], [ 'instagram photo, photo of 23 y.o man in black sweater, pale skin, (smile:0.4), hard shadows', 'example_inputs/pengwei.jpg', 42, 0.8, 10, ], [ 'by Tsutomu Nihei,(strange but extremely beautiful:1.4),(masterpiece, best quality:1.4),in the style of nicola samori,The Joker,', 'example_inputs/lecun.jpg', 1675432759740519133, 0.8, 10, ], ] jugger_example_inps = [ [ 'robot,simple robot,robot with glass face,ellipse head robot,(made partially out of glass),hexagonal shapes,ferns growing inside head,butterflies on head,butterflies flying around', 'example_inputs/hinton.jpeg', 15022214902832471291, 0.8, 20, ], ['sticker art, 1girl', 'example_inputs/liuyifei.png', 42, 0.8, 20], [ '1girl, cute model, Long thick Maxi Skirt, Knit sweater, swept back hair, alluring smile, working at a clothing store, perfect eyes, highly detailed beautiful expressive eyes, detailed eyes, 35mm photograph, film, bokeh, professional, 4k, highly detailed dynamic lighting, photorealistic, 8k, raw, rich, intricate details,', 'example_inputs/liuyifei.png', 42, 0.8, 20, ], ['Chinese paper-cut, 1girl', 'example_inputs/liuyifei.png', 42, 0.8, 20], ['Studio Ghibli, 1boy', 'example_inputs/hinton.jpeg', 42, 0.8, 20], ['1man made of ice sculpture', 'example_inputs/lecun.jpg', 42, 0.8, 20], ['portrait of green-skinned shrek, wearing lacoste purple sweater', 'example_inputs/lecun.jpg', 42, 0.8, 20], ['1990s Japanese anime, 1girl', 'example_inputs/liuyifei.png', 42, 0.8, 20], ['made of little stones, portrait', 'example_inputs/hinton.jpeg', 42, 0.8, 20], ] @torch.inference_mode() def run(*args): id_image = args[0] supp_images = args[1:4] prompt, neg_prompt, scale, seed, steps, H, W, id_scale, num_zero, ortho = args[4:] seed = int(seed) if seed == -1: seed = torch.Generator(device="cpu").seed() pipeline.debug_img_list = [] attention.NUM_ZERO = num_zero if ortho == 'v2': attention.ORTHO = False attention.ORTHO_v2 = True elif ortho == 'v1': attention.ORTHO = True attention.ORTHO_v2 = False else: attention.ORTHO = False attention.ORTHO_v2 = False if id_image is not None: id_image = resize_numpy_image_long(id_image, 1024) supp_id_image_list = [ resize_numpy_image_long(supp_id_image, 1024) for supp_id_image in supp_images if supp_id_image is not None ] id_image_list = [id_image] + supp_id_image_list uncond_id_embedding, id_embedding = pipeline.get_id_embedding(id_image_list) else: uncond_id_embedding = None id_embedding = None img = pipeline.inference( prompt, (1, H, W), neg_prompt, id_embedding, uncond_id_embedding, id_scale, scale, steps, seed )[0] return np.array(img), str(seed), pipeline.debug_img_list _HEADER_ = '''