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 formatimg = Image.fromarray(input_image)# 2. Add a default motion direction if the user left the prompt blankfinal_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 imagevideo_bytes = client.image_to_video(image=img,prompt=final_prompt)# 4. Save the generated video file locally so Gradio can play itoutput_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 functionrun_btn.click(fn=generate_video,inputs=[input_img, motion_prompt],outputs=output_video)if __name__ == "__main__":demo.launch()123456789101112131415161718192021222324import gradio as grdef dummy_video_process(video):# For now, just return the same videoreturn videowith gr.Blocks() as demo:gr.Markdown("# RustyVideo ๐ฅ")gr.Markdown("Upload a video and RustyAI will (soon) do something crazy with it.")with gr.Row():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=dummy_video_process,inputs=input_video,outputs=output_video)if __name__ == "__main__":demo.launch()
app.py+14-49