Spaces:
Sleeping
Sleeping
Create app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import gradio as grfrom huggingface_hub import InferenceClientfrom PIL import Imageimport os
# We use the official LTX-Video model engine by Lightricks for fast rendering!client = InferenceClient("Lightricks/LTX-Video")
def generate_video(input_image, prompt): if input_image is None: return None # 1. Convert the uploaded image to the proper format img = Image.fromarray(input_image) # 2. Add a default motion direction if the user left the prompt blank final_prompt = prompt if prompt else "gentle motion, smooth animation, high quality" print("Sending image to Hugging Face video cluster...") # 3. Call the high-speed Hugging Face server to animate the static image video_bytes = client.image_to_video( image=img, prompt=final_prompt ) # 4. Save the generated video file locally so Gradio can play it output_path = "animated_output.mp4" with open(output_path, "wb") as f: f.write(video_bytes) return output_path
# 🛠️ Build the Interactive App Interfacewith gr.Blocks(title="Rusty's Image-to-Video Animator") as demo: gr.Markdown("# 🎬 Rusty's Image-to-Video Animator") gr.Markdown("Upload a static photo, type how you want it to move, and watch the AI animate it!") with gr.Row(): with gr.Column(): input_img = gr.Image(label="1. Drag your image here") motion_prompt = gr.Textbox( label="2. Motion Prompt (Optional)", placeholder="e.g., the mouth opens and talks, blinking eyes, camera zooms in..." ) run_btn = gr.Button("Animate Video 🚀", variant="primary") with gr.Column(): output_video = gr.Video(label="AI Animated Result") # Connect the button to our Python animation function run_btn.click( fn=generate_video, inputs=[input_img, motion_prompt], outputs=output_video )
if __name__ == "__main__": demo.launch()app.pyAdded+59