import gradio as gr import torch from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline import spaces from PIL import Image import numpy as np # Load the ControlNet model and pipeline controlnet = ControlNetModel.from_pretrained( "briaai/BRIA-2.2-ControlNet-Recoloring", torch_dtype=torch.float16 ) pipe = StableDiffusionXLControlNetPipeline.from_pretrained( "briaai/BRIA-2.2", controlnet=controlnet, torch_dtype=torch.float16, ).to("cuda") # Function to transform the image based on a prompt @spaces.GPU(enable_queue=True) def generate_image(image, prompt): # Prepare the image for processing image = image.convert("RGB") recoloring_image = Image.fromarray(np.array(image)).convert('L').convert('RGB') # Define the negative prompt negative_prompt = "Logo,Watermark,Text,Ugly,Morbid,Extra fingers,Poorly drawn hands,Mutation,Blurry,Extra limbs,Gross proportions,Missing arms,Mutated hands,Long neck,Duplicate,Mutilated,Mutilated hands,Poorly drawn face,Deformed,Bad anatomy,Cloned face,Malformed limbs,Missing legs,Too many fingers" # Generate the transformed image results = pipe(prompt=prompt, negative_prompt=negative_prompt, image=recoloring_image, controlnet_conditioning_scale=1.0, height=1024, width=1024) return results.images[0] # Gradio Interface description = """ Anything to Anything, a workflow by Angrypenguinpng using the Bria Recolor ControlNet, check it out here: https://huggingface.co/briaai/BRIA-2.2-ControlNet-Recoloring """ with gr.Blocks() as demo: gr.Markdown("