Spaces:
Sleeping
Sleeping
Update backend with high-quality catalog and fixes
Browse files- app/api/seed.py +17 -4
app/api/seed.py
CHANGED
|
@@ -165,28 +165,39 @@ async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
|
| 165 |
all_sub_cats[s["en"]] = sub_cat # Map both names to the same object
|
| 166 |
|
| 167 |
|
|
|
|
|
|
|
| 168 |
# Prioritize the full catalog over the smaller sample
|
| 169 |
possible_paths = [
|
| 170 |
# 1. Packaged location (relative to this file)
|
| 171 |
os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "data", "extra_products_vortex.json")),
|
| 172 |
-
# 2. Docker /app location
|
| 173 |
"/app/app/data/extra_products_vortex.json",
|
|
|
|
| 174 |
# 3. Project root (typical for local dev)
|
| 175 |
os.path.abspath("kaggle/extra_products_vortex.json"),
|
|
|
|
| 176 |
# 4. Fallback to the 200 products sample
|
| 177 |
os.path.abspath("real_products_200.json"),
|
| 178 |
]
|
| 179 |
|
| 180 |
json_path = None
|
|
|
|
| 181 |
for p in possible_paths:
|
| 182 |
-
|
|
|
|
|
|
|
| 183 |
json_path = p
|
| 184 |
break
|
| 185 |
|
| 186 |
if not json_path:
|
| 187 |
return AuthResponse(
|
| 188 |
isSuccess=False,
|
| 189 |
-
value={
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
statusCode=404,
|
| 191 |
error="File not found"
|
| 192 |
)
|
|
@@ -343,7 +354,9 @@ async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
|
| 343 |
"total_products": len(products_data),
|
| 344 |
"inserted_new": inserted_count,
|
| 345 |
"skipped": skipped_count,
|
| 346 |
-
"source_file": os.path.basename(json_path)
|
|
|
|
|
|
|
| 347 |
},
|
| 348 |
statusCode=201,
|
| 349 |
)
|
|
|
|
| 165 |
all_sub_cats[s["en"]] = sub_cat # Map both names to the same object
|
| 166 |
|
| 167 |
|
| 168 |
+
API_VERSION = "2026.03.16.V2"
|
| 169 |
+
|
| 170 |
# Prioritize the full catalog over the smaller sample
|
| 171 |
possible_paths = [
|
| 172 |
# 1. Packaged location (relative to this file)
|
| 173 |
os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "data", "extra_products_vortex.json")),
|
| 174 |
+
# 2. Docker /app location (standard Hugging Face structure)
|
| 175 |
"/app/app/data/extra_products_vortex.json",
|
| 176 |
+
"/app/data/extra_products_vortex.json",
|
| 177 |
# 3. Project root (typical for local dev)
|
| 178 |
os.path.abspath("kaggle/extra_products_vortex.json"),
|
| 179 |
+
os.path.abspath("app/data/extra_products_vortex.json"),
|
| 180 |
# 4. Fallback to the 200 products sample
|
| 181 |
os.path.abspath("real_products_200.json"),
|
| 182 |
]
|
| 183 |
|
| 184 |
json_path = None
|
| 185 |
+
checked_info = []
|
| 186 |
for p in possible_paths:
|
| 187 |
+
exists = os.path.exists(p)
|
| 188 |
+
checked_info.append(f"{p}: {'FOUND' if exists else 'NOT FOUND'}")
|
| 189 |
+
if exists:
|
| 190 |
json_path = p
|
| 191 |
break
|
| 192 |
|
| 193 |
if not json_path:
|
| 194 |
return AuthResponse(
|
| 195 |
isSuccess=False,
|
| 196 |
+
value={
|
| 197 |
+
"message": "Source file not found.",
|
| 198 |
+
"checked": checked_info,
|
| 199 |
+
"version": API_VERSION
|
| 200 |
+
},
|
| 201 |
statusCode=404,
|
| 202 |
error="File not found"
|
| 203 |
)
|
|
|
|
| 354 |
"total_products": len(products_data),
|
| 355 |
"inserted_new": inserted_count,
|
| 356 |
"skipped": skipped_count,
|
| 357 |
+
"source_file": os.path.basename(json_path),
|
| 358 |
+
"path": json_path,
|
| 359 |
+
"version": API_VERSION
|
| 360 |
},
|
| 361 |
statusCode=201,
|
| 362 |
)
|