Update app.py
Browse files
app.py
CHANGED
@@ -291,23 +291,19 @@ def download_video(url):
|
|
291 |
return None
|
292 |
|
293 |
# Download YouTube video
|
294 |
-
def
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
|
301 |
-
video_stream.download(filename=temp_file.name)
|
302 |
-
return temp_file.name, yt.title, yt.thumbnail_url # Return video title & thumbnail
|
303 |
-
except Exception as e:
|
304 |
-
return None, None, None
|
305 |
|
306 |
# Select Video Source
|
307 |
video_path = None
|
308 |
video_display_url = None
|
309 |
video_title = None
|
310 |
video_thumbnail = None
|
|
|
311 |
|
312 |
# Process Uploaded Video
|
313 |
if uploaded_video is not None:
|
@@ -321,27 +317,20 @@ if uploaded_video is not None:
|
|
321 |
# Process Video from URL (Check if YouTube or Direct Link)
|
322 |
elif video_url:
|
323 |
if "youtube.com" in video_url or "youtu.be" in video_url:
|
324 |
-
|
325 |
-
|
326 |
else:
|
327 |
video_path = download_video(video_url) # Download direct MP4 video
|
328 |
-
video_display_url =
|
329 |
video_title = "Online MP4 Video"
|
330 |
|
331 |
-
# ✅
|
332 |
-
if
|
333 |
-
st.markdown(f"### 🎬 {video_title}")
|
334 |
-
|
335 |
-
|
336 |
-
st.markdown(
|
337 |
-
|
338 |
-
<video controls width="300">
|
339 |
-
<source src="{video_display_url}" type="video/mp4">
|
340 |
-
Your browser does not support the video tag.
|
341 |
-
</video>
|
342 |
-
""",
|
343 |
-
unsafe_allow_html=True,
|
344 |
-
)
|
345 |
|
346 |
# ✅ "Analyze Video" بٹن ہمیشہ شو ہوگا
|
347 |
analyze_button = st.button("Analyze Video")
|
|
|
291 |
return None
|
292 |
|
293 |
# Download YouTube video
|
294 |
+
def get_youtube_embed_code(youtube_url):
|
295 |
+
"""Generate an embedded iframe for YouTube videos"""
|
296 |
+
return f"""
|
297 |
+
<iframe width="560" height="315" src="https://www.youtube.com/embed/{youtube_url.split('=')[-1]}"
|
298 |
+
frameborder="0" allowfullscreen></iframe>
|
299 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
300 |
|
301 |
# Select Video Source
|
302 |
video_path = None
|
303 |
video_display_url = None
|
304 |
video_title = None
|
305 |
video_thumbnail = None
|
306 |
+
youtube_embed = None
|
307 |
|
308 |
# Process Uploaded Video
|
309 |
if uploaded_video is not None:
|
|
|
317 |
# Process Video from URL (Check if YouTube or Direct Link)
|
318 |
elif video_url:
|
319 |
if "youtube.com" in video_url or "youtu.be" in video_url:
|
320 |
+
youtube_embed = get_youtube_embed_code(video_url) # Get embedded iframe
|
321 |
+
video_title = "YouTube Video"
|
322 |
else:
|
323 |
video_path = download_video(video_url) # Download direct MP4 video
|
324 |
+
video_display_url = video_path
|
325 |
video_title = "Online MP4 Video"
|
326 |
|
327 |
+
# ✅ Display Video Properly
|
328 |
+
if youtube_embed:
|
329 |
+
st.markdown(f"### 🎬 {video_title}")
|
330 |
+
st.markdown(youtube_embed, unsafe_allow_html=True) # Show YouTube Video
|
331 |
+
elif video_display_url:
|
332 |
+
st.markdown(f"### 🎬 {video_title}")
|
333 |
+
st.video(video_display_url) # Show Uploaded or MP4 URL Video
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
|
335 |
# ✅ "Analyze Video" بٹن ہمیشہ شو ہوگا
|
336 |
analyze_button = st.button("Analyze Video")
|