MCPcopy Create free account
hub / github.com/TIGER-AI-Lab/TheoremExplainAgent / process_theorem

Function process_theorem

evaluate.py:245–346  ·  view source on GitHub ↗

Process a theorem file or directory for evaluation. Args: models: Dictionary of models for different evaluation types. file_path (str): Path to the file or directory to evaluate. eval_type (str): Type of evaluation to perform. retry_limit (int): Number of re

(models, file_path: str, eval_type: str, retry_limit: int,
                    target_fps: int = None, use_parent_folder_as_topic: bool = False,
                    output_folder: str = None)

Source from the content-addressed store, hash-verified

243
244
245def process_theorem(models, file_path: str, eval_type: str, retry_limit: int,
246 target_fps: int = None, use_parent_folder_as_topic: bool = False,
247 output_folder: str = None) -> tuple[str, dict]:
248 """
249 Process a theorem file or directory for evaluation.
250
251 Args:
252 models: Dictionary of models for different evaluation types.
253 file_path (str): Path to the file or directory to evaluate.
254 eval_type (str): Type of evaluation to perform.
255 retry_limit (int): Number of retry attempts.
256 target_fps (int, optional): Target frames per second for video processing.
257 use_parent_folder_as_topic (bool, optional): Use parent folder name as topic.
258 output_folder (str, optional): Directory to store output files.
259
260 Returns:
261 tuple[str, dict]: Tuple of file name and evaluation results.
262 """
263 ext_map = {
264 'text': ('.txt', '.srt'),
265 'video': ('.mp4', '.mkv')
266 }
267
268 # Handle single file evaluation
269 if os.path.isfile(file_path):
270 file_ext = os.path.splitext(file_path)[1].lower()
271 file_name = os.path.basename(file_path)
272
273 if eval_type == "text" and file_ext in ext_map['text']:
274 return file_name, evaluate_text_file(models['text'], file_path, retry_limit)
275 elif eval_type == "video" and file_ext in ext_map['video']:
276 if use_parent_folder_as_topic:
277 topic_name = os.path.basename(os.path.dirname(file_path))
278 else:
279 topic_name = None
280 topic_name = process_topic_name(topic_name)
281 return file_name, evaluate_video_file(models['video'], file_path, None, topic_name, target_fps, output_folder)
282 elif eval_type == "image" and file_ext in ext_map['video']:
283 if use_parent_folder_as_topic:
284 topic_name = os.path.basename(os.path.dirname(file_path))
285 else:
286 topic_name = None
287 topic_name = process_topic_name(topic_name)
288 return file_name, evaluate_sampled_images(models['image'], file_path, topic_name, num_chunks=10, output_folder=output_folder)
289 elif eval_type == "all":
290 raise ValueError("Evaluation type 'all' is not supported for a single file. Try passing a folder with both a video and a subtitle file.")
291 else:
292 raise ValueError(f"File type of {file_path} does not match evaluation type {eval_type!r}")
293
294 # Handle directory evaluation
295 theorem_dir = file_path
296 all_files = os.listdir(theorem_dir)
297
298 # Look for transcript files, prioritizing .srt over .txt if both exist
299 transcript_file_candidates = [f for f in all_files if f.endswith(ext_map['text']) and not f.endswith('_scene_outline.txt')]
300 srt_files = [f for f in transcript_file_candidates if f.endswith('.srt')]
301 txt_files = [f for f in transcript_file_candidates if f.endswith('.txt')]
302

Callers 1

mainFunction · 0.70

Calls 6

evaluate_sampled_imagesFunction · 0.90
evaluate_text_fileFunction · 0.85
process_topic_nameFunction · 0.85
evaluate_video_fileFunction · 0.85
merge_dictsFunction · 0.85
calculate_overall_scoreFunction · 0.85

Tested by

no test coverage detected