Spaces:
Sleeping
Sleeping
fix path issue
Browse files- audio_tools.py +1 -1
- utils.py +5 -9
- vlm_tools.py +2 -2
audio_tools.py
CHANGED
@@ -41,7 +41,7 @@ def audio_to_base64(file_path: str) -> str:
|
|
41 |
except Exception as e:
|
42 |
current_file_path = os.path.abspath(__file__)
|
43 |
current_file_dir = os.path.dirname(current_file_path)
|
44 |
-
file_path = os.path.join(current_file_dir, file_path
|
45 |
audio = AudioSegment.from_file(file_path)
|
46 |
|
47 |
# Export the audio to a BytesIO object
|
|
|
41 |
except Exception as e:
|
42 |
current_file_path = os.path.abspath(__file__)
|
43 |
current_file_dir = os.path.dirname(current_file_path)
|
44 |
+
file_path = os.path.join(current_file_dir, file_path)
|
45 |
audio = AudioSegment.from_file(file_path)
|
46 |
|
47 |
# Export the audio to a BytesIO object
|
utils.py
CHANGED
@@ -2,7 +2,7 @@ import json
|
|
2 |
import os
|
3 |
from typing import Optional
|
4 |
|
5 |
-
def find_file_by_task_id(task_id: str, metadata_path: str = "
|
6 |
"""
|
7 |
Search for a filename that matches a given task_id in the metadata.jsonl file.
|
8 |
|
@@ -20,20 +20,16 @@ def find_file_by_task_id(task_id: str, metadata_path: str = "Final_Assignment_Te
|
|
20 |
if not os.path.exists(metadata_path):
|
21 |
try:
|
22 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
23 |
-
print("CURRENT DIR: ", current_dir)
|
24 |
-
print("ABSOLUTE PATH: ", os.path.abspath(__file__))
|
25 |
metadata_path = os.path.join(current_dir, "validation", "metadata.jsonl")
|
26 |
except Exception as e:
|
27 |
raise FileNotFoundError(f"Metadata file not found at {metadata_path}")
|
28 |
|
29 |
-
print("METADATA PATH: ", metadata_path)
|
30 |
with open(metadata_path, 'r', encoding='utf-8') as f:
|
31 |
for line in f:
|
32 |
-
print("LINE: ", line)
|
33 |
try:
|
34 |
data = json.loads(line.strip())
|
35 |
-
print("DATA: ", data)
|
36 |
-
print("TASK ID: ", task_id)
|
37 |
print("DATA GET TASK ID: ", data.get('task_id'))
|
38 |
print("DATA GET FILE NAME: ", data.get('file_name'))
|
39 |
if data.get('task_id') == task_id:
|
@@ -44,7 +40,7 @@ def find_file_by_task_id(task_id: str, metadata_path: str = "Final_Assignment_Te
|
|
44 |
|
45 |
return None
|
46 |
|
47 |
-
def get_full_file_path(task_id: str, base_dir: str = "
|
48 |
"""
|
49 |
Get the full file path for a given task_id if it exists.
|
50 |
|
@@ -57,7 +53,7 @@ def get_full_file_path(task_id: str, base_dir: str = "Final_Assignment_Template/
|
|
57 |
|
58 |
Example:
|
59 |
>>> get_full_file_path("32102e3e-d12a-4209-9163-7b3a104efe5d")
|
60 |
-
"
|
61 |
"""
|
62 |
filename = find_file_by_task_id(task_id)
|
63 |
if not filename:
|
|
|
2 |
import os
|
3 |
from typing import Optional
|
4 |
|
5 |
+
def find_file_by_task_id(task_id: str, metadata_path: str = "validation/metadata.jsonl") -> Optional[str]:
|
6 |
"""
|
7 |
Search for a filename that matches a given task_id in the metadata.jsonl file.
|
8 |
|
|
|
20 |
if not os.path.exists(metadata_path):
|
21 |
try:
|
22 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
23 |
metadata_path = os.path.join(current_dir, "validation", "metadata.jsonl")
|
24 |
except Exception as e:
|
25 |
raise FileNotFoundError(f"Metadata file not found at {metadata_path}")
|
26 |
|
|
|
27 |
with open(metadata_path, 'r', encoding='utf-8') as f:
|
28 |
for line in f:
|
|
|
29 |
try:
|
30 |
data = json.loads(line.strip())
|
31 |
+
#print("DATA: ", data)
|
32 |
+
#print("TASK ID: ", task_id)
|
33 |
print("DATA GET TASK ID: ", data.get('task_id'))
|
34 |
print("DATA GET FILE NAME: ", data.get('file_name'))
|
35 |
if data.get('task_id') == task_id:
|
|
|
40 |
|
41 |
return None
|
42 |
|
43 |
+
def get_full_file_path(task_id: str, base_dir: str = "validation") -> Optional[str]:
|
44 |
"""
|
45 |
Get the full file path for a given task_id if it exists.
|
46 |
|
|
|
53 |
|
54 |
Example:
|
55 |
>>> get_full_file_path("32102e3e-d12a-4209-9163-7b3a104efe5d")
|
56 |
+
"validation/32102e3e-d12a-4209-9163-7b3a104efe5d.xlsx"
|
57 |
"""
|
58 |
filename = find_file_by_task_id(task_id)
|
59 |
if not filename:
|
vlm_tools.py
CHANGED
@@ -114,7 +114,7 @@ def get_image_from_file_path(file_path: str)->str:
|
|
114 |
except Exception as e:
|
115 |
current_file_path = os.path.abspath(__file__)
|
116 |
current_file_dir = os.path.dirname(current_file_path)
|
117 |
-
file_path = os.path.join(current_file_dir, file_path
|
118 |
# Try again with the new path
|
119 |
with BytesIO() as buffer:
|
120 |
img = cv2.imread(file_path)
|
@@ -171,7 +171,7 @@ def get_video_from_file_path(file_path: str)->str:
|
|
171 |
except Exception as e:
|
172 |
current_file_path = os.path.abspath(__file__)
|
173 |
current_file_dir = os.path.dirname(current_file_path)
|
174 |
-
file_path = os.path.join(current_file_dir, file_path
|
175 |
|
176 |
# Try again with the new path
|
177 |
cap = cv2.VideoCapture(file_path)
|
|
|
114 |
except Exception as e:
|
115 |
current_file_path = os.path.abspath(__file__)
|
116 |
current_file_dir = os.path.dirname(current_file_path)
|
117 |
+
file_path = os.path.join(current_file_dir, file_path)
|
118 |
# Try again with the new path
|
119 |
with BytesIO() as buffer:
|
120 |
img = cv2.imread(file_path)
|
|
|
171 |
except Exception as e:
|
172 |
current_file_path = os.path.abspath(__file__)
|
173 |
current_file_dir = os.path.dirname(current_file_path)
|
174 |
+
file_path = os.path.join(current_file_dir, file_path)
|
175 |
|
176 |
# Try again with the new path
|
177 |
cap = cv2.VideoCapture(file_path)
|