Update app.py
Browse files
app.py
CHANGED
|
@@ -1273,6 +1273,9 @@ def yolo11_fast_classify(img, declared_text):
|
|
| 1273 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1274 |
# ุฎุฑูุทุฉ ุงูููู
ุงุช ุงูู
ูุชุงุญูุฉ โ ุงุณู
ุงูุตูู ูู ูุงุนุฏุฉ ุงูุจูุงูุงุช
|
| 1275 |
DECLARED_KEYWORD_MAP = {
|
|
|
|
|
|
|
|
|
|
| 1276 |
# ุฃุฑุฒ
|
| 1277 |
'rice': 'rice', 'ุฃุฑุฒ': 'rice', 'ุฑุฒ': 'rice',
|
| 1278 |
'sella': 'rice', 'basmati': 'rice', 'ุจุณู
ุชู': 'rice',
|
|
@@ -1285,16 +1288,32 @@ def yolo11_fast_classify(img, declared_text):
|
|
| 1285 |
'oil': 'oil', 'ุฒูุช': 'oil',
|
| 1286 |
# ุดุงู
|
| 1287 |
'tea': 'tea', 'ุดุงู': 'tea',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1288 |
# ุจูุงุณุชูู
|
| 1289 |
'plastic': 'plastic', 'ุจูุงุณุชูู': 'plastic',
|
| 1290 |
# ุฃูู
ุดุฉ
|
| 1291 |
'fabric': 'fabric', 'textile': 'fabric', 'ูู
ุงุด': 'fabric',
|
|
|
|
|
|
|
| 1292 |
# ุฃุญุฐูุฉ
|
| 1293 |
'shoes': 'shoes', 'footwear': 'shoes', 'ุฃุญุฐูุฉ': 'shoes',
|
| 1294 |
# ุฅุทุงุฑุงุช
|
| 1295 |
'tires': 'tires', 'tyres': 'tires', 'ุฅุทุงุฑุงุช': 'tires',
|
| 1296 |
# ูููุฏ
|
| 1297 |
'fuel': 'fuel', 'diesel': 'fuel', 'ูููุฏ': 'fuel',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1298 |
}
|
| 1299 |
|
| 1300 |
override_applied = False
|
|
@@ -1322,21 +1341,23 @@ def yolo11_fast_classify(img, declared_text):
|
|
| 1322 |
|
| 1323 |
# ุดุฑูุท ุชุทุจูู ุงูู Override:
|
| 1324 |
# 1. YOLO ูุง ููุงูู ุงูุจูุงู
|
| 1325 |
-
# 2. ุซูุฉ YOLO ุฃูู ู
ู
|
| 1326 |
-
if not yolo_agrees and top_yolo_conf < 0.
|
| 1327 |
override_applied = True
|
| 1328 |
override_reason = (
|
| 1329 |
f"ุงูุจูุงู: '{declared_text}' | "
|
| 1330 |
-
f"YOLO ุฃุนุทู: {top_yolo_name} ({top_yolo_conf:.1%}) <
|
| 1331 |
f"Override โ {matched_category}"
|
| 1332 |
)
|
| 1333 |
print(f"\n๐ OVERRIDE: {override_reason}")
|
| 1334 |
-
# ุง
|
| 1335 |
-
|
|
|
|
|
|
|
| 1336 |
|
| 1337 |
-
elif not yolo_agrees and top_yolo_conf >= 0.
|
| 1338 |
-
print(f"\nโ ๏ธ ุชุนุงุฑุถ: ุงูุจูุงู='{matched_keyword}' ููู YOLO ูุงุซู {top_yolo_conf:.1%} ู
ู {top_yolo_name}")
|
| 1339 |
-
print(f" โ ูุญุชูุธ ุจูุชูุฌุฉ YOLO
|
| 1340 |
|
| 1341 |
else:
|
| 1342 |
print(f"\nโ
YOLO ููุงูู ุงูุจูุงู: {matched_category} ({top_yolo_conf:.1%})")
|
|
@@ -2842,25 +2863,19 @@ def api_analyze(img, declared_text=""):
|
|
| 2842 |
return json.dumps(result, ensure_ascii=False)
|
| 2843 |
|
| 2844 |
if __name__ == "__main__":
|
| 2845 |
-
#
|
| 2846 |
-
# ๐ Keep-Alive Thread โ ูู
ูุน Hugging Face Space ู
ู ุงูููู
|
| 2847 |
-
# ูุฑุณู ping ูู 4 ุฏูุงุฆู ูุฅุจูุงุก ุงูู Space ูุดุทุงู 24/7
|
| 2848 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝ๏ฟฝโโโโโโโโโโโโโ
|
| 2849 |
def keep_alive():
|
| 2850 |
import requests as _req
|
| 2851 |
-
|
| 2852 |
-
time_module.sleep(30) # ุงูุชุธุฑ ุญุชู ูุจุฏุฃ ุงูู server
|
| 2853 |
while True:
|
| 2854 |
try:
|
| 2855 |
-
_req.get(
|
| 2856 |
-
print("๐ Keep-Alive
|
| 2857 |
except Exception as e:
|
| 2858 |
-
print(f"๐ Keep-Alive
|
| 2859 |
-
time_module.sleep(240)
|
| 2860 |
-
|
| 2861 |
-
|
| 2862 |
-
ka_thread.start()
|
| 2863 |
-
print("๐ Keep-Alive thread started (ping every 4 min)")
|
| 2864 |
print(f"๐ฑ SONAR-AI v{VERSION}")
|
| 2865 |
print(f"๐ฆ Cargo: {len(CARGO_DATABASE)} | TSC: {len(TSC_DATABASE)}")
|
| 2866 |
print(f"๐ค Models: {len(CLASSIFICATION_MODELS)} cls + {'det' if DETECTION_MODEL else 'no det'}")
|
|
|
|
| 1273 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1274 |
# ุฎุฑูุทุฉ ุงูููู
ุงุช ุงูู
ูุชุงุญูุฉ โ ุงุณู
ุงูุตูู ูู ูุงุนุฏุฉ ุงูุจูุงูุงุช
|
| 1275 |
DECLARED_KEYWORD_MAP = {
|
| 1276 |
+
# ู
ูุฒ
|
| 1277 |
+
'banana': 'banana', 'bananas': 'banana', 'ู
ูุฒ': 'banana',
|
| 1278 |
+
'indian banana': 'banana', 'cavendish': 'banana',
|
| 1279 |
# ุฃุฑุฒ
|
| 1280 |
'rice': 'rice', 'ุฃุฑุฒ': 'rice', 'ุฑุฒ': 'rice',
|
| 1281 |
'sella': 'rice', 'basmati': 'rice', 'ุจุณู
ุชู': 'rice',
|
|
|
|
| 1288 |
'oil': 'oil', 'ุฒูุช': 'oil',
|
| 1289 |
# ุดุงู
|
| 1290 |
'tea': 'tea', 'ุดุงู': 'tea',
|
| 1291 |
+
# ููุงูู ูุฎุถุฑูุงุช
|
| 1292 |
+
'apple': 'fruits', 'apples': 'fruits', 'ุชูุงุญ': 'fruits',
|
| 1293 |
+
'orange': 'fruits', 'oranges': 'fruits', 'ุจุฑุชูุงู': 'fruits',
|
| 1294 |
+
'grape': 'fruits', 'grapes': 'fruits', 'ุนูุจ': 'fruits',
|
| 1295 |
+
'date': 'fruits', 'dates': 'fruits', 'ุชู
ุฑ': 'fruits',
|
| 1296 |
+
'vegetable': 'vegetables', 'vegetables': 'vegetables', 'ุฎุถุฑูุงุช': 'vegetables',
|
| 1297 |
# ุจูุงุณุชูู
|
| 1298 |
'plastic': 'plastic', 'ุจูุงุณุชูู': 'plastic',
|
| 1299 |
# ุฃูู
ุดุฉ
|
| 1300 |
'fabric': 'fabric', 'textile': 'fabric', 'ูู
ุงุด': 'fabric',
|
| 1301 |
+
'garment': 'clothes', 'garments': 'clothes', 'ู
ูุงุจุณ': 'clothes',
|
| 1302 |
+
'clothes': 'clothes', 'clothing': 'clothes',
|
| 1303 |
# ุฃุญุฐูุฉ
|
| 1304 |
'shoes': 'shoes', 'footwear': 'shoes', 'ุฃุญุฐูุฉ': 'shoes',
|
| 1305 |
# ุฅุทุงุฑุงุช
|
| 1306 |
'tires': 'tires', 'tyres': 'tires', 'ุฅุทุงุฑุงุช': 'tires',
|
| 1307 |
# ูููุฏ
|
| 1308 |
'fuel': 'fuel', 'diesel': 'fuel', 'ูููุฏ': 'fuel',
|
| 1309 |
+
# ุฃุฏููุฉ
|
| 1310 |
+
'medicine': 'medicine', 'medicines': 'medicine', 'pharmaceutical': 'medicine',
|
| 1311 |
+
'ุฃุฏููุฉ': 'medicine', 'ุฏูุงุก': 'medicine',
|
| 1312 |
+
# ุฅููุชุฑูููุงุช
|
| 1313 |
+
'electronics': 'electronics', 'electronic': 'electronics', 'ุฅููุชุฑูููุงุช': 'electronics',
|
| 1314 |
+
# ู
ูุงุฏ ุจูุงุก
|
| 1315 |
+
'ceramic': 'ceramics', 'tiles': 'ceramics', 'ุณูุฑุงู
ูู': 'ceramics',
|
| 1316 |
+
'steel': 'steel', 'iron': 'steel', 'ุญุฏูุฏ': 'steel', 'ูููุงุฐ': 'steel',
|
| 1317 |
}
|
| 1318 |
|
| 1319 |
override_applied = False
|
|
|
|
| 1341 |
|
| 1342 |
# ุดุฑูุท ุชุทุจูู ุงูู Override:
|
| 1343 |
# 1. YOLO ูุง ููุงูู ุงูุจูุงู
|
| 1344 |
+
# 2. โ
ุซูุฉ YOLO ุฃูู ู
ู 85% (ุตูุฑ ุงูุณููุงุฑ ุตุนุจุฉุ YOLO ูุฏ ููุฎุทุฆ ุจุซูุฉ 52-80%)
|
| 1345 |
+
if not yolo_agrees and top_yolo_conf < 0.85:
|
| 1346 |
override_applied = True
|
| 1347 |
override_reason = (
|
| 1348 |
f"ุงูุจูุงู: '{declared_text}' | "
|
| 1349 |
+
f"YOLO ุฃุนุทู: {top_yolo_name} ({top_yolo_conf:.1%}) < 85% | "
|
| 1350 |
f"Override โ {matched_category}"
|
| 1351 |
)
|
| 1352 |
print(f"\n๐ OVERRIDE: {override_reason}")
|
| 1353 |
+
# โ
ุงูุจุถุงุนุฉ ุงูู
ุตุฑูุญุฉ ุฃููุงู + ุจุงูู ูุชุงุฆุฌ YOLO ูู
ุดุจููุฉ
|
| 1354 |
+
declared_item = (matched_category, 0.70)
|
| 1355 |
+
other_items = [(n, c) for n, c in items_list[1:] if n != matched_category]
|
| 1356 |
+
items_list = [declared_item] + other_items[:3]
|
| 1357 |
|
| 1358 |
+
elif not yolo_agrees and top_yolo_conf >= 0.85:
|
| 1359 |
+
print(f"\nโ ๏ธ ุชุนุงุฑุถ ููู: ุงูุจูุงู='{matched_keyword}' ููู YOLO ูุงุซู {top_yolo_conf:.1%} ู
ู {top_yolo_name}")
|
| 1360 |
+
print(f" โ ูุญุชูุธ ุจูุชูุฌุฉ YOLO (ู
ุดุจูู!)")
|
| 1361 |
|
| 1362 |
else:
|
| 1363 |
print(f"\nโ
YOLO ููุงูู ุงูุจูุงู: {matched_category} ({top_yolo_conf:.1%})")
|
|
|
|
| 2863 |
return json.dumps(result, ensure_ascii=False)
|
| 2864 |
|
| 2865 |
if __name__ == "__main__":
|
| 2866 |
+
# ๐ Keep-Alive โ ูู
ูุน Hugging Face Space ู
ู ุงูููู
|
|
|
|
|
|
|
|
|
|
| 2867 |
def keep_alive():
|
| 2868 |
import requests as _req
|
| 2869 |
+
time_module.sleep(30)
|
|
|
|
| 2870 |
while True:
|
| 2871 |
try:
|
| 2872 |
+
_req.get("http://localhost:7860/", timeout=5)
|
| 2873 |
+
print("๐ Keep-Alive OK")
|
| 2874 |
except Exception as e:
|
| 2875 |
+
print(f"๐ Keep-Alive: {e}")
|
| 2876 |
+
time_module.sleep(240)
|
| 2877 |
+
threading.Thread(target=keep_alive, daemon=True, name="KeepAlive").start()
|
| 2878 |
+
print("๐ Keep-Alive started (every 4 min)")
|
|
|
|
|
|
|
| 2879 |
print(f"๐ฑ SONAR-AI v{VERSION}")
|
| 2880 |
print(f"๐ฆ Cargo: {len(CARGO_DATABASE)} | TSC: {len(TSC_DATABASE)}")
|
| 2881 |
print(f"๐ค Models: {len(CLASSIFICATION_MODELS)} cls + {'det' if DETECTION_MODEL else 'no det'}")
|