ManishThota commited on
Commit
2a2b9f5
·
verified ·
1 Parent(s): 2914f1a

Update multi_video_app.py

Browse files
Files changed (1) hide show
  1. multi_video_app.py +19 -21
multi_video_app.py CHANGED
@@ -20,14 +20,14 @@ def save_to_csv(observations: List[Dict], output_dir: str = "outputs") -> str:
20
 
21
  with open(csv_file, mode='w', newline='') as file:
22
  writer = csv.writer(file)
23
- writer.writerow(["video_name", "standing", "hands_free", "indoors", "screen_interaction_yes"])
24
  for observation in observations:
25
  writer.writerow([
26
  observation['video_name'],
27
  observation['standing'],
28
- observation['hands_free'],
29
  observation['indoors'],
30
- observation['screen_interaction_yes']
31
  ])
32
 
33
  return csv_file
@@ -57,24 +57,22 @@ def process_single_video(video_path: str, sitting, hands, location, screen) -> D
57
  final_prompt = final_query + " " + end_query
58
 
59
  # Assuming your describe_video function handles the video processing
60
- response = describe_video(video_path, final_prompt)
61
-
62
- try:
63
- # Parse the annotations from the response
64
- tags = ["annotation"]
65
- parsed_data = parse_string(response, tags)
66
- annotations_list = parsed_data.get("annotation", [])
67
- annotations_dict = parse_annotations(annotations_list)
68
-
69
- return {
70
- "video_name": video_name,
71
- "standing": annotations_dict.get("standing", 'N/A'),
72
- "hands_free": annotations_dict.get("hands.free", 'N/A'),
73
- "indoors": annotations_dict.get("indoors", 'N/A'),
74
- "screen_interaction_yes": annotations_dict.get("screen.interaction_yes", 'N/A'),
75
- }
76
- except Exception as e:
77
- return {"error": f"An error occurred with {video_name}: {e}"}
78
 
79
  # Function to process all videos in a folder
80
  def process_multiple_videos(video_files: List[str], sitting, hands, location, screen):
 
20
 
21
  with open(csv_file, mode='w', newline='') as file:
22
  writer = csv.writer(file)
23
+ writer.writerow(["video_name", "standing", "hands.free", "indoors", "screen.interaction_yes"])
24
  for observation in observations:
25
  writer.writerow([
26
  observation['video_name'],
27
  observation['standing'],
28
+ observation['hands.free'],
29
  observation['indoors'],
30
+ observation['screen.interaction_yes']
31
  ])
32
 
33
  return csv_file
 
57
  final_prompt = final_query + " " + end_query
58
 
59
  # Assuming your describe_video function handles the video processing
60
+ final_response = describe_video(video_path, final_prompt)
61
+
62
+ conditions = {
63
+ 'standing': (standing, 'standing: 1', 'standing: None'),
64
+ 'hands': (hands, 'hands.free: 1', 'hands.free: None'),
65
+ 'location': (location, 'indoors: 1', 'indoors: None'),
66
+ 'screen': (screen, 'screen.interaction_yes: 1', 'screen.interaction_yes: None')
67
+ }
68
+
69
+ for key, (condition, to_replace, replacement) in conditions.items():
70
+ if not condition:
71
+ final_response = final_response.replace(to_replace, replacement)
72
+
73
+ return final_response
74
+
75
+
 
 
76
 
77
  # Function to process all videos in a folder
78
  def process_multiple_videos(video_files: List[str], sitting, hands, location, screen):