Spaces:
Sleeping
Sleeping
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import gradio as grfrom huggingface_hub import InferenceClientfrom PIL import Imageimport os# Connecting to the ultimate image-to-video processing backendclient = InferenceClient()def animate_uploaded_image(input_image, motion_prompt):if input_image is None:return None# Convert the user's uploaded picture into the correct pixel formatimg = Image.fromarray(input_image)# If you leave the text box blank, it defaults to a clean, smooth animation sequencefinal_prompt = motion_prompt if motion_prompt else "smooth animation, high quality, realistic motion"print(f"RustyAI Engine is animating your image with motion: {final_prompt}")try:# Passes your actual file directly to the external animation modelvideo_bytes = client.image_to_video(image=img,prompt=final_prompt,model="Lightricks/LTX-Video")output_filename = "rusty_animated_output.mp4"with open(output_filename, "wb") as f:f.write(video_bytes)return output_filenameexcept Exception as e:print(f"Animation Error: {e}")return None# Setting up the exact Image-to-Animation interface for RustyAIwith gr.Blocks(title="RustyAI Image Animator") as demo:gr.Markdown("# π¬ RustyAI Image-to-Animation Machine")gr.Markdown("Upload a static image, type how it should move, and watch your AI animate it!")with gr.Row():with gr.Column():user_image = gr.Image(label="1. Drag or Upload your photo here")user_prompt = gr.Textbox(label="2. Motion Prompt (Optional)",placeholder="e.g., the character walks forward, camera shakes, eyes blink...")run_btn = gr.Button("Animate My Image π", variant="primary")with gr.Column():video_output = gr.Video(label="Your Animated Result")run_btn.click(fn=animate_uploaded_image,inputs=[user_image, user_prompt],outputs=video_output)if __name__ == "__main__":demo.launch()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import gradio as grfrom moviepy.editor import ImageClipimport tempfileimport osdef image_to_video(image, duration, fps):if image is None:return None# Create a temporary file for the output videotmp_dir = tempfile.mkdtemp()output_path = os.path.join(tmp_dir, "output.mp4")# Create a video clip from the imageclip = ImageClip(image).set_duration(duration)clip = clip.set_fps(fps)# Write the video fileclip.write_videofile(output_path,codec="libx264",audio=False,fps=fps,verbose=False,logger=None)return output_pathwith gr.Blocks() as demo:gr.Markdown("# RustyAI Image β Video π₯")gr.Markdown("Upload an image and RustyAI will turn it into a video.")with gr.Row():with gr.Column():img_input = gr.Image(type="numpy", label="Input image")duration_input = gr.Slider(1, 15, value=5, step=1, label="Duration (seconds)")fps_input = gr.Slider(5, 60, value=24, step=1, label="FPS")btn = gr.Button("Generate Video")with gr.Column():video_output = gr.Video(label="Output video")btn.click(fn=image_to_video,inputs=[img_input, duration_input, fps_input],outputs=video_output)if __name__ == "__main__":demo.launch()
app.py+38-48