Spaces:
Sleeping
Sleeping
Create app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import 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()12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import gradio as grfrom huggingface_hub import InferenceClient# Initialize the inference client for direct text-to-video generationclient = InferenceClient()def generate_video_from_text(prompt):if not prompt:return Noneprint(f"RustyAI Engine is manufacturing video for: {prompt}")try:# Call the external GPU cluster to build a video from text wordsvideo_bytes = client.text_to_video(prompt,model="Lightricks/LTX-Video")output_path = "rusty_text_motion.mp4"with open(output_path, "wb") as f:f.write(video_bytes)print("RustyAI Engine: Text-to-Video generation complete!")return output_pathexcept Exception as e:print(f"Text-to-Video Error: {e}")return None# Clean, simple UI layout for prompt typingwith gr.Blocks(title="RustyAI Text-to-Video") as demo:gr.Markdown("# π¬ RustyAI Text-to-Video Generator")gr.Markdown("Type a scene description below and watch the AI manifest it into a video clip.")with gr.Row():with gr.Column():user_prompt = gr.Textbox(label="Describe your video scene",placeholder="e.g., A multi-armed wooden creature swinging baseball bats in a dark room, analog horror style...")run_btn = gr.Button("Bake Video π", variant="primary")with gr.Column():video_output = gr.Video(label="Generated MP4 Output")run_btn.click(fn=generate_video_from_text, inputs=user_prompt, outputs=video_output)if __name__ == "__main__":demo.launch()
app.py+24-37