huytofu92 commited on
Commit
8d48756
·
1 Parent(s): ce867e1

Fix file path issue

Browse files
Files changed (1) hide show
  1. utils.py +12 -2
utils.py CHANGED
@@ -19,7 +19,11 @@ def find_file_by_task_id(task_id: str, metadata_path: str = "Final_Assignment_Te
19
  "32102e3e-d12a-4209-9163-7b3a104efe5d.xlsx"
20
  """
21
  if not os.path.exists(metadata_path):
22
- raise FileNotFoundError(f"Metadata file not found at {metadata_path}")
 
 
 
 
23
 
24
  with open(metadata_path, 'r', encoding='utf-8') as f:
25
  for line in f:
@@ -68,4 +72,10 @@ def load_file_from_task_id(task_id: str) -> str:
68
  if not file_path:
69
  return "File not found"
70
  with open(file_path, 'r') as file:
71
- return file.read()
 
 
 
 
 
 
 
19
  "32102e3e-d12a-4209-9163-7b3a104efe5d.xlsx"
20
  """
21
  if not os.path.exists(metadata_path):
22
+ try:
23
+ current_dir = os.path.dirname(os.path.abspath(__file__))
24
+ metadata_path = os.path.join(current_dir, "validation", "metadata.jsonl")
25
+ except Exception as e:
26
+ raise FileNotFoundError(f"Metadata file not found at {metadata_path}")
27
 
28
  with open(metadata_path, 'r', encoding='utf-8') as f:
29
  for line in f:
 
72
  if not file_path:
73
  return "File not found"
74
  with open(file_path, 'r') as file:
75
+ try:
76
+ return file.read()
77
+ except Exception as e:
78
+ current_dir = os.path.dirname(os.path.abspath(__file__))
79
+ file_path = os.path.join(current_dir, file_path.replace("Final_Assignment_Template", ""))
80
+ with open(file_path, 'r') as file:
81
+ return file.read()