# 🔹 app.py (Optimized with Path Handling & Real-time Previews) import streamlit as st import tempfile import os import numpy as np import cv2 import moviepy.editor as mp from model import AnimationGenerator # Initialize core system st.set_page_config(page_title="AI Stick Animation", layout="wide") st.title("🎭 Ultra-Advanced AI Stick Animation") class AnimationApp: def __init__(self): self.animator = AnimationGenerator() self.setup_ui() def setup_ui(self): col1, col2 = st.columns([2, 1]) with col1: self.story = st.text_area("📝 Story Script:", "John walks cautiously through the dark forest...", height=200) self.character = st.text_input("🎭 Main Character:", "John") with col2: self.background = st.selectbox("🌆 Background", ["None", "Dark Forest", "Haunted House", "City"]) self.camera_effect = st.selectbox("📽️ Camera Effect", ["None", "Dynamic Shake", "Cinematic Zoom", "Slow Motion"]) self.soundtrack = st.selectbox("🎶 Soundtrack", ["None", "Epic", "Suspense", "Upbeat"]) if st.button("🚀 Generate Animation"): self.process_animation() def process_animation(self): with st.spinner("🧠 AI is crafting your masterpiece..."): with tempfile.TemporaryDirectory() as tmp_dir: # Generate core animation video_path = self.animator.create_animation( self.story, self.character, self.background, self.camera_effect, self.soundtrack, tmp_dir ) # Display results st.success("✅ Animation Complete!") st.video(video_path) st.download_button("💾 Download", open(video_path, "rb"), file_name="ai_animation.mp4") if __name__ == "__main__": AnimationApp()