Update app.py
Browse files
app.py
CHANGED
|
@@ -45,7 +45,7 @@ def is_frame_different(frame1, frame2, threshold=0.9):
|
|
| 45 |
def generate_journal_with_images(video_path, frame_interval=30):
|
| 46 |
cap = cv2.VideoCapture(video_path)
|
| 47 |
journal_entries = []
|
| 48 |
-
|
| 49 |
frame_count = 0
|
| 50 |
last_processed_frame = None
|
| 51 |
output_folder = "detected_frames"
|
|
@@ -69,7 +69,7 @@ def generate_journal_with_images(video_path, frame_interval=30):
|
|
| 69 |
# Save the annotated image
|
| 70 |
frame_filename = os.path.join(output_folder, f"frame_{frame_count}.jpg")
|
| 71 |
cv2.imwrite(frame_filename, annotated_frame[:, :, ::-1]) # Convert back to BGR for saving
|
| 72 |
-
|
| 73 |
|
| 74 |
# Extract labels (class indices) and map them to class names
|
| 75 |
detected_objects = [model.names[int(box.cls)] for box in results[0].boxes] # Access the first result
|
|
@@ -82,7 +82,7 @@ def generate_journal_with_images(video_path, frame_interval=30):
|
|
| 82 |
|
| 83 |
# Store the activities with their timestamp
|
| 84 |
for activity, objects in activity_summary.items():
|
| 85 |
-
journal_entries.append(
|
| 86 |
|
| 87 |
last_processed_frame = frame # Update the last processed frame
|
| 88 |
|
|
@@ -90,17 +90,21 @@ def generate_journal_with_images(video_path, frame_interval=30):
|
|
| 90 |
|
| 91 |
cap.release()
|
| 92 |
|
| 93 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
def display_journal_with_images(video):
|
| 97 |
journal_entries, image_paths = generate_journal_with_images(video, frame_interval=30)
|
| 98 |
|
| 99 |
-
|
| 100 |
journal_text = "\n".join(journal_entries)
|
| 101 |
return journal_text, image_paths
|
| 102 |
|
| 103 |
-
|
| 104 |
with gr.Blocks() as iface:
|
| 105 |
video_input = gr.Video(label="Upload Video", height=300)
|
| 106 |
journal_output = gr.Textbox(label="Generated Daily Journal", lines=10)
|
|
|
|
| 45 |
def generate_journal_with_images(video_path, frame_interval=30):
|
| 46 |
cap = cv2.VideoCapture(video_path)
|
| 47 |
journal_entries = []
|
| 48 |
+
image_paths = []
|
| 49 |
frame_count = 0
|
| 50 |
last_processed_frame = None
|
| 51 |
output_folder = "detected_frames"
|
|
|
|
| 69 |
# Save the annotated image
|
| 70 |
frame_filename = os.path.join(output_folder, f"frame_{frame_count}.jpg")
|
| 71 |
cv2.imwrite(frame_filename, annotated_frame[:, :, ::-1]) # Convert back to BGR for saving
|
| 72 |
+
image_paths.append(frame_filename)
|
| 73 |
|
| 74 |
# Extract labels (class indices) and map them to class names
|
| 75 |
detected_objects = [model.names[int(box.cls)] for box in results[0].boxes] # Access the first result
|
|
|
|
| 82 |
|
| 83 |
# Store the activities with their timestamp
|
| 84 |
for activity, objects in activity_summary.items():
|
| 85 |
+
journal_entries.append(f"At {timestamp:.2f} seconds: {', '.join(objects[0])}")
|
| 86 |
|
| 87 |
last_processed_frame = frame # Update the last processed frame
|
| 88 |
|
|
|
|
| 90 |
|
| 91 |
cap.release()
|
| 92 |
|
| 93 |
+
# Debug print to verify the return values
|
| 94 |
+
print(f"journal_entries: {journal_entries}")
|
| 95 |
+
print(f"image_paths: {image_paths}")
|
| 96 |
+
|
| 97 |
+
return journal_entries, image_paths
|
| 98 |
|
| 99 |
|
| 100 |
def display_journal_with_images(video):
|
| 101 |
journal_entries, image_paths = generate_journal_with_images(video, frame_interval=30)
|
| 102 |
|
| 103 |
+
|
| 104 |
journal_text = "\n".join(journal_entries)
|
| 105 |
return journal_text, image_paths
|
| 106 |
|
| 107 |
+
|
| 108 |
with gr.Blocks() as iface:
|
| 109 |
video_input = gr.Video(label="Upload Video", height=300)
|
| 110 |
journal_output = gr.Textbox(label="Generated Daily Journal", lines=10)
|