Spaces:
Sleeping
Sleeping
Update backend with high-quality catalog and fixes
Browse files- app/api/seed.py +44 -38
app/api/seed.py
CHANGED
|
@@ -48,59 +48,59 @@ SUB_ICONS = {
|
|
| 48 |
"نظارات شمسية": "🕶️",
|
| 49 |
}
|
| 50 |
|
| 51 |
-
# Robust Category Hierarchy (Extra.com
|
| 52 |
CATEGORY_HIERARCHY = {
|
| 53 |
"الأجهزة الإلكترونية": {
|
| 54 |
"name_en": "Electronics & Mobiles",
|
| 55 |
"icon": "📱",
|
| 56 |
"subs": [
|
| 57 |
-
{"en": "Electronics", "ar": "الهواتف والإلكترونيات"},
|
| 58 |
{"en": "Smartphones", "ar": "جوالات"},
|
| 59 |
{"en": "Laptops", "ar": "أجهزة الكمبيوتر"},
|
|
|
|
|
|
|
| 60 |
]
|
| 61 |
},
|
| 62 |
"ملحقات واكسسوارات": {
|
| 63 |
-
"name_en": "Accessories &
|
| 64 |
-
"icon": "
|
| 65 |
"subs": [
|
| 66 |
-
{"en": "Accessories", "ar": "اكسسوارات
|
| 67 |
-
{"en": "
|
| 68 |
-
{"en": "
|
| 69 |
-
{"en": "
|
|
|
|
| 70 |
]
|
| 71 |
},
|
| 72 |
-
"
|
| 73 |
-
"name_en": "
|
| 74 |
-
"icon": "
|
| 75 |
"subs": [
|
| 76 |
-
{"en": "
|
| 77 |
-
{"en": "
|
|
|
|
| 78 |
]
|
| 79 |
},
|
| 80 |
-
"
|
| 81 |
-
"name_en": "
|
| 82 |
-
"icon": "
|
| 83 |
"subs": [
|
| 84 |
-
{"en": "
|
| 85 |
-
{"en": "
|
|
|
|
|
|
|
| 86 |
]
|
| 87 |
}
|
| 88 |
}
|
| 89 |
|
| 90 |
-
# Map scraped category strings (EN/AR) to target subcategories
|
| 91 |
-
# Format: { "scraped_name": "target_ar_name" }
|
| 92 |
SCRAPED_TO_TARGET_MAP = {
|
| 93 |
-
"Electronics": "
|
| 94 |
-
"Smartphones": "
|
| 95 |
"Laptops": "أجهزة الكمبيوتر",
|
| 96 |
-
"Home Appliances": "
|
| 97 |
-
"Accessories": "اكسسوارات
|
| 98 |
-
"Gaming": "ألعاب
|
| 99 |
-
"Security
|
| 100 |
-
"Car
|
| 101 |
-
"Perfumes": "العطور والتجميل",
|
| 102 |
-
"Fashion": "الساعات والإكسسوارات",
|
| 103 |
-
"Beauty": "العطور والتجميل",
|
| 104 |
}
|
| 105 |
|
| 106 |
@router.api_route("", methods=["GET", "POST"], response_model=AuthResponse)
|
|
@@ -165,13 +165,13 @@ 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 |
-
# Search for real_products_200.json
|
| 169 |
possible_paths = [
|
|
|
|
| 170 |
os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "backend", "real_products_200.json"),
|
| 171 |
-
os.path.
|
| 172 |
os.path.abspath("real_products_200.json"),
|
| 173 |
-
|
| 174 |
-
"/app/real_products_200.json",
|
| 175 |
]
|
| 176 |
|
| 177 |
json_path = None
|
|
@@ -230,10 +230,16 @@ async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
|
| 230 |
KEYWORD_MAP = {
|
| 231 |
"جوالات": ["iphone", "galaxy", "phone", "mobile", "pixel", "هاتف", "جوال"],
|
| 232 |
"أجهزة الكمبيوتر": ["laptop", "macbook", "notebook", "pc", "computer", "لابتوب", "حاسوب"],
|
| 233 |
-
"أ
|
| 234 |
-
"
|
| 235 |
-
"
|
| 236 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
}
|
| 238 |
|
| 239 |
for target, keywords in KEYWORD_MAP.items():
|
|
|
|
| 48 |
"نظارات شمسية": "🕶️",
|
| 49 |
}
|
| 50 |
|
| 51 |
+
# Robust Category Hierarchy (Optimized for Extra.com Dataset)
|
| 52 |
CATEGORY_HIERARCHY = {
|
| 53 |
"الأجهزة الإلكترونية": {
|
| 54 |
"name_en": "Electronics & Mobiles",
|
| 55 |
"icon": "📱",
|
| 56 |
"subs": [
|
|
|
|
| 57 |
{"en": "Smartphones", "ar": "جوالات"},
|
| 58 |
{"en": "Laptops", "ar": "أجهزة الكمبيوتر"},
|
| 59 |
+
{"en": "Tablets", "ar": "أجهزة لوحية"},
|
| 60 |
+
{"en": "Audio", "ar": "أجهزة الصوت"},
|
| 61 |
]
|
| 62 |
},
|
| 63 |
"ملحقات واكسسوارات": {
|
| 64 |
+
"name_en": "Accessories & Gadgets",
|
| 65 |
+
"icon": "🔌",
|
| 66 |
"subs": [
|
| 67 |
+
{"en": "Accessories", "ar": "اكسسوارات"},
|
| 68 |
+
{"en": "Cables & Power", "ar": "كابلات وشواحن"},
|
| 69 |
+
{"en": "Wearables", "ar": "أجهزة قابلة للارتداء"},
|
| 70 |
+
{"en": "Security", "ar": "كاميرات وأمان"},
|
| 71 |
+
{"en": "Car Accessories", "ar": "ملحقات سيارات"},
|
| 72 |
]
|
| 73 |
},
|
| 74 |
+
"ألعاب جيمنج": {
|
| 75 |
+
"name_en": "Gaming & Entertainment",
|
| 76 |
+
"icon": "🎮",
|
| 77 |
"subs": [
|
| 78 |
+
{"en": "Gaming Console", "ar": "أجهزة ألعاب"},
|
| 79 |
+
{"en": "Gaming Accessories", "ar": "ملحقات ألعاب"},
|
| 80 |
+
{"en": "Toys", "ar": "ألعاب أطفال"},
|
| 81 |
]
|
| 82 |
},
|
| 83 |
+
"الأجهزة المنزلية": {
|
| 84 |
+
"name_en": "Home & Kitchen Appliances",
|
| 85 |
+
"icon": "🏠",
|
| 86 |
"subs": [
|
| 87 |
+
{"en": "Large Appliances", "ar": "أجهزة منزلية كبيرة"},
|
| 88 |
+
{"en": "Small Appliances", "ar": "أجهزة منزلية صغيرة"},
|
| 89 |
+
{"en": "Kitchenware", "ar": "أدوات المطبخ"},
|
| 90 |
+
{"en": "Personal Care", "ar": "عناية شخصية"},
|
| 91 |
]
|
| 92 |
}
|
| 93 |
}
|
| 94 |
|
|
|
|
|
|
|
| 95 |
SCRAPED_TO_TARGET_MAP = {
|
| 96 |
+
"Electronics": "Smartphones",
|
| 97 |
+
"Smartphones": "Smartphones",
|
| 98 |
"Laptops": "أجهزة الكمبيوتر",
|
| 99 |
+
"Home Appliances": "أجهزة منزلية كبيرة",
|
| 100 |
+
"Accessories": "اكسسوارات",
|
| 101 |
+
"Gaming": "أجهزة ألعاب",
|
| 102 |
+
"Security": "كاميرات وأمان",
|
| 103 |
+
"Car": "ملحقات سيارات",
|
|
|
|
|
|
|
|
|
|
| 104 |
}
|
| 105 |
|
| 106 |
@router.api_route("", methods=["GET", "POST"], response_model=AuthResponse)
|
|
|
|
| 165 |
all_sub_cats[s["en"]] = sub_cat # Map both names to the same object
|
| 166 |
|
| 167 |
|
| 168 |
+
# Search for real_products_200.json or the full extra_products_vortex.json
|
| 169 |
possible_paths = [
|
| 170 |
+
os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "kaggle", "extra_products_vortex.json"),
|
| 171 |
os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "backend", "real_products_200.json"),
|
| 172 |
+
os.path.abspath("kaggle/extra_products_vortex.json"),
|
| 173 |
os.path.abspath("real_products_200.json"),
|
| 174 |
+
"/app/kaggle/extra_products_vortex.json",
|
|
|
|
| 175 |
]
|
| 176 |
|
| 177 |
json_path = None
|
|
|
|
| 230 |
KEYWORD_MAP = {
|
| 231 |
"جوالات": ["iphone", "galaxy", "phone", "mobile", "pixel", "هاتف", "جوال"],
|
| 232 |
"أجهزة الكمبيوتر": ["laptop", "macbook", "notebook", "pc", "computer", "لابتوب", "حاسوب"],
|
| 233 |
+
"أجهزة لوحية": ["ipad", "tablet", "tab", "لوحي"],
|
| 234 |
+
"أجهزة الصوت": ["headphone", "earbud", "speaker", "audio", "سماعة", "مكبر صوت"],
|
| 235 |
+
"أجهزة ألعاب": ["playstation", "xbox", "nintendo", "console", "بلايستيشن", "إكس بوكس"],
|
| 236 |
+
"ملحقات ألعاب": ["controller", "joystick", "gaming mouse", "gaming keyboard", "يد تحكم"],
|
| 237 |
+
"ألعاب أطفال": ["lego", "toy", "doll", "لعبة"],
|
| 238 |
+
"ملحقات سيارات": ["dashcam", "car charger", "car holder", "سيارة"],
|
| 239 |
+
"أدوات المطبخ": ["air fryer", "blender", "coffee", "mixer", "قلاية", "خلاط"],
|
| 240 |
+
"عناية شخصية": ["shaver", "hair", "brush", "عناية", "حلاقة"],
|
| 241 |
+
"أجهزة منزلية كبيرة": ["fridge", "dryer", "washer", "غسالة", "ثلاجة"],
|
| 242 |
+
"أجهزة منزلية صغيرة": ["vacuum", "cleaner", "iron", "مكنسة", "مكواة"]
|
| 243 |
}
|
| 244 |
|
| 245 |
for target, keywords in KEYWORD_MAP.items():
|