Update app.py
Browse files
app.py
CHANGED
|
@@ -50,8 +50,9 @@ def generate_journal_with_images(video_path):
|
|
| 50 |
# Make predictions using YOLOv10 on the current frame
|
| 51 |
results = model.predict(source=frame_rgb, device=device)
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
# Save the image with bounding boxes
|
| 57 |
frame_filename = os.path.join(output_folder, f"frame_{frame_count}.jpg")
|
|
@@ -59,7 +60,7 @@ def generate_journal_with_images(video_path):
|
|
| 59 |
saved_images.append(frame_filename)
|
| 60 |
|
| 61 |
# Extract labels (class indices) and map them to class names
|
| 62 |
-
detected_objects = [model.names[int(box.cls)] for box in results.boxes]
|
| 63 |
|
| 64 |
# Get current timestamp in the video
|
| 65 |
timestamp = cap.get(cv2.CAP_PROP_POS_MSEC) / 1000 # Convert ms to seconds
|
|
@@ -98,7 +99,7 @@ def display_journal_with_images(video):
|
|
| 98 |
return display_items
|
| 99 |
|
| 100 |
with gr.Blocks() as iface:
|
| 101 |
-
video_input = gr.Video(label="Upload Video")
|
| 102 |
output_gallery = gr.Gallery(label="Generated Daily Journal with Images")
|
| 103 |
run_button = gr.Button("Generate Journal")
|
| 104 |
|
|
|
|
| 50 |
# Make predictions using YOLOv10 on the current frame
|
| 51 |
results = model.predict(source=frame_rgb, device=device)
|
| 52 |
|
| 53 |
+
# Loop through the list of results and render bounding boxes
|
| 54 |
+
for result in results:
|
| 55 |
+
result.render() # Render the results on the image (modifies the frame in-place)
|
| 56 |
|
| 57 |
# Save the image with bounding boxes
|
| 58 |
frame_filename = os.path.join(output_folder, f"frame_{frame_count}.jpg")
|
|
|
|
| 60 |
saved_images.append(frame_filename)
|
| 61 |
|
| 62 |
# Extract labels (class indices) and map them to class names
|
| 63 |
+
detected_objects = [model.names[int(box.cls)] for box in results[0].boxes] # Access the first result
|
| 64 |
|
| 65 |
# Get current timestamp in the video
|
| 66 |
timestamp = cap.get(cv2.CAP_PROP_POS_MSEC) / 1000 # Convert ms to seconds
|
|
|
|
| 99 |
return display_items
|
| 100 |
|
| 101 |
with gr.Blocks() as iface:
|
| 102 |
+
video_input = gr.Video(label="Upload Video", height=300)
|
| 103 |
output_gallery = gr.Gallery(label="Generated Daily Journal with Images")
|
| 104 |
run_button = gr.Button("Generate Journal")
|
| 105 |
|