|
1 | 1 | import ast |
2 | | -import copy |
3 | 2 | import inspect |
4 | | -import re |
5 | 3 | import sys |
6 | 4 | import time |
7 | 5 | import traceback |
8 | 6 | from itertools import groupby |
9 | 7 | from operator import itemgetter |
10 | | -from pydoc import doc |
11 | 8 | from typing import Any, Dict, Sequence |
12 | | - |
13 | 9 | import cv2 |
14 | | -import matplotlib.pyplot as plt |
15 | 10 | import numpy as np |
16 | | -from numpy import ndarray |
17 | 11 | from scipy.ndimage.filters import uniform_filter1d |
18 | | - |
19 | 12 | from amadeusgpt.logger import AmadeusLogger |
20 | 13 |
|
21 | 14 |
|
@@ -63,23 +56,6 @@ def moving_average(x: Sequence, window_size: int, pos: str = "centered"): |
63 | 56 | return uniform_filter1d(x, window_size, mode="constant", origin=origin) |
64 | 57 |
|
65 | 58 |
|
66 | | -def moving_variance(x, window_size): |
67 | | - """ |
68 | | - Blazing fast implementation of a moving variance. |
69 | | - :param x: ndarray, 1D input |
70 | | - :param window_size: int, window length |
71 | | - :return: 1D ndarray of length len(x)-window+1 |
72 | | - """ |
73 | | - nrows = x.size - window_size + 1 |
74 | | - n = x.strides[0] |
75 | | - mat = np.lib.stride_tricks.as_strided( |
76 | | - x, |
77 | | - shape=(nrows, window_size), |
78 | | - strides=(n, n), |
79 | | - ) |
80 | | - return np.var(mat, axis=1) |
81 | | - |
82 | | - |
83 | 59 | def smooth_boolean_mask(x: Sequence, window_size: int): |
84 | 60 | # `window_size` should be at least twice as large as the |
85 | 61 | # minimal number of consecutive frames to be smoothed out. |
@@ -109,136 +85,6 @@ def get_video_length(video_path): |
109 | 85 | return int(n_frames) |
110 | 86 |
|
111 | 87 |
|
112 | | -def frame_number_to_minute_seconds(frame_number, video_path): |
113 | | - fps = get_fps(video_path) |
114 | | - temp = frame_number / fps |
115 | | - minutes = int(temp // 60) |
116 | | - seconds = int(temp % 60) |
117 | | - ret = f"{minutes:02d}:{seconds:02d}" |
118 | | - return ret |
119 | | - |
120 | | - |
121 | | -def search_generated_func(text): |
122 | | - functions = [] |
123 | | - lines = text.split("\n") |
124 | | - func_names = [] |
125 | | - i = 0 |
126 | | - |
127 | | - while i < len(lines): |
128 | | - line = lines[i] |
129 | | - func_signature = "def task_program" |
130 | | - if line.startswith(func_signature): |
131 | | - start = line.index("def ") + 4 |
132 | | - end = line.index("(") |
133 | | - func_name = line[start:end] |
134 | | - func_names.append(func_name) |
135 | | - function_lines = [line] |
136 | | - nesting_level = 0 |
137 | | - i += 1 |
138 | | - |
139 | | - while i < len(lines): |
140 | | - line = lines[i] |
141 | | - # Check for nested function definitions |
142 | | - if line.lstrip().startswith("def "): |
143 | | - nesting_level += 1 |
144 | | - elif line.lstrip().startswith("return") and nesting_level > 0: |
145 | | - nesting_level -= 1 |
146 | | - elif line.lstrip().startswith("return") and nesting_level == 0: |
147 | | - function_lines.append(line) |
148 | | - break |
149 | | - |
150 | | - function_lines.append(line) |
151 | | - i += 1 |
152 | | - |
153 | | - functions.append("\n".join(function_lines)) |
154 | | - i += 1 |
155 | | - |
156 | | - return functions, func_names |
157 | | - |
158 | | - |
159 | | -def search_external_module_for_context_window(text): |
160 | | - """ |
161 | | - just include everything |
162 | | - """ |
163 | | - functions = [] |
164 | | - i = 0 |
165 | | - lines = text.split("\n") |
166 | | - func_names = [] |
167 | | - while i < len(lines): |
168 | | - line = lines[i].strip() |
169 | | - func_signature = "def " |
170 | | - if line.strip() == "": |
171 | | - i += 1 |
172 | | - continue |
173 | | - if line.startswith(func_signature): |
174 | | - start = line.index("def ") + 4 |
175 | | - end = line.index("(") |
176 | | - func_name = line[start:end] |
177 | | - func_names.append(func_name) |
178 | | - function_lines = [line] |
179 | | - in_function = True |
180 | | - while in_function: |
181 | | - i += 1 |
182 | | - if i == len(lines): |
183 | | - break |
184 | | - next_line = lines[i].rstrip() |
185 | | - if not next_line.startswith((" ", "\t")): |
186 | | - in_function = False |
187 | | - continue |
188 | | - function_lines.append(next_line) |
189 | | - functions.append("\n".join(function_lines)) |
190 | | - else: |
191 | | - i += 1 |
192 | | - return functions, func_names |
193 | | - |
194 | | - |
195 | | -def search_external_module_for_task_program_table(text): |
196 | | - """ |
197 | | - in this case, just include everything |
198 | | - """ |
199 | | - functions = [] |
200 | | - i = 0 |
201 | | - lines = text.split("\n") |
202 | | - lines_copy = copy.deepcopy(lines) |
203 | | - func_names = [] |
204 | | - example_indentation = " " * 4 |
205 | | - while i < len(lines): |
206 | | - if lines[i].startswith("def "): |
207 | | - start = lines[i].index("def ") + 4 |
208 | | - end = lines[i].index("(") |
209 | | - func_name = lines[i][start:end] |
210 | | - func_names.append(func_name) |
211 | | - if "" not in lines[i]: |
212 | | - i += 1 |
213 | | - continue |
214 | | - else: |
215 | | - lines[i] = lines[i].replace("", "").strip() |
216 | | - line = lines[i].strip() |
217 | | - func_signature = "def " |
218 | | - if line.strip() == "": |
219 | | - i += 1 |
220 | | - continue |
221 | | - if line.startswith("def "): |
222 | | - function_lines = [line] |
223 | | - in_function = True |
224 | | - while in_function: |
225 | | - i += 1 |
226 | | - if i == len(lines): |
227 | | - break |
228 | | - next_line = lines[i].rstrip() |
229 | | - if "" not in lines_copy[i]: |
230 | | - in_function = False |
231 | | - continue |
232 | | - function_lines.append( |
233 | | - next_line.replace("", "").replace(example_indentation, "", 1) |
234 | | - ) |
235 | | - functions.append("\n".join(function_lines)) |
236 | | - else: |
237 | | - i += 1 |
238 | | - |
239 | | - return functions, func_names |
240 | | - |
241 | | - |
242 | 88 | def filter_kwargs_for_function(func, kwargs): |
243 | 89 | sig = inspect.signature(func) |
244 | 90 | return {k: v for k, v in kwargs.items() if k in sig.parameters} |
@@ -385,20 +231,3 @@ def func2json(func): |
385 | 231 | } |
386 | 232 | return json_obj |
387 | 233 |
|
388 | | - |
389 | | -def get_func_name_from_func_string(function_string: str): |
390 | | - import ast |
391 | | - |
392 | | - # Parse the string into an AST |
393 | | - parsed_ast = ast.parse(function_string) |
394 | | - |
395 | | - # Initialize a variable to hold the function name |
396 | | - function_name = None |
397 | | - |
398 | | - # Traverse the AST |
399 | | - for node in ast.walk(parsed_ast): |
400 | | - if isinstance(node, ast.FunctionDef): |
401 | | - function_name = node.name |
402 | | - break |
403 | | - |
404 | | - return function_name |
0 commit comments