Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -19,8 +19,18 @@ client = OpenAI(
|
|
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:
|
26 |
encoded_string = base64.b64encode(image.read()).decode()
|
@@ -39,11 +49,13 @@ def set_background(image_file):
|
|
39 |
unsafe_allow_html=True
|
40 |
)
|
41 |
|
|
|
|
|
42 |
# Set background
|
43 |
set_background("yellow-wallpaper.jpg")
|
44 |
|
45 |
|
46 |
-
uploaded_file = st.file_uploader("
|
47 |
|
48 |
if uploaded_file:
|
49 |
video_path = "input_video.mp4"
|
@@ -53,7 +65,7 @@ if uploaded_file:
|
|
53 |
st.video(video_path)
|
54 |
|
55 |
# Scene Detection & Frame Extraction
|
56 |
-
st.write("
|
57 |
|
58 |
def extract_key_frames(video_path, output_folder="frames"):
|
59 |
os.makedirs(output_folder, exist_ok=True)
|
@@ -78,7 +90,7 @@ if uploaded_file:
|
|
78 |
extract_key_frames(video_path)
|
79 |
|
80 |
# Caption Generation
|
81 |
-
st.write("
|
82 |
|
83 |
def generate_caption(image_path):
|
84 |
image = Image.open(image_path).convert("RGB")
|
@@ -95,7 +107,7 @@ if uploaded_file:
|
|
95 |
# st.write("π Generated Captions:", captions)
|
96 |
|
97 |
# Summarization
|
98 |
-
st.write("
|
99 |
|
100 |
def summarize_captions(captions):
|
101 |
prompt = f"Summarize the following sequence of video frames into a meaningful story under 800 characters:\n\n{captions}"
|
@@ -113,7 +125,7 @@ if uploaded_file:
|
|
113 |
st.write("π Video Summary:", summary)
|
114 |
|
115 |
# Text-to-Speech
|
116 |
-
st.write("
|
117 |
|
118 |
def text_to_speech(text, output_audio="summary_audio.mp3"):
|
119 |
tts = gTTS(text, lang="en")
|
|
|
19 |
# Streamlit App UI
|
20 |
st.title("π₯ AI-Powered Video Summarization")
|
21 |
# Define custom CSS
|
22 |
+
st.markdown(
|
23 |
+
"""
|
24 |
+
<style>
|
25 |
+
body, .stApp {
|
26 |
+
font-size: 20px !important;
|
27 |
+
font-weight: bold;
|
28 |
+
color: black;
|
29 |
+
}
|
30 |
+
</style>
|
31 |
+
""",
|
32 |
+
unsafe_allow_html=True
|
33 |
+
)
|
34 |
def set_background(image_file):
|
35 |
with open(image_file, "rb") as image:
|
36 |
encoded_string = base64.b64encode(image.read()).decode()
|
|
|
49 |
unsafe_allow_html=True
|
50 |
)
|
51 |
|
52 |
+
|
53 |
+
|
54 |
# Set background
|
55 |
set_background("yellow-wallpaper.jpg")
|
56 |
|
57 |
|
58 |
+
uploaded_file = st.file_uploader("<h2 style='font-size:30px; color:black;'>π€ Upload a Video File</h2>", type=["mp4"])
|
59 |
|
60 |
if uploaded_file:
|
61 |
video_path = "input_video.mp4"
|
|
|
65 |
st.video(video_path)
|
66 |
|
67 |
# Scene Detection & Frame Extraction
|
68 |
+
st.write("<h2 style='font-size:30px; color:black;'>π Detecting scene changes and extracting key frames...</h2>")
|
69 |
|
70 |
def extract_key_frames(video_path, output_folder="frames"):
|
71 |
os.makedirs(output_folder, exist_ok=True)
|
|
|
90 |
extract_key_frames(video_path)
|
91 |
|
92 |
# Caption Generation
|
93 |
+
st.write("<h2 style='font-size:30px; color:black;'>π Generating captions for extracted frames...</h2>")
|
94 |
|
95 |
def generate_caption(image_path):
|
96 |
image = Image.open(image_path).convert("RGB")
|
|
|
107 |
# st.write("π Generated Captions:", captions)
|
108 |
|
109 |
# Summarization
|
110 |
+
st.write("<h2 style='font-size:30px; color:black;'>π Summarizing captions using AI...</h2>")
|
111 |
|
112 |
def summarize_captions(captions):
|
113 |
prompt = f"Summarize the following sequence of video frames into a meaningful story under 800 characters:\n\n{captions}"
|
|
|
125 |
st.write("π Video Summary:", summary)
|
126 |
|
127 |
# Text-to-Speech
|
128 |
+
st.write("<h2 style='font-size:30px; color:black;'>π Generating voice narration...</h2>")
|
129 |
|
130 |
def text_to_speech(text, output_audio="summary_audio.mp3"):
|
131 |
tts = gTTS(text, lang="en")
|