import torch from diffusers import StableDiffusionPipeline import gradio as gr model_id = "SG161222/RealVisXL_V4.0" pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) pipe.to("cpu") # Use "cuda" if GPU is available def generate_image( prompt: str, negative_prompt: str = "", use_negative_prompt: bool = False, style: str = DEFAULT_STYLE_NAME, seed: int = 0, width: int = 1024, height: int = 1024, guidance_scale: float = 3, randomize_seed: bool = False, use_resolution_binning: bool = True, progress=gr.Progress(track_tqdm=True), ): if check_text(prompt, negative_prompt): raise ValueError("Prompt contains restricted words.") prompt, negative_prompt = apply_style(style, prompt, negative_prompt) seed = int(randomize_seed_fn(seed, randomize_seed)) generator = torch.Generator().manual_seed(seed) if not use_negative_prompt: negative_prompt = "" # type: ignore negative_prompt += default_negative options = { "prompt": prompt, "negative_prompt": negative_prompt, "width": width, "height": height, "guidance_scale": guidance_scale, "num_inference_steps": 25, "generator": generator, "num_images_per_prompt": NUM_IMAGES_PER_PROMPT, "use_resolution_binning": use_resolution_binning, "output_type": "pil", } images = pipe(**options).images + pipe2(**options).images image_paths = [save_image(img) for img in images] return image_paths, seed def chatbot(prompt): # Generate the image based on the user's input image = generate_image(prompt) return image # Create the Gradio interface interface = gr.Interface( fn=chatbot, inputs="text", outputs="image", title="RealVisXL V4.0 Text-to-Image Chatbot", description="Enter a text prompt and get an AI-generated image." ) # Launch the interface interface.launch()