DrAbbas commited on
Commit
90c40c9
ยท
verified ยท
1 Parent(s): b3335b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -8
app.py CHANGED
@@ -1161,7 +1161,64 @@ def crop_container(img):
1161
  # ู„ุง ูŠุณุชุฎุฏู… classify_image ูˆู„ุง analyze_image
1162
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
1163
 
1164
- def yolo11_fast_classify(img, declared_text):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1165
  """โšก ุชุตู†ูŠู ุณุฑูŠุน ุจู€ YOLO11x-cls ูู‚ุท (3-8 ุซูˆุงู†ูŠ)"""
1166
  if img is None:
1167
  return ("<div style='text-align:center;padding:60px;color:#999;'>"
@@ -1301,13 +1358,12 @@ def yolo11_fast_classify(img, declared_text):
1301
  'ุงู„ุซู‚ุฉ': f"{conf:.1%}", 'ุงู„ู…ุตุฏุฑ': source_label})
1302
  df = pd.DataFrame(rows)
1303
 
1304
- # โ•โ•โ• ู…ุทุงุจู‚ุฉ ุงู„ุชุตุฑูŠุญ โ•โ•โ•
1305
  declared = [d.strip().lower() for d in declared_text.split('+') if d.strip()] if declared_text else []
1306
- det_names = [it.lower() for it, _ in items_list]
1307
  is_match = True
1308
  if declared:
1309
- matched = sum(1 for d in declared if any(d in nm for nm in det_names))
1310
- is_match = matched / max(len(declared), 1) > 0.5
1311
 
1312
  top_name, top_conf = items_list[0]
1313
  risk = 0 if is_match else 3
@@ -2268,10 +2324,9 @@ def analyze_image(img, declared_text):
2268
  df = pd.DataFrame(rows)
2269
 
2270
  declared = [d.strip().lower() for d in declared_text.split('+') if d.strip()] if declared_text else []
2271
- det_names = [it.lower() for it, _ in final_items]
2272
  if declared:
2273
- matched = sum(1 for d in declared if any(d in nm for nm in det_names))
2274
- is_match = matched / max(len(declared), 1) > 0.5
2275
  else:
2276
  is_match = random.choice([True, True, True, False])
2277
 
 
1161
  # ู„ุง ูŠุณุชุฎุฏู… classify_image ูˆู„ุง analyze_image
1162
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
1163
 
1164
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
1165
+ # ๐Ÿง  ู…ุทุงุจู‚ุฉ ุฐูƒูŠุฉ: ุชุฑุจุท ุงู„ุจูŠุงู† ุงู„ุนุฑุจูŠ/ุงู„ุฅู†ุฌู„ูŠุฒูŠ ุจู†ุชูŠุฌุฉ YOLO
1166
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
1167
+ GOODS_MATCH_MAP = {
1168
+ "rice": ["rice","ุฑุฒ","ุฃุฑุฒ","ุงุฑุฒ","sella","basmati","ุญุจูˆุจ","grain","long grain"],
1169
+ "sugar": ["sugar","ุณูƒุฑ"],
1170
+ "wheat": ["wheat","ู‚ู…ุญ","flour","ุทุญูŠู†","ุฏู‚ูŠู‚"],
1171
+ "oil": ["oil","ุฒูŠุช","sunflower","palm","vegetable oil"],
1172
+ "tea": ["tea","ุดุงูŠ"],
1173
+ "coffee": ["coffee","ู‚ู‡ูˆุฉ"],
1174
+ "chemicals": ["chemicals","chemical","ูƒูŠู…ุงูˆูŠุงุช","ูƒูŠู…ูŠุงุฆูŠ","ูƒูŠู…ูŠุงุฆูŠุงุช"],
1175
+ "batteries": ["batteries","battery","ุจุทุงุฑูŠุงุช","ุจุทุงุฑูŠุฉ"],
1176
+ "plastic": ["plastic","ุจู„ุงุณุชูŠูƒ","plastics"],
1177
+ "fabric": ["fabric","textile","ู‚ู…ุงุด","ุฃู‚ู…ุดุฉ","ู…ู†ุณูˆุฌุงุช","ู†ุณูŠุฌ"],
1178
+ "tires": ["tires","tyres","ุฅุทุงุฑุงุช","ุฅุทุงุฑ","tire","tyre"],
1179
+ "shoes": ["shoes","footwear","ุฃุญุฐูŠุฉ","ุญุฐุงุก","sandals"],
1180
+ "food": ["food","foodstuff","ุบุฐุงุก","ู…ูˆุงุฏ ุบุฐุงุฆูŠุฉ","ุฃุบุฐูŠุฉ","foods","ู…ูˆุงุฏ_ุบุฐุงุฆูŠุฉ"],
1181
+ "snacks": ["snacks","ูˆุฌุจุงุช ุฎููŠูุฉ","ู…ู‚ุฑู…ุดุงุช","chips","biscuits","ุจุณูƒูˆูŠุช"],
1182
+ "metal": ["metal","steel","ู…ุนุฏู†","ููˆู„ุงุฐ","ุญุฏูŠุฏ","iron","aluminum","ุฃู„ูˆู…ู†ูŠูˆู…"],
1183
+ "wood": ["wood","timber","ุฎุดุจ","ุฃุฎุดุงุจ","lumber"],
1184
+ "paper": ["paper","ูˆุฑู‚","carton","ูƒุฑุชูˆู†","cardboard"],
1185
+ "medicine": ["medicine","ุฏูˆุงุก","ุฃุฏูˆูŠุฉ","pharmaceutical","drug"],
1186
+ "clothing": ["clothing","clothes","garment","ู…ู„ุงุจุณ","ุซูŠุงุจ","apparel"],
1187
+ "furniture": ["furniture","ุฃุซุงุซ","furniture"],
1188
+ "electronics":["electronics","ุฅู„ูƒุชุฑูˆู†ูŠุงุช","electronic","ูƒู‡ุฑุจุงุฆูŠุงุช"],
1189
+ "vehicles": ["vehicles","ู…ุฑูƒุจุงุช","ุณูŠุงุฑุงุช","cars","truck","ุดุงุญู†ุฉ"],
1190
+ "weapons": ["weapons","ุฃุณู„ุญุฉ","ุณู„ุงุญ","gun","rifle","arms"],
1191
+ "dates": ["dates","ุชู…ุฑ","ุชู…ูˆุฑ","palm dates"],
1192
+ "seeds": ["seeds","ุจุฐูˆุฑ","ุจุฐุฑ","grain","ุญุจูˆุจ"],
1193
+ "salt": ["salt","ู…ู„ุญ"],
1194
+ "spices": ["spices","ุชูˆุงุจู„","ุจู‡ุงุฑุงุช","spice"],
1195
+ }
1196
+
1197
+ def smart_goods_match(declared_word, det_names):
1198
+ """
1199
+ ู…ุทุงุจู‚ุฉ ุฐูƒูŠุฉ ุจูŠู† ูƒู„ู…ุฉ ู…ู† ุงู„ุจูŠุงู† ูˆู…ุฌู…ูˆุนุฉ ู†ุชุงุฆุฌ YOLO
1200
+ ุชุนู…ู„ ู…ุน ุงู„ุนุฑุจูŠ ูˆุงู„ุฅู†ุฌู„ูŠุฒูŠ ุนุจุฑ ุฎุฑูŠุทุฉ ุงู„ู…ุฑุงุฏูุงุช
1201
+ """
1202
+ if not declared_word:
1203
+ return True
1204
+
1205
+ d = declared_word.lower().strip()
1206
+ det_lower = [n.lower() for n in det_names]
1207
+
1208
+ # 1. ู…ุทุงุจู‚ุฉ ู…ุจุงุดุฑุฉ
1209
+ for nm in det_lower:
1210
+ if d in nm or nm in d:
1211
+ return True
1212
+
1213
+ # 2. ู…ุทุงุจู‚ุฉ ุนุจุฑ ุงู„ุฎุฑูŠุทุฉ
1214
+ for category, keywords in GOODS_MATCH_MAP.items():
1215
+ declared_hit = any(k in d for k in keywords)
1216
+ detected_hit = any(k in nm for nm in det_lower for k in keywords)
1217
+ if declared_hit and detected_hit:
1218
+ print(f"โœ… Match via map: '{declared_word}' โ†” {det_names} [{category}]")
1219
+ return True
1220
+
1221
+ return False
1222
  """โšก ุชุตู†ูŠู ุณุฑูŠุน ุจู€ YOLO11x-cls ูู‚ุท (3-8 ุซูˆุงู†ูŠ)"""
1223
  if img is None:
1224
  return ("<div style='text-align:center;padding:60px;color:#999;'>"
 
1358
  'ุงู„ุซู‚ุฉ': f"{conf:.1%}", 'ุงู„ู…ุตุฏุฑ': source_label})
1359
  df = pd.DataFrame(rows)
1360
 
1361
+ # โ•โ•โ• ู…ุทุงุจู‚ุฉ ุงู„ุชุตุฑูŠุญ ุงู„ุฐูƒูŠุฉ: ุนุฑุจูŠ โ†” ุฅู†ุฌู„ูŠุฒูŠ โ•โ•โ•
1362
  declared = [d.strip().lower() for d in declared_text.split('+') if d.strip()] if declared_text else []
1363
+ det_names = [it for it, _ in items_list]
1364
  is_match = True
1365
  if declared:
1366
+ is_match = any(smart_goods_match(d, det_names) for d in declared)
 
1367
 
1368
  top_name, top_conf = items_list[0]
1369
  risk = 0 if is_match else 3
 
2324
  df = pd.DataFrame(rows)
2325
 
2326
  declared = [d.strip().lower() for d in declared_text.split('+') if d.strip()] if declared_text else []
2327
+ det_names = [it for it, _ in final_items]
2328
  if declared:
2329
+ is_match = any(smart_goods_match(d, det_names) for d in declared)
 
2330
  else:
2331
  is_match = random.choice([True, True, True, False])
2332