Spaces:
Sleeping
Sleeping
Create app.py
Browse files12342673456910111213141516171819202122232425262728293031327891034353637381140414243444546474849505112131415161753541819202122235924import 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 dummy_video_process(video): # For now, just return the same video return 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_pathwith gr.Blocks() as demo: gr.Markdown("# RustyVideo ๐ฅ") gr.Markdown("Upload a video and RustyAI will (soon) do something crazy with it.")
# ๐ ๏ธ 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 input_video = gr.Video(label="Input video") output_video = gr.Video(label="Output video")
run_btn = gr.Button("Process with RustyAI")
run_btn.click( fn=generate_video, inputs=[input_img, motion_prompt], fn=dummy_video_process, inputs=input_video, outputs=output_video )
if __name__ == "__main__": demo.launch() demo.launch()app.py+14-49