hisham-cmd commited on
Commit
3f50ffd
·
verified ·
1 Parent(s): 84ae7ef

Update backend with high-quality catalog and fixes

Browse files
Files changed (1) hide show
  1. 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 Style)
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 & Gaming",
64
- "icon": "🚗",
65
  "subs": [
66
- {"en": "Accessories", "ar": "اكسسوارات الأجهزة"},
67
- {"en": "Gaming", "ar": "ألعاب إلكترونية"},
68
- {"en": "Security Cameras", "ar": "كاميرات مراقبة"},
69
- {"en": "Car Accessories", "ar": "ملحقات السيارات"},
 
70
  ]
71
  },
72
- "الأجهزة المنزلية": {
73
- "name_en": "Large Appliances",
74
- "icon": "🏠",
75
  "subs": [
76
- {"en": "Home Appliances", "ar": "المستلزمات المنزلية"},
77
- {"en": "Kitchen", "ar": "المنزل والمطبخ"},
 
78
  ]
79
  },
80
- "تصنيفات أخرى": {
81
- "name_en": "Other Categories",
82
- "icon": "✨",
83
  "subs": [
84
- {"en": "Beauty", "ar": "العطور والتجميل"},
85
- {"en": "Watches", "ar": "الساعات والإكسسوارات"},
 
 
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 Cameras": "كاميرات مراقبة",
100
- "Car Accessories": "ملحقات السيارات",
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 in multiple likely locations
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.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "real_products_200.json"),
172
  os.path.abspath("real_products_200.json"),
173
- os.path.abspath("backend/real_products_200.json"),
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
- "ألعاب إلكترونية": ["game", "playstation", "xbox", "nintendo", "controller", "ألعاب", "بلايستيشن"],
234
- "المستلزمات المنزلية": ["vacuum", "cleaner", "iron", "washer", "مكنسة", "غسالة", "مكواة"],
235
- "ملحقات السيارات": ["car", "dashcam", "charger", "سيارة", "شاحن"],
236
- "العطور والتجميل": ["perfume", "beauty", "cream", "عطر", "تجميل", "كريم"]
 
 
 
 
 
 
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():