Spaces:
Runtime error
Runtime error
Update app.py
Browse filesUpdated code and corrected video file correct
app.py
CHANGED
|
@@ -1,17 +1,41 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
|
|
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="AI Thumbnail Generator", layout="centered")
|
| 6 |
|
| 7 |
st.title("🎯 AI-Based Thumbnail Generator")
|
| 8 |
-
st.write("Upload a video
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
if
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
st.download_button("Download Thumbnail", uploaded_file, file_name="thumbnail.jpg")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import cv2
|
| 3 |
+
import tempfile
|
| 4 |
import os
|
| 5 |
+
from PIL import Image
|
| 6 |
|
| 7 |
st.set_page_config(page_title="AI Thumbnail Generator", layout="centered")
|
| 8 |
|
| 9 |
st.title("🎯 AI-Based Thumbnail Generator")
|
| 10 |
+
st.write("Upload a video to extract thumbnail-worthy frames using AI.")
|
| 11 |
+
|
| 12 |
+
uploaded_video = st.file_uploader("Upload Video File", type=["mp4", "mov", "avi", "mkv", "wmv"])
|
| 13 |
+
|
| 14 |
+
if uploaded_video is not None:
|
| 15 |
+
st.video(uploaded_video)
|
| 16 |
+
st.success("✅ Video uploaded successfully!")
|
| 17 |
+
|
| 18 |
+
# Save the uploaded video to a temp file
|
| 19 |
+
tfile = tempfile.NamedTemporaryFile(delete=False)
|
| 20 |
+
tfile.write(uploaded_video.read())
|
| 21 |
|
| 22 |
+
# Extract frames using OpenCV
|
| 23 |
+
vidcap = cv2.VideoCapture(tfile.name)
|
| 24 |
+
success, image = vidcap.read()
|
| 25 |
+
count = 0
|
| 26 |
+
thumbnail_frame = None
|
| 27 |
+
while success:
|
| 28 |
+
if count % 60 == 0: # extract every 2 seconds assuming 30 FPS
|
| 29 |
+
frame_path = f"frame_{count}.jpg"
|
| 30 |
+
cv2.imwrite(frame_path, image)
|
| 31 |
+
thumbnail_frame = frame_path # keep last extracted frame as mock thumbnail
|
| 32 |
+
success, image = vidcap.read()
|
| 33 |
+
count += 1
|
| 34 |
|
| 35 |
+
if thumbnail_frame:
|
| 36 |
+
st.subheader("Generated Thumbnail Frame")
|
| 37 |
+
image = Image.open(thumbnail_frame)
|
| 38 |
+
st.image(image, caption="Best Frame", use_column_width=True)
|
| 39 |
|
| 40 |
+
with open(thumbnail_frame, "rb") as file:
|
| 41 |
+
st.download_button("📥 Download Thumbnail", file, file_name="thumbnail.jpg")
|
|
|