File size: 1,764 Bytes
4bece86 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import streamlit as st
import tempfile
import os
import numpy as np
import cv2
import moviepy.editor as mp
from model import generate_stick_animation, add_camera_effects, add_background, add_sound
# Streamlit UI
st.set_page_config(page_title="AI Stick Animation", layout="wide")
st.title("π AI Stick Animation Generator")
# User Inputs
story = st.text_area("π Enter Your Story:", "John is walking in a dark forest...")
character_name = st.text_input("π Enter Main Character Name:", "John")
# Extra Features Selection
background_choice = st.selectbox("π Choose Background", ["None", "Dark Forest", "Haunted House", "Battlefield"])
camera_effect = st.selectbox("π½οΈ Choose Camera Effect", ["None", "Shake", "Zoom", "Slow Motion"])
sound_effect = st.selectbox("πΆ Choose Background Music", ["None", "Horror", "Action", "Comedy"])
# Generate Animation Button
if st.button("π Generate Animation"):
with st.spinner("AI is generating animation..."):
output_frames = generate_stick_animation(story, character_name)
# Apply Extra Features
output_frames = add_camera_effects(output_frames, camera_effect)
output_frames = add_background(output_frames, background_choice)
# Save animation as MP4
temp_dir = tempfile.mkdtemp()
output_path = os.path.join(temp_dir, "animation.mp4")
clip = mp.ImageSequenceClip(output_frames, fps=24) # High FPS for smooth motion
clip.write_videofile(output_path, codec="libx264", fps=24)
# Add Sound Effect
final_video = add_sound(output_path, sound_effect)
# Display Video
st.video(final_video)
st.download_button("π₯ Download Animation", open(final_video, "rb"), file_name="stick_animation.mp4") |