Update app.py
Browse files
app.py
CHANGED
|
@@ -1161,7 +1161,64 @@ def crop_container(img):
|
|
| 1161 |
# ูุง ูุณุชุฎุฏู
classify_image ููุง analyze_image
|
| 1162 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1163 |
|
| 1164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 1307 |
is_match = True
|
| 1308 |
if declared:
|
| 1309 |
-
|
| 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
|
| 2272 |
if declared:
|
| 2273 |
-
|
| 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 |
|