SabkeSawaal68 commited on
Commit
7769943
Β·
verified Β·
1 Parent(s): 5eba0be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -37
app.py CHANGED
@@ -1,45 +1,58 @@
1
- import os
2
- os.system("pip install opencv-python-headless") # Ensure OpenCV is installed
3
- import cv2
4
  import streamlit as st
5
  import tempfile
6
  import os
7
  import numpy as np
8
  import cv2
9
  import moviepy.editor as mp
10
- from model import generate_stick_animation, add_camera_effects, add_background, add_sound
11
 
12
- # Streamlit UI
13
  st.set_page_config(page_title="AI Stick Animation", layout="wide")
14
- st.title("🎭 AI Stick Animation Generator")
15
-
16
- # User Inputs
17
- story = st.text_area("πŸ“ Enter Your Story:", "John is walking in a dark forest...")
18
- character_name = st.text_input("🎭 Enter Main Character Name:", "John")
19
-
20
- # Extra Features Selection
21
- background_choice = st.selectbox("πŸŒ† Choose Background", ["None", "Dark Forest", "Haunted House", "Battlefield"])
22
- camera_effect = st.selectbox("πŸ“½οΈ Choose Camera Effect", ["None", "Shake", "Zoom", "Slow Motion"])
23
- sound_effect = st.selectbox("🎢 Choose Background Music", ["None", "Horror", "Action", "Comedy"])
24
-
25
- # Generate Animation Button
26
- if st.button("πŸš€ Generate Animation"):
27
- with st.spinner("AI is generating animation..."):
28
- output_frames = generate_stick_animation(story, character_name)
29
-
30
- # Apply Extra Features
31
- output_frames = add_camera_effects(output_frames, camera_effect)
32
- output_frames = add_background(output_frames, background_choice)
33
-
34
- # Save animation as MP4
35
- temp_dir = tempfile.mkdtemp()
36
- output_path = os.path.join(temp_dir, "animation.mp4")
37
- clip = mp.ImageSequenceClip(output_frames, fps=24) # High FPS for smooth motion
38
- clip.write_videofile(output_path, codec="libx264", fps=24)
39
-
40
- # Add Sound Effect
41
- final_video = add_sound(output_path, sound_effect)
42
-
43
- # Display Video
44
- st.video(final_video)
45
- st.download_button("πŸ“₯ Download Animation", open(final_video, "rb"), file_name="stick_animation.mp4")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # πŸ”Ή app.py (Optimized with Path Handling & Real-time Previews)
2
+
 
3
  import streamlit as st
4
  import tempfile
5
  import os
6
  import numpy as np
7
  import cv2
8
  import moviepy.editor as mp
9
+ from model import AnimationGenerator
10
 
11
+ # Initialize core system
12
  st.set_page_config(page_title="AI Stick Animation", layout="wide")
13
+ st.title("🎭 Ultra-Advanced AI Stick Animation")
14
+
15
+ class AnimationApp:
16
+ def __init__(self):
17
+ self.animator = AnimationGenerator()
18
+ self.setup_ui()
19
+
20
+ def setup_ui(self):
21
+ col1, col2 = st.columns([2, 1])
22
+ with col1:
23
+ self.story = st.text_area("πŸ“ Story Script:",
24
+ "John walks cautiously through the dark forest...", height=200)
25
+ self.character = st.text_input("🎭 Main Character:", "John")
26
+
27
+ with col2:
28
+ self.background = st.selectbox("πŸŒ† Background",
29
+ ["None", "Dark Forest", "Haunted House", "City"])
30
+ self.camera_effect = st.selectbox("πŸ“½οΈ Camera Effect",
31
+ ["None", "Dynamic Shake", "Cinematic Zoom", "Slow Motion"])
32
+ self.soundtrack = st.selectbox("🎢 Soundtrack",
33
+ ["None", "Epic", "Suspense", "Upbeat"])
34
+
35
+ if st.button("πŸš€ Generate Animation"):
36
+ self.process_animation()
37
+
38
+ def process_animation(self):
39
+ with st.spinner("🧠 AI is crafting your masterpiece..."):
40
+ with tempfile.TemporaryDirectory() as tmp_dir:
41
+ # Generate core animation
42
+ video_path = self.animator.create_animation(
43
+ self.story,
44
+ self.character,
45
+ self.background,
46
+ self.camera_effect,
47
+ self.soundtrack,
48
+ tmp_dir
49
+ )
50
+
51
+ # Display results
52
+ st.success("βœ… Animation Complete!")
53
+ st.video(video_path)
54
+ st.download_button("πŸ’Ύ Download", open(video_path, "rb"),
55
+ file_name="ai_animation.mp4")
56
+
57
+ if __name__ == "__main__":
58
+ AnimationApp()