yasserrmd commited on
Commit
47f97bd
1 Parent(s): 109fee8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -44,7 +44,7 @@ def is_frame_different(frame1, frame2, threshold=0.9):
44
  @spaces.GPU
45
  def generate_journal_with_images(video_path, frame_interval=30):
46
  cap = cv2.VideoCapture(video_path)
47
- journal_entries = {}
48
  saved_images = []
49
  frame_count = 0
50
  last_processed_frame = None
@@ -82,9 +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
- if activity not in journal_entries:
86
- journal_entries[activity] = []
87
- journal_entries[activity].append((f"At {timestamp:.2f} seconds: {', '.join(objects[0])}", frame_filename))
88
 
89
  last_processed_frame = frame # Update the last processed frame
90
 
@@ -92,26 +90,20 @@ def generate_journal_with_images(video_path, frame_interval=30):
92
 
93
  cap.release()
94
 
95
- # Create a formatted journal output
96
- formatted_journal = []
97
- for activity, entries in journal_entries.items():
98
- formatted_journal.append(f"**{activity}:**")
99
- for entry, image_path in entries:
100
- formatted_journal.append((entry, image_path))
101
-
102
- return formatted_journal
103
 
104
  # Gradio interface for uploading video and generating journal with images
105
  def display_journal_with_images(video):
106
- journal_with_images = generate_journal_with_images(video)
107
 
108
  # Create the final display with text and images
109
  display_items = []
110
  for entry, image_path in journal_with_images:
111
- display_items.append((entry, image_path))
112
 
113
  return display_items
114
 
 
115
  with gr.Blocks() as iface:
116
  video_input = gr.Video(label="Upload Video", height=300)
117
  output_gallery = gr.Gallery(label="Generated Daily Journal with Images")
 
44
  @spaces.GPU
45
  def generate_journal_with_images(video_path, frame_interval=30):
46
  cap = cv2.VideoCapture(video_path)
47
+ journal_entries = []
48
  saved_images = []
49
  frame_count = 0
50
  last_processed_frame = None
 
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])}", frame_filename))
 
 
86
 
87
  last_processed_frame = frame # Update the last processed frame
88
 
 
90
 
91
  cap.release()
92
 
93
+ return journal_entries
 
 
 
 
 
 
 
94
 
95
  # Gradio interface for uploading video and generating journal with images
96
  def display_journal_with_images(video):
97
+ journal_with_images = generate_journal_with_images(video, frame_interval=30)
98
 
99
  # Create the final display with text and images
100
  display_items = []
101
  for entry, image_path in journal_with_images:
102
+ display_items.append((entry, image_path)) # Add both the journal entry and the image path
103
 
104
  return display_items
105
 
106
+
107
  with gr.Blocks() as iface:
108
  video_input = gr.Video(label="Upload Video", height=300)
109
  output_gallery = gr.Gallery(label="Generated Daily Journal with Images")