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