Spaces:
Runtime error
Runtime error
Download app.py from 786King786/AvatarifyAI: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/786King786/AvatarifyAI/resolve/main/app.py
- Command line
-
hf download hf://spaces/786King786/AvatarifyAI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/786King786/AvatarifyAI/resolve/main/app.py
1.12 kB
| import gradio as gr | |
| from diffusers import StableDiffusionPipeline | |
| import torch | |
| # Load Stable Diffusion model | |
| pipe = StableDiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo") | |
| pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") | |
| # Avatar 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" | |
| ] | |
| # Function to generate avatar | |
| def generate_avatar(image, style): | |
| prompt = f"{style} style portrait of a person" | |
| result = pipe(prompt=prompt, image=image).images[0] | |
| return result | |
| # Build Gradio UI | |
| gr.Interface( | |
| fn=generate_avatar, | |
| inputs=[ | |
| gr.Image(type="pil", label="Upload Your Selfie"), | |
| gr.Dropdown(choices=styles, label="Choose a Style") | |
| ], | |
| outputs=gr.Image(label="Your Avatar"), | |
| title="AvatarifyAI", | |
| description="Turn your selfie into an AI-generated avatar in awesome styles!" | |
| ) | |
| demo.launch() |