ManishThota commited on
Commit
23a5823
·
verified ·
1 Parent(s): b68921c

Update src/utils.py

Browse files
Files changed (1) hide show
  1. src/utils.py +44 -1
src/utils.py CHANGED
@@ -1,10 +1,53 @@
1
  # Importing the requirements
2
  from PIL import Image
3
  from decord import VideoReader, cpu
 
4
 
5
 
6
  # Maximum number of frames to use
7
- MAX_NUM_FRAMES = 64 # If CUDA OOM, set a smaller number
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
 
10
  def encode_video(video_path):
 
1
  # Importing the requirements
2
  from PIL import Image
3
  from decord import VideoReader, cpu
4
+ import re
5
 
6
 
7
  # Maximum number of frames to use
8
+ MAX_NUM_FRAMES = 25 # If CUDA OOM, set a smaller number
9
+
10
+
11
+ def parse_string(string, tags):
12
+ """
13
+ Extracts the content between the specified HTML tags from the given string.
14
+
15
+ Args:
16
+ string (str): The input string to search for the tag content.
17
+ tags (list): A list of HTML tags to search for.
18
+
19
+ Returns:
20
+ dict: A dictionary with tags as keys and lists of content as values.
21
+
22
+ Example:
23
+ >>> parse_string("<code>Hello, World!</code><note>Important</note>", ["code", "note"])
24
+ {'code': ['Hello, World!'], 'note': ['Important']}
25
+ """
26
+ results = {}
27
+
28
+ for tag in tags:
29
+ pattern = rf"<{tag}>(.*?)</{tag}>"
30
+ matches = re.findall(pattern, string, re.DOTALL)
31
+ results[tag] = matches if matches else None
32
+
33
+ return results
34
+
35
+ def parse_annotations(annotations_list):
36
+ """
37
+ Converts a list of annotations into a dictionary of key-value pairs.
38
+
39
+ Args:
40
+ annotations_list (list): A list of annotations in the format 'key: value'.
41
+
42
+ Returns:
43
+ dict: A dictionary with annotation keys and values.
44
+ """
45
+ annotations_dict = {}
46
+ for annotation in annotations_list:
47
+ key, value = annotation.split(': ')
48
+ annotations_dict[key] = int(value)
49
+ return annotations_dict
50
+
51
 
52
 
53
  def encode_video(video_path):