Spaces:
Build error
Build error
Download app.py from 786King786/AvratarifyAI: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/786King786/AvratarifyAI/resolve/main/app.py
- Command line
-
hf download hf://spaces/786King786/AvratarifyAI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/786King786/AvratarifyAI/resolve/main/app.py
1.13 kB
| import gradio as gr | |
| from diffusers import StableDiffusionPipeline | |
| import torch | |
| # Load model | |
| pipe = StableDiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo") | |
| pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") | |
| # Available styles | |
| styles = [ | |
| "Anime", "Cartoon", "Pixel Art", "Cyberpunk", "Disney", | |
| "GTA", "Barbie", "Pixar", "Watercolor", "3D Render", | |
| "Futuristic Soldier", "Zombie Apocalypse", "Royal Portrait", | |
| "Oil Painting", "Astronaut", "Cyber Angel", "Superhero", | |
| "Line Art Sketch", "Pop Art", "Cute Chibi" | |
| ] | |
| # Avatar generation function | |
| def generate_avatar(name, style): | |
| prompt = f"{style} style portrait of {name}" | |
| image = pipe(prompt=prompt).images[0] | |
| return image | |
| # Gradio UI | |
| gr.Interface( | |
| fn=generate_avatar, | |
| inputs=[ | |
| gr.Textbox(label="Who do you want to see? (e.g. a young woman, a boy, etc.)"), | |
| gr.Dropdown(choices=styles, label="Choose a Style") | |
| ], | |
| outputs=gr.Image(label="Generated Avatar"), | |
| title="AvatarifyAI", | |
| description="Generate stylish avatars using SDXL Turbo. Enter who you want to see and select a style!" | |
| ).launch() |