yogeshbam's picture
Create app.py
dbef2c5 verified
import gradio as gr
import cv2
import imageio
import numpy as np
def generate_walking_animation(image):
video_height = 1920
video_width = 1080
fps = 30 # Frames per second
duration = 10 # Minimum duration in seconds
total_frames = fps * duration # 10 seconds of animation
video_filename = "walking_animation.mp4"
writer = imageio.get_writer(video_filename, fps=fps)
# Resize image to fit portrait mode
image = cv2.resize(image, (video_width, video_height // 2)) # Half height for walking effect
# Generate walking effect by shifting the image up/down
for i in range(total_frames):
shift_amount = (i % 20 - 10) # Move up and down
shifted_image = np.roll(image, shift_amount, axis=0)
writer.append_data(shifted_image)
writer.close()
return video_filename
demo = gr.Interface(
fn=generate_walking_animation,
inputs=gr.Image(type="numpy", label="Upload Character Image"),
outputs=gr.Video(),
title="10-Second Walking Animation Generator",
description="Upload an image of a character, and we generate a 10-second walking animation in portrait mode."
)
demo.launch()