Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -19,19 +19,7 @@ client = OpenAI(
|
|
19 |
# Streamlit App UI
|
20 |
st.title("🎥 AI-Powered Video Summarization")
|
21 |
# Define custom CSS
|
22 |
-
|
23 |
-
st.markdown(
|
24 |
-
"""
|
25 |
-
<style>
|
26 |
-
.big-font {
|
27 |
-
font-size: 30px !important;
|
28 |
-
font-weight: bold;
|
29 |
-
color: black;
|
30 |
-
}
|
31 |
-
</style>
|
32 |
-
""",
|
33 |
-
unsafe_allow_html=True
|
34 |
-
)
|
35 |
|
36 |
def set_background(image_file):
|
37 |
with open(image_file, "rb") as image:
|
@@ -136,17 +124,30 @@ if uploaded_file:
|
|
136 |
text_to_speech(summary)
|
137 |
st.audio('summary_audio.mp3')
|
138 |
|
139 |
-
# # Combine Audio & Video
|
140 |
-
# st.write("🎬 Merging audio with the video...")
|
141 |
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
-
|
151 |
|
152 |
-
|
|
|
19 |
# Streamlit App UI
|
20 |
st.title("🎥 AI-Powered Video Summarization")
|
21 |
# Define custom CSS
|
22 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def set_background(image_file):
|
25 |
with open(image_file, "rb") as image:
|
|
|
124 |
text_to_speech(summary)
|
125 |
st.audio('summary_audio.mp3')
|
126 |
|
|
|
|
|
127 |
|
128 |
+
import moviepy.editor as mp
|
129 |
+
|
130 |
+
def create_summary_video(image_folder, output_video):
|
131 |
+
images = sorted([os.path.join(image_folder, img) for img in os.listdir(image_folder) if img.endswith(".jpg")])
|
132 |
+
clips = [mp.ImageClip(img).set_duration(2) for img in images] # 2 sec per frame
|
133 |
+
|
134 |
+
video = mp.concatenate_videoclips(clips, method="compose")
|
135 |
+
video.write_videofile(output_video, fps=24)
|
136 |
+
|
137 |
+
# Example usage
|
138 |
+
create_summary_video("scenes", "summary_video.mp4")
|
139 |
+
|
140 |
+
# Combine Audio & Video
|
141 |
+
st.write("🎬 Merging audio with the video...")
|
142 |
+
|
143 |
+
def add_audio_to_video(video_path, audio_path, output_video="final_video.mp4"):
|
144 |
+
video = mp.VideoFileClip(video_path)
|
145 |
+
audio = mp.AudioFileClip(audio_path)
|
146 |
+
if audio.duration > video.duration:
|
147 |
+
audio = audio.subclip(0, video.duration)
|
148 |
+
final_video = video.set_audio(audio)
|
149 |
+
final_video.write_videofile(output_video, codec="libx264", audio_codec="aac")
|
150 |
|
151 |
+
add_audio_to_video("summary_video.mp4", "summary_audio.mp3")
|
152 |
|
153 |
+
st.video("final_video.mp4")
|