asad231 commited on
Commit
83ad611
·
verified ·
1 Parent(s): 8fd4d5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -3,6 +3,7 @@ import numpy as np
3
  import cv2
4
  import tempfile
5
  import requests
 
6
  from PIL import Image
7
  from pytube import YouTube
8
  import os
@@ -290,7 +291,7 @@ def download_video(url):
290
  except Exception as e:
291
  return None
292
 
293
- # ✅ Display Video (YouTube Embed or Local)
294
  video_path = None
295
 
296
  if uploaded_video is not None:
@@ -298,18 +299,36 @@ if uploaded_video is not None:
298
  with open(temp_file.name, "wb") as f:
299
  f.write(uploaded_video.read())
300
  video_path = temp_file.name # Set video path for detection
301
- st.video(video_path) # Show uploaded video
 
 
 
 
 
 
 
 
 
 
 
302
 
303
  elif video_url:
304
  if "youtube.com" in video_url or "youtu.be" in video_url:
305
  st.markdown(
306
- f'<iframe width="560" height="315" src="{video_url.replace("watch?v=", "embed/")}" frameborder="0" allowfullscreen></iframe>',
307
  unsafe_allow_html=True,
308
  )
309
  else:
310
  video_path = download_video(video_url) # Download MP4
311
  if video_path:
312
- st.video(video_path) # Show downloaded MP4
 
 
 
 
 
 
 
313
  else:
314
  st.warning("⚠️ Invalid MP4 URL.")
315
 
@@ -328,5 +347,6 @@ if uploaded_video or (video_url and not "youtube.com" in video_url):
328
  else:
329
  st.warning("⚠️ Unable to analyze the video. Please try a different file.")
330
 
 
331
 
332
  st.markdown("🔹 **Developed for Fake News & Deepfake Detection**")
 
3
  import cv2
4
  import tempfile
5
  import requests
6
+ import base64
7
  from PIL import Image
8
  from pytube import YouTube
9
  import os
 
291
  except Exception as e:
292
  return None
293
 
294
+ # ✅ Display Video (YouTube Embed or Small Embedded Video)
295
  video_path = None
296
 
297
  if uploaded_video is not None:
 
299
  with open(temp_file.name, "wb") as f:
300
  f.write(uploaded_video.read())
301
  video_path = temp_file.name # Set video path for detection
302
+
303
+ # Convert video to base64
304
+ with open(video_path, "rb") as video_file:
305
+ video_base64 = base64.b64encode(video_file.read()).decode("utf-8")
306
+
307
+ # 🔹 **Small Embedded Video Display**
308
+ st.markdown(
309
+ f"""
310
+ <iframe width="300" height="170" src="data:video/mp4;base64,{video_base64}" frameborder="0" allowfullscreen></iframe>
311
+ """,
312
+ unsafe_allow_html=True,
313
+ )
314
 
315
  elif video_url:
316
  if "youtube.com" in video_url or "youtu.be" in video_url:
317
  st.markdown(
318
+ f'<iframe width="300" height="170" src="{video_url.replace("watch?v=", "embed/")}" frameborder="0" allowfullscreen></iframe>',
319
  unsafe_allow_html=True,
320
  )
321
  else:
322
  video_path = download_video(video_url) # Download MP4
323
  if video_path:
324
+ with open(video_path, "rb") as video_file:
325
+ video_base64 = base64.b64encode(video_file.read()).decode("utf-8")
326
+ st.markdown(
327
+ f"""
328
+ <iframe width="300" height="170" src="data:video/mp4;base64,{video_base64}" frameborder="0" allowfullscreen></iframe>
329
+ """,
330
+ unsafe_allow_html=True,
331
+ )
332
  else:
333
  st.warning("⚠️ Invalid MP4 URL.")
334
 
 
347
  else:
348
  st.warning("⚠️ Unable to analyze the video. Please try a different file.")
349
 
350
+
351
 
352
  st.markdown("🔹 **Developed for Fake News & Deepfake Detection**")