Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import 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()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import gradio as grfrom huggingface_hub import InferenceClientfrom PIL import Imageimport os# Connecting to the high-performance Stable Video Diffusion clusterclient = InferenceClient()def transform_image_to_video(uploaded_image):# Check if the user actually uploaded a fileif uploaded_image is None:return Noneprint("RustyAI Engine: Converting image array to PIL format...")# Convert the raw image data into a format Python can processinput_img = Image.fromarray(uploaded_image)print("RustyAI Engine: Sending file to external GPU cluster for animation...")try:# Call the high-speed serverless endpoint using Stable Video Diffusionvideo_bytes = client.image_to_video(image=input_img,model="stabilityai/stable-video-diffusion-img2vid-xt")# Define the path where the finished video clip will saveoutput_file_path = "rusty_ai_animation.mp4"# Write the video bytes into an actual playable MP4 filewith open(output_file_path, "wb") as f:f.write(video_bytes)print("RustyAI Engine: Video successfully baked!")return output_file_pathexcept Exception as e:print(f"Server Error caught during animation: {e}")return None# π οΈ Designing the Clean RustyAI Studio Interfacewith gr.Blocks(title="RustyAI Video Studio") as demo:gr.Markdown("# π¬ RustyAI Image-to-Video Machine")gr.Markdown("Drop any image format (`.webp`, `.png`, `.jpg`) into the slot and turn it into an animated video clip instantly.")with gr.Row():with gr.Column():image_slot = gr.Image(label="Upload Your Static Image Here")generate_button = gr.Button("Bake Video File π", variant="primary")with gr.Column():video_slot = gr.Video(label="Generated MP4 Output")# Connect the button directly to our new Python processing functiongenerate_button.click(fn=transform_image_to_video,inputs=image_slot,outputs=video_slot)# Launch the local server web appif __name__ == "__main__":demo.launch()
app.py+51-39