import spaces import gradio as gr import torch from diffusers import DiffusionPipeline MODEL_ID = "cagliostrolab/animagine-xl-4.0" pipe = DiffusionPipeline.from_pretrained( MODEL_ID, torch_dtype=torch.bfloat16, use_safetensors=True, safety_checker=None, requires_safety_checker=False, ) NEGATIVE_PROMPT = "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry" @spaces.GPU def generate_image(prompt: str, negative_prompt: str = NEGATIVE_PROMPT, width: int = 1024, height: int = 1024, steps: int = 28): pipe.to("cuda") result = pipe( prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=steps, guidance_scale=7.0, width=width, height=height, ) return result.images[0] demo = gr.Interface( fn=generate_image, inputs=[ gr.Textbox(label="Prompt"), gr.Textbox(label="Negative Prompt", value=NEGATIVE_PROMPT), gr.Slider(512, 1024, value=1024, step=64, label="Width"), gr.Slider(512, 1024, value=1024, step=64, label="Height"), gr.Slider(1, 40, value=28, step=1, label="Steps"), ], outputs=gr.Image(label="Generated Image"), title="Anime Generator", ) demo.launch()