Spaces:
Sleeping
Sleeping
Download app.py from JasonOost/anime-generator: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/JasonOost/anime-generator/resolve/main/app.py
- Command line
-
hf download hf://spaces/JasonOost/anime-generator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/JasonOost/anime-generator/resolve/main/app.py
1.37 kB
| 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" | |
| 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() | |