|
import gradio as gr |
|
from PIL import Image |
|
import os |
|
|
|
|
|
ANIMATIONS = { |
|
"wave": "sprites/wave.gif", |
|
"jump": "sprites/jump.gif", |
|
"idle": "sprites/idle.gif", |
|
} |
|
|
|
def get_animation(prompt): |
|
prompt = prompt.lower().strip() |
|
|
|
|
|
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() |
|
|