Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files123456789101112135 unmodified lines19202122232425262712 unmodified lines4041424344454647484950515253545556575859606162636465666768697071727345 unmodified lines1191201211221231241 unmodified line12612712812913013113213324 unmodified lines1581591601611621631641651661673 unmodified lines17117217317417517617765 unmodified lines24324424524624724834 unmodified lines283284285286287288289290291292293294295296297#!/usr/bin/env python#patch 1.0()# Permission is hereby granted, free of charge, to any person obtaining a copy# of this software and associated documentation files (the "Software"), to deal# in the Software without restriction, including without limitation the rights# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell# copies of the Software, and to permit persons to whom the Software is# furnished to do so, subject to the following conditions:## ...import osimport randomimport uuid5 unmodified linesimport torchfrom diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteSchedulerDESCRIPTIONz= """## SDXL-LoRA-DLC β‘"""def save_image(img):unique_name = str(uuid.uuid4()) + ".png"img.save(unique_name)12 unmodified linesUSE_TORCH_COMPILE = 0ENABLE_CPU_OFFLOAD = 0if torch.cuda.is_available():pipe = StableDiffusionXLPipeline.from_pretrained("SG161222/RealVisXL_V4.0_Lightning",torch_dtype=torch.float16,use_safetensors=True,)pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)LORA_OPTIONS = {"Realism (face/character)π¦π»": ("prithivMLmods/Canopus-Realism-LoRA", "Canopus-Realism-LoRA.safetensors", "rlms"),"Pixar (art/toons)π": ("prithivMLmods/Canopus-Pixar-Art", "Canopus-Pixar-Art.safetensors", "pixar"),"Photoshoot (camera/film)πΈ": ("prithivMLmods/Canopus-Photo-Shoot-Mini-LoRA", "Canopus-Photo-Shoot-Mini-LoRA.safetensors", "photo"),"Clothing (hoodies/pant/shirts)π": ("prithivMLmods/Canopus-Clothing-Adp-LoRA", "Canopus-Dress-Clothing-LoRA.safetensors", "clth"),"Interior Architecture (house/hotel)π ": ("prithivMLmods/Canopus-Interior-Architecture-0.1", "Canopus-Interior-Architecture-0.1Ξ΄.safetensors", "arch"),"Fashion Product (wearing/usable)π": ("prithivMLmods/Canopus-Fashion-Product-Dilation", "Canopus-Fashion-Product-Dilation.safetensors", "fashion"),"Minimalistic Image (minimal/detailed)ποΈ": ("prithivMLmods/Pegasi-Minimalist-Image-Style", "Pegasi-Minimalist-Image-Style.safetensors", "minimalist"),"Modern Clothing (trend/new)π": ("prithivMLmods/Canopus-Modern-Clothing-Design", "Canopus-Modern-Clothing-Design.safetensors", "mdrnclth"),"Animaliea (farm/wild)π«": ("prithivMLmods/Canopus-Animaliea-Artism", "Canopus-Animaliea-Artism.safetensors", "Animaliea"),"Liquid Wallpaper (minimal/illustration)πΌοΈ": ("prithivMLmods/Canopus-Liquid-Wallpaper-Art", "Canopus-Liquid-Wallpaper-Minimalize-LoRA.safetensors", "liquid"),"Canes Cars (realistic/futurecars)π": ("prithivMLmods/Canes-Cars-Model-LoRA", "Canes-Cars-Model-LoRA.safetensors", "car"),"Pencil Art (characteristic/creative)βοΈ": ("prithivMLmods/Canopus-Pencil-Art-LoRA", "Canopus-Pencil-Art-LoRA.safetensors", "Pencil Art"),"Art Minimalistic (paint/semireal)π¨": ("prithivMLmods/Canopus-Art-Medium-LoRA", "Canopus-Art-Medium-LoRA.safetensors", "mdm"),}for model_name, weight_name, adapter_name in LORA_OPTIONS.values():pipe.load_lora_weights(model_name, weight_name=weight_name, adapter_name=adapter_name)pipe.to("cuda")style_list = [{45 unmodified linesrandomize_seed: bool = False,style_name: str = DEFAULT_STYLE_NAME,lora_model: str = "Realism (face/character)π¦π»",progress=gr.Progress(track_tqdm=True),):seed = int(randomize_seed_fn(seed, randomize_seed))1 unmodified linepositive_prompt, effective_negative_prompt = apply_style(style_name, prompt, negative_prompt)if not use_negative_prompt:effective_negative_prompt = "" # type: ignoremodel_name, weight_name, adapter_name = LORA_OPTIONS[lora_model]pipe.set_adapters(adapter_name)24 unmodified linesvisibility: hidden}'''def load_predefined_images():predefined_images = ["assets/1.png","assets/2.png","assets/3.png",3 unmodified lines"assets/7.png","assets/8.png","assets/9.png",]return predefined_images65 unmodified lineslabel="Quality Style",)with gr.Row(visible=True):model_choice = gr.Dropdown(label="LoRA Selection",34 unmodified linesrandomize_seed,style_selection,model_choice,],outputs=[result, seed],api_name="run",)with gr.Column(scale=3):gr.Markdown("### Image Gallery")predefined_gallery = gr.Gallery(label="Image Gallery", columns=3, show_label=False, value=load_predefined_images())if __name__ == "__main__":demo.queue(max_size=30).launch()1235 unmodified lines9101112131415161718192021222324252612 unmodified lines39404142434445464748495051525354555657585960616263646566676869707172737445 unmodified lines1201211221231241251261 unmodified line12812913013113213313413513624 unmodified lines1611621631641651661671681693 unmodified lines17317417517617717865 unmodified lines24424524624724824925025125225325425525625734 unmodified lines292293294295296297298299300301302303304305306import osimport randomimport uuid5 unmodified linesimport torchfrom diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteSchedulerDESCRIPTIONz = """## SDXL-LoRA-DLC β‘"""# Define model optionsMODEL_OPTIONS = {"RealVisXL V4.0 Lightning": "SG161222/RealVisXL_V4.0_Lightning","RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",}# Dictionary to cache pipelinespipelines = {}def save_image(img):unique_name = str(uuid.uuid4()) + ".png"img.save(unique_name)12 unmodified linesUSE_TORCH_COMPILE = 0ENABLE_CPU_OFFLOAD = 0# Define LoRA optionsLORA_OPTIONS = {"Realism (face/character)π¦π»": ("prithivMLmods/Canopus-Realism-LoRA", "Canopus-Realism-LoRA.safetensors", "rlms"),"Pixar (art/toons)π": ("prithivMLmods/Canopus-Pixar-Art", "Canopus-Pixar-Art.safetensors", "pixar"),"Photoshoot (camera/film)πΈ": ("prithivMLmods/Canopus-Photo-Shoot-Mini-LoRA", "Canopus-Photo-Shoot-Mini-LoRA.safetensors", "photo"),"Clothing (hoodies/pant/shirts)π": ("prithivMLmods/Canopus-Clothing-Adp-LoRA", "Canopus-Dress-Clothing-LoRA.safetensors", "clth"),"Interior Architecture (house/hotel)π ": ("prithivMLmods/Canopus-Interior-Architecture-0.1", "Canopus-Interior-Architecture-0.1Ξ΄.safetensors", "arch"),"Fashion Product (wearing/usable)π": ("prithivMLmods/Canopus-Fashion-Product-Dilation", "Canopus-Fashion-Product-Dilation.safetensors", "fashion"),"Minimalistic Image (minimal/detailed)ποΈ": ("prithivMLmods/Pegasi-Minimalist-Image-Style", "Pegasi-Minimalist-Image-Style.safetensors", "minimalist"),"Modern Clothing (trend/new)π": ("prithivMLmods/Canopus-Modern-Clothing-Design", "Canopus-Modern-Clothing-Design.safetensors", "mdrnclth"),"Animaliea (farm/wild)π«": ("prithivMLmods/Canopus-Animaliea-Artism", "Canopus-Animaliea-Artism.safetensors", "Animaliea"),"Liquid Wallpaper (minimal/illustration)πΌοΈ": ("prithivMLmods/Canopus-Liquid-Wallpaper-Art", "Canopus-Liquid-Wallpaper-Minimalize-LoRA.safetensors", "liquid"),"Canes Cars (realistic/futurecars)π": ("prithivMLmods/Canes-Cars-Model-LoRA", "Canes-Cars-Model-LoRA.safetensors", "car"),"Pencil Art (characteristic/creative)βοΈ": ("prithivMLmods/Canopus-Pencil-Art-LoRA", "Canopus-Pencil-Art-LoRA.safetensors", "Pencil Art"),"Art Minimalistic (paint/semireal)π¨": ("prithivMLmods/Canopus-Art-Medium-LoRA", "Canopus-Art-Medium-LoRA.safetensors", "mdm"),}# Function to load or retrieve a pipelinedef get_pipeline(model_name):if model_name not in pipelines:pipelines[model_name] = StableDiffusionXLPipeline.from_pretrained(MODEL_OPTIONS[model_name],torch_dtype=torch.float16,use_safetensors=True,)pipelines[model_name].scheduler = EulerAncestralDiscreteScheduler.from_config(pipelines[model_name].scheduler.config)for lora_model_name, lora_weight_name, lora_adapter_name in LORA_OPTIONS.values():pipelines[model_name].load_lora_weights(lora_model_name, weight_name=lora_weight_name, adapter_name=lora_adapter_name)pipelines[model_name].to("cuda")return pipelines[model_name]style_list = [{45 unmodified linesrandomize_seed: bool = False,style_name: str = DEFAULT_STYLE_NAME,lora_model: str = "Realism (face/character)π¦π»",base_model: str = "RealVisXL V4.0 Lightning",progress=gr.Progress(track_tqdm=True),):seed = int(randomize_seed_fn(seed, randomize_seed))1 unmodified linepositive_prompt, effective_negative_prompt = apply_style(style_name, prompt, negative_prompt)if not use_negative_prompt:effective_negative_prompt = ""pipe = get_pipeline(base_model)model_name, weight_name, adapter_name = LORA_OPTIONS[lora_model]pipe.set_adapters(adapter_name)24 unmodified linesvisibility: hidden}'''def load_predefined_images():predefined_images = ["assets/1.png","assets/2.png","assets/3.png",3 unmodified lines"assets/7.png","assets/8.png","assets/9.png",]return predefined_images65 unmodified lineslabel="Quality Style",)# Add base model selection dropdownwith gr.Row():base_model_choice = gr.Dropdown(label="Base Model",choices=list(MODEL_OPTIONS.keys()),value="RealVisXL V4.0 Lightning",)with gr.Row(visible=True):model_choice = gr.Dropdown(label="LoRA Selection",34 unmodified linesrandomize_seed,style_selection,model_choice,base_model_choice,],outputs=[result, seed],api_name="run",)with gr.Column(scale=3):gr.Markdown("### Image Gallery")predefined_gallery = gr.Gallery(label="Image Gallery", columns=3, show_label=False, value=load_predefined_images())if __name__ == "__main__":demo.queue(max_size=30).launch()
app.py+54-45