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()