revert code app.py as the approach to use GPU as needed doesnot work
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ from handlers import video_handler as vh
|
|
| 11 |
model_path = "yolov8n.pt" # YOLOv8 model path
|
| 12 |
|
| 13 |
|
|
|
|
| 14 |
def process_video(video_file):
|
| 15 |
"""
|
| 16 |
Processes the uploaded video file by extracting key frames, cropping them, and generating a processed video.
|
|
@@ -51,18 +52,19 @@ def process_video(video_file):
|
|
| 51 |
# Step 1: Extract all frames
|
| 52 |
status_message = "Extracting frames. Please wait...!"
|
| 53 |
yield status_message, None
|
| 54 |
-
|
| 55 |
|
| 56 |
# Step 2 - extract key frames
|
| 57 |
status_message = "Extracting key frames. Please wait...!"
|
| 58 |
yield status_message, None
|
| 59 |
-
|
| 60 |
|
| 61 |
# Step 3 - cropping key frames while reserving key objects
|
| 62 |
status_message = "Cropping key frames. Please wait...!"
|
| 63 |
yield status_message, None
|
| 64 |
target_resolution = (360, 640) # Output resolution (9:16)
|
| 65 |
-
|
|
|
|
| 66 |
|
| 67 |
status_message = "Generating final video. Please wait...!"
|
| 68 |
yield status_message, None
|
|
@@ -74,21 +76,6 @@ def process_video(video_file):
|
|
| 74 |
status_message = "Processing complete!"
|
| 75 |
yield status_message, processed_video_path
|
| 76 |
|
| 77 |
-
|
| 78 |
-
def step_one(video_path, all_frames_folder, original_fps):
|
| 79 |
-
vh.extract_frames_by_rate(video_path, all_frames_folder, original_fps)
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
@spaces.GPU(duration=300)
|
| 83 |
-
def step_two(all_frames_folder, key_frames_folder, original_fps):
|
| 84 |
-
fh.extract_key_frames(all_frames_folder, key_frames_folder, original_fps, model_path)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
@spaces.GPU(duration=120)
|
| 88 |
-
def step_three(key_frames_folder, cropped_frames_folder, target_resolution):
|
| 89 |
-
fh.crop_preserve_key_objects(key_frames_folder, cropped_frames_folder, model_path, target_resolution)
|
| 90 |
-
|
| 91 |
-
|
| 92 |
# Gradio Blocks UI
|
| 93 |
with gr.Blocks() as demo:
|
| 94 |
gr.Markdown("## Generate short video for your football match")
|
|
|
|
| 11 |
model_path = "yolov8n.pt" # YOLOv8 model path
|
| 12 |
|
| 13 |
|
| 14 |
+
@spaces.GPU(duration=300)
|
| 15 |
def process_video(video_file):
|
| 16 |
"""
|
| 17 |
Processes the uploaded video file by extracting key frames, cropping them, and generating a processed video.
|
|
|
|
| 52 |
# Step 1: Extract all frames
|
| 53 |
status_message = "Extracting frames. Please wait...!"
|
| 54 |
yield status_message, None
|
| 55 |
+
vh.extract_frames_by_rate(video_path, all_frames_folder, original_fps)
|
| 56 |
|
| 57 |
# Step 2 - extract key frames
|
| 58 |
status_message = "Extracting key frames. Please wait...!"
|
| 59 |
yield status_message, None
|
| 60 |
+
fh.extract_key_frames(all_frames_folder, key_frames_folder, original_fps, model_path)
|
| 61 |
|
| 62 |
# Step 3 - cropping key frames while reserving key objects
|
| 63 |
status_message = "Cropping key frames. Please wait...!"
|
| 64 |
yield status_message, None
|
| 65 |
target_resolution = (360, 640) # Output resolution (9:16)
|
| 66 |
+
fh.crop_preserve_key_objects(key_frames_folder, cropped_frames_folder, model_path, target_resolution)
|
| 67 |
+
|
| 68 |
|
| 69 |
status_message = "Generating final video. Please wait...!"
|
| 70 |
yield status_message, None
|
|
|
|
| 76 |
status_message = "Processing complete!"
|
| 77 |
yield status_message, processed_video_path
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
# Gradio Blocks UI
|
| 80 |
with gr.Blocks() as demo:
|
| 81 |
gr.Markdown("## Generate short video for your football match")
|