asad231 commited on
Commit
db588d5
·
verified ·
1 Parent(s): ad42a25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -4
app.py CHANGED
@@ -407,6 +407,24 @@ def detect_deepfake_video(video_path):
407
 
408
  return {"label": final_label, "score": confidence}
409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
  # Process Uploaded Video
411
  if uploaded_video is not None:
412
  st.video(uploaded_video) # Show uploaded video
@@ -418,10 +436,7 @@ if uploaded_video is not None:
418
  # Process Video from URL
419
  elif video_url:
420
  st.video(video_url) # Show the video directly from URL
421
- video_path = video_url # Use URL for detection
422
-
423
- else:
424
- video_path = None
425
 
426
  # Analyze Button
427
  if video_path and st.button("Analyze Video"):
 
407
 
408
  return {"label": final_label, "score": confidence}
409
 
410
+ # Download video from URL
411
+ def download_video(url):
412
+ try:
413
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
414
+ response = requests.get(url, stream=True)
415
+ if response.status_code == 200:
416
+ with open(temp_file.name, "wb") as f:
417
+ for chunk in response.iter_content(chunk_size=1024):
418
+ f.write(chunk)
419
+ return temp_file.name
420
+ else:
421
+ return None
422
+ except Exception as e:
423
+ return None
424
+
425
+ # Select Video Source
426
+ video_path = None
427
+
428
  # Process Uploaded Video
429
  if uploaded_video is not None:
430
  st.video(uploaded_video) # Show uploaded video
 
436
  # Process Video from URL
437
  elif video_url:
438
  st.video(video_url) # Show the video directly from URL
439
+ video_path = download_video(video_url) # Download the video for analysis
 
 
 
440
 
441
  # Analyze Button
442
  if video_path and st.button("Analyze Video"):