File size: 878 Bytes
e860e58 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import gradio as gr
from PIL import Image
import os
# Mapping between text prompts and sprite animations
ANIMATIONS = {
"wave": "sprites/wave.gif",
"jump": "sprites/jump.gif",
"idle": "sprites/idle.gif",
}
def get_animation(prompt):
prompt = prompt.lower().strip()
# Pick a matching animation or fallback to idle
for keyword in ANIMATIONS:
if keyword in prompt:
return ANIMATIONS[keyword]
return ANIMATIONS["idle"]
with gr.Blocks() as demo:
gr.Markdown("# 🎮 2D Character Animator\nEnter a prompt like `wave`, `jump`, or `dance`.")
input_text = gr.Textbox(label="What should the character do?")
output_img = gr.Image(type="filepath", label="Animation")
run_btn = gr.Button("Animate!")
run_btn.click(fn=get_animation, inputs=input_text, outputs=output_img)
if __name__ == "__main__":
demo.launch()
|