Artificial-superintelligence commited on
Commit
cd153ea
·
verified ·
1 Parent(s): e6ca1ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  import yt_dlp
3
  import os
4
  import re
5
- import time
6
  from moviepy.video.io.VideoFileClip import VideoFileClip
7
 
8
  # Function to sanitize the filename
@@ -38,7 +37,7 @@ def crop_video(input_path, start_time, end_time):
38
  try:
39
  with VideoFileClip(input_path) as video:
40
  cropped_video = video.subclip(start_time, end_time)
41
- cropped_video.write_videofile(output_path, codec='libx264')
42
  return output_path
43
  except Exception as e:
44
  return str(e)
@@ -73,16 +72,14 @@ def gradio_interface():
73
  status_message.value = "Cropping video..."
74
  cropped_video_path = crop_video(video_path, start_time, end_time)
75
  if cropped_video_path and os.path.exists(cropped_video_path):
76
- time.sleep(1) # Add a slight delay to ensure file is fully written
77
- status_message.value = "Done! You can download your video below."
78
- return cropped_video_path
79
  else:
80
  status_message.value = "Error cropping video."
81
  else:
82
  status_message.value = "Error downloading video. Please check the URL."
83
- return None
84
 
85
- process_btn.click(process_video, inputs=[url_input, start_time_input, end_time_input], outputs=[output_file])
86
 
87
  return demo
88
 
 
2
  import yt_dlp
3
  import os
4
  import re
 
5
  from moviepy.video.io.VideoFileClip import VideoFileClip
6
 
7
  # Function to sanitize the filename
 
37
  try:
38
  with VideoFileClip(input_path) as video:
39
  cropped_video = video.subclip(start_time, end_time)
40
+ cropped_video.write_videofile(output_path, codec='libx264', audio_codec='aac')
41
  return output_path
42
  except Exception as e:
43
  return str(e)
 
72
  status_message.value = "Cropping video..."
73
  cropped_video_path = crop_video(video_path, start_time, end_time)
74
  if cropped_video_path and os.path.exists(cropped_video_path):
75
+ return cropped_video_path, "Done! You can download your video below."
 
 
76
  else:
77
  status_message.value = "Error cropping video."
78
  else:
79
  status_message.value = "Error downloading video. Please check the URL."
80
+ return None, status_message.value
81
 
82
+ process_btn.click(process_video, inputs=[url_input, start_time_input, end_time_input], outputs=[output_file, status_message])
83
 
84
  return demo
85