Spaces:
Sleeping
Sleeping
Update load_files.py
Browse files- load_files.py +36 -5
load_files.py
CHANGED
|
@@ -93,6 +93,28 @@ class ImageGalleryApp:
|
|
| 93 |
print(f"Error in parallel loading: {e}")
|
| 94 |
return images
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
def search_images(self,
|
| 97 |
category: str = "All",
|
| 98 |
file_name: str = "All",
|
|
@@ -101,6 +123,10 @@ class ImageGalleryApp:
|
|
| 101 |
lob: str = "test") -> Tuple[List[Image.Image], str]:
|
| 102 |
"""Search images based on filters with optimizations"""
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
# Build query with default status filter
|
| 105 |
query = {
|
| 106 |
"lob": lob,
|
|
@@ -117,18 +143,18 @@ class ImageGalleryApp:
|
|
| 117 |
# Handle date filtering with proper date objects
|
| 118 |
if start_date or end_date:
|
| 119 |
date_query = {}
|
| 120 |
-
if
|
| 121 |
try:
|
| 122 |
# Convert date to datetime at start of day
|
| 123 |
-
start_dt = datetime.combine(
|
| 124 |
date_query["$gte"] = start_dt
|
| 125 |
except Exception as e:
|
| 126 |
print(f"Error parsing start date: {e}")
|
| 127 |
|
| 128 |
-
if
|
| 129 |
try:
|
| 130 |
# Convert date to datetime at end of day
|
| 131 |
-
end_dt = datetime.combine(
|
| 132 |
date_query["$lte"] = end_dt
|
| 133 |
except Exception as e:
|
| 134 |
print(f"Error parsing end date: {e}")
|
|
@@ -172,7 +198,12 @@ class ImageGalleryApp:
|
|
| 172 |
|
| 173 |
# Build info text
|
| 174 |
info_text = f"Found {len(documents)} records (showing {len(images)} images)\n"
|
| 175 |
-
info_text += f"Filter: Status = completed, LOB = {lob}\n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
for i, doc in enumerate(documents[:len(images)]):
|
| 178 |
info_text += f"#{i + 1}\n"
|
|
|
|
| 93 |
print(f"Error in parallel loading: {e}")
|
| 94 |
return images
|
| 95 |
|
| 96 |
+
def parse_date_input(self, date_input) -> Optional[date]:
|
| 97 |
+
"""Convert string date input to date object"""
|
| 98 |
+
if not date_input or date_input == "":
|
| 99 |
+
return None
|
| 100 |
+
|
| 101 |
+
if isinstance(date_input, date):
|
| 102 |
+
return date_input
|
| 103 |
+
|
| 104 |
+
if isinstance(date_input, str):
|
| 105 |
+
try:
|
| 106 |
+
# Handle YYYY-MM-DD format (most common from Calendar component)
|
| 107 |
+
if date_input.count('-') == 2:
|
| 108 |
+
return datetime.strptime(date_input, '%Y-%m-%d').date()
|
| 109 |
+
# Handle MM/DD/YYYY format
|
| 110 |
+
elif date_input.count('/') == 2:
|
| 111 |
+
return datetime.strptime(date_input, '%m/%d/%Y').date()
|
| 112 |
+
except ValueError as e:
|
| 113 |
+
print(f"Error parsing date string '{date_input}': {e}")
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
return None
|
| 117 |
+
|
| 118 |
def search_images(self,
|
| 119 |
category: str = "All",
|
| 120 |
file_name: str = "All",
|
|
|
|
| 123 |
lob: str = "test") -> Tuple[List[Image.Image], str]:
|
| 124 |
"""Search images based on filters with optimizations"""
|
| 125 |
|
| 126 |
+
# Convert string inputs to date objects
|
| 127 |
+
start_date_obj = self.parse_date_input(start_date)
|
| 128 |
+
end_date_obj = self.parse_date_input(end_date)
|
| 129 |
+
|
| 130 |
# Build query with default status filter
|
| 131 |
query = {
|
| 132 |
"lob": lob,
|
|
|
|
| 143 |
# Handle date filtering with proper date objects
|
| 144 |
if start_date or end_date:
|
| 145 |
date_query = {}
|
| 146 |
+
if start_date_obj:
|
| 147 |
try:
|
| 148 |
# Convert date to datetime at start of day
|
| 149 |
+
start_dt = datetime.combine(start_date_obj, datetime.min.time())
|
| 150 |
date_query["$gte"] = start_dt
|
| 151 |
except Exception as e:
|
| 152 |
print(f"Error parsing start date: {e}")
|
| 153 |
|
| 154 |
+
if end_date_obj:
|
| 155 |
try:
|
| 156 |
# Convert date to datetime at end of day
|
| 157 |
+
end_dt = datetime.combine(end_date_obj, datetime.max.time())
|
| 158 |
date_query["$lte"] = end_dt
|
| 159 |
except Exception as e:
|
| 160 |
print(f"Error parsing end date: {e}")
|
|
|
|
| 198 |
|
| 199 |
# Build info text
|
| 200 |
info_text = f"Found {len(documents)} records (showing {len(images)} images)\n"
|
| 201 |
+
info_text += f"Filter: Status = completed, LOB = {lob}\n"
|
| 202 |
+
if start_date_obj:
|
| 203 |
+
info_text += f"Start Date: {start_date_obj}\n"
|
| 204 |
+
if end_date_obj:
|
| 205 |
+
info_text += f"End Date: {end_date_obj}\n"
|
| 206 |
+
info_text += "\n"
|
| 207 |
|
| 208 |
for i, doc in enumerate(documents[:len(images)]):
|
| 209 |
info_text += f"#{i + 1}\n"
|