pip install invisible-watermark import gradio as gr import torch from diffusers import DiffusionPipeline pip install invisible-watermark # Load the pre-trained model from Hugging Face pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16) pipe.to("cuda") # Ensure the model runs on the GPU if available # Define the function for the Gradio interface def generate_image(prompt): # Generate an image using the provided prompt image = pipe(prompt).images[0] return image # Set up the Gradio interface interface = gr.Interface( fn=generate_image, inputs="text", outputs="image", title="Stable Diffusion XL Refiner", description="Generate images from text prompts using Stable Diffusion XL Refiner 1.0" ) # Launch the Gradio app if __name__ == "__main__": interface.launch()