Poe255M commited on
Commit
4645c1d
·
verified ·
1 Parent(s): e2a3c21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -39
app.py CHANGED
@@ -272,40 +272,64 @@ class VerificationSystem:
272
 
273
  @staticmethod
274
  def get_nlp_prediction(text):
275
- """🌟 AI Accuracy ကို ၉၉% ထိ တိုးမြှင့်လိုက်သော logic 🌟"""
276
  if not text or len(text.split()) < 3: return 10.0
277
 
278
  # ၁။ AI Model မှ ရလဒ်ယူခြင်း
279
  inputs = tokenizer(text, max_length=512, padding="max_length", truncation=True, return_tensors="pt").to(device)
 
280
  with torch.no_grad():
281
  outputs = nlp_model(**inputs)
282
  probs = torch.nn.functional.softmax(outputs.logits, dim=-1)[0]
283
 
284
  real_score = probs[0].item() * 100
285
 
286
- # ၂။ 🚨 Case 2 & 3 အတွက် အထူး Red Flags (Heuristics)
287
- # သတင်းအတုတွေမှာ အမြဲသုံးတဲ့ 'ခြိမ်းခြောက်မှု' နဲ့ 'လောဘဆွမှု' စကားလုံးများ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  urgency_patterns = [
289
  "ပိတ်သိမ်းသွားမည်", "ပိတ်သိမ်းတော့မယ်", "အမြန်ဆုံး", "လက်ဆင့်ကမ်း",
290
  "အတွင်းသတင်း", "Update ပြုလုပ်ရပါမည်", "Personal Information",
291
  "အကောင့်ပိတ်သိမ်း", "ယာယီပိတ်သိမ်း", "မယုံနိုင်စရာ", "၁၀၀% အမှန်"
292
  ]
293
 
294
- penalty = 0
295
- for pattern in urgency_patterns:
296
- if pattern in text:
297
- penalty += 20 # တစ်ခုပါတိုင်း ၂၀% ျှော့ချမည
 
 
 
 
 
 
 
 
298
 
299
  # ၃။ AI က ၉၀% ကျော် အစစ်လို့ပြောရင်တောင် Penalty ပါရင် Score ကို ချက်ချင်းချမည်
300
  final_score = real_score - penalty
301
 
302
  # ၄။ Logic Correction (Case 2/3 Fix)
303
  # AI က သိပ်မသေချာဘူး (၇၅% အောက်) ဆိုရင် 'သံသယဖြစ်ဖွယ်' ဘက်ကို ပိုပို့မည်
304
- if final_score < 75:
305
- final_score = final_score * 0.6 # Score ကို ထပ်လျှော့ချခြင်း
306
 
307
  return round(max(5, final_score), 2)
308
 
 
 
309
  @staticmethod
310
  def check_rss_similarity(headline, url=""):
311
  import requests
@@ -327,13 +351,15 @@ class VerificationSystem:
327
  break
328
 
329
  feeds = [
330
- "https://feeds.bbci.co.uk/news/world/rss.xml",
 
331
  "https://www.bbc.com/burmese/index.xml",
332
- "https://www.rfa.org/burmese/RSS",
333
- "https://burmese.voanews.com/api/zuy_pv-m_i",
334
- "https://www.theguardian.com/world/rss",
335
- "https://rss.nytimes.com/services/xml/rss/nyt/World.xml"
336
- "https://www.myanmarcelebrity.com/"
 
337
  ]
338
 
339
  headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}
@@ -365,7 +391,6 @@ class VerificationSystem:
365
 
366
 
367
 
368
-
369
  # --- 3. MASTER ENGINE (Final Presentation Version) ---
370
  def master_detector_v12(text, url, image):
371
  try:
@@ -374,7 +399,7 @@ def master_detector_v12(text, url, image):
374
  # ၁။ 🚨 Empty Input Check (စာသားမပါလျှင်)
375
  if not text or not text.strip():
376
  return "<div style='color:#dc2626; padding:20px; text-align:center; background:#fef2f2; border-radius:10px; border:1px solid #fca5a5;'><b>⚠️ ကျေးဇူးပြု၍ စစ်ဆေးလိုသော သတင်းစာသားကို ထည့်သွင်းပါ။</b></div>"
377
-
378
  # ၂။ 🚨 Short Text Check ("I don't know" Logic - စာသားတိုလွန်းလျှင်)
379
  words = text.split()
380
  if len(words) < 10:
@@ -385,11 +410,11 @@ def master_detector_v12(text, url, image):
385
  AI မှ တိကျစွာ ဆန်းစစ်နိုင်ရန်အတွက် အနည်းဆုံး စကားလုံး (၁၀) လုံးနှင့်အထက် ပါဝင်သော သတင်းအပြည့်အစုံကို ထည့်သွင်းပေးပါ။
386
  </div>
387
  """
388
-
389
  # URL ပါ၊ မပါ စစ်ဆေးခြင်း
390
  has_url = bool(url and url.strip() != "")
391
  is_myanmar = bool(re.search(r'[\u1000-\u109F]', text))
392
-
393
  # --- 📊 3. UI Progress Bar ဖန်တီးပေးသော Helper Function ---
394
  def create_bar(label, value, bar_color, is_mm, nlp_label_local, custom_msg=None):
395
  if custom_msg:
@@ -410,7 +435,6 @@ def master_detector_v12(text, url, image):
410
  elif label == "Visual Context":
411
  explainer = ("✅ ပုံနှင့်စာသား ကိုက်ညီမှုရှိသည်။" if value > 72 else "⚠️ ပုံနှင့်စာသား တစ်ခြားစီဖြစ်နေသည်။") if is_mm else ("✅ Context matches." if value > 72 else "⚠️ Context mismatch.")
412
  else: explainer = ""
413
-
414
  return f"""
415
  <div style="margin-bottom: 12px;">
416
  <div style="display: flex; justify-content: space-between; font-size: 0.8rem; color: #475569; margin-bottom: 3px;">
@@ -421,13 +445,13 @@ def master_detector_v12(text, url, image):
421
  </div>
422
  <div style="font-size: 0.72rem; color: #1e293b; margin-top: 3px; line-height: 1.3; font-weight: 500;">{explainer}</div>
423
  </div>"""
424
-
425
  # --- 🔍 4. Core Metrics Calculations ---
426
  url_image = v.extract_image_from_url(url) if has_url else None
427
  src_score, src_msg = v.get_source_score(url) if has_url else (0, "No URL")
428
  rss_score = v.check_rss_similarity(text, url=url)
429
  nlp_score = v.get_nlp_prediction(text)
430
-
431
  # NLP Score Labeling
432
  if nlp_score >= 65:
433
  nlp_label = "Real"; nlp_val = nlp_score; ai_c = "#10b981"
@@ -435,12 +459,12 @@ def master_detector_v12(text, url, image):
435
  nlp_label = "Fake"; nlp_val = 100 - nlp_score; ai_c = "#dc2626"
436
  else:
437
  nlp_label = "Neutral"; nlp_val = nlp_score; ai_c = "#94a3b8"
438
-
439
  # --- 🖼️ 5. Image Processing & Zero-shot Classification ---
440
  image_bars_html = ""
441
  img_msg_extra = ""
442
  sim_msg = ""
443
-
444
  if image:
445
  # ပြည်တွင်း/ပြည်ပ မြင်ကွင်းခွဲခြားခြင်း (Zero-shot CLIP)
446
  try:
@@ -452,20 +476,19 @@ def master_detector_v12(text, url, image):
452
  loc_embs = clip_model.encode(loc_prompts)
453
  img_emb_local = clip_model.encode(img_obj)
454
  loc_scores = util.cos_sim(img_emb_local, loc_embs)[0]
455
-
456
  if loc_scores[1] > loc_scores[0] + 0.02:
457
  img_msg_extra = "<br><span style='color:#dc2626; font-weight:600;'>🌍 AI Visual Scan: ဤပုံသည် ပြည်ပနိုင်ငံမှ မြင်ကွင်းဖြစ်နိုင်ခြေများပါသည်။ (Foreign Image Detected)</span>"
458
  elif loc_scores[0] > loc_scores[1] + 0.02:
459
  img_msg_extra = "<br><span style='color:#059669; font-weight:600;'>🇲🇲 AI Visual Scan: ဤပုံသည် ပြည်တွင်းမှ မြင်ကွင်းဖြစ်နိုင်ခြေများပါသည်။ (Domestic Image)</span>"
460
  except Exception as e:
461
  pass # Error တက်လျှင် ကျော်သွားမည်
462
-
463
  img_ela_score, _ = v.perform_ela(image)
464
  img_sim_score, sim_msg_original = v.get_image_text_similarity(image, text, url=url, url_image_path=url_image)
465
 
466
  # Combine image similarity message with location detection
467
  sim_msg = sim_msg_original + img_msg_extra
468
-
469
  # ⚖️ Dynamic Weighting for Image Case
470
  if has_url:
471
  weights = {'source': 0.20, 'nlp': 0.35, 'rss': 0.15, 'ela': 0.10, 'sim': 0.20}
@@ -476,7 +499,7 @@ def master_detector_v12(text, url, image):
476
  final = (src_score * weights['source']) + (nlp_score * weights['nlp']) + \
477
  (rss_score * weights['rss']) + (img_ela_score * weights['ela']) + \
478
  (img_sim_score * weights['sim'])
479
-
480
  image_bars_html = f"""
481
  {create_bar("Image Integrity", img_ela_score, "#f59e0b", is_myanmar, nlp_label)}
482
  {create_bar("Visual Context", img_sim_score, "#06b6d4", is_myanmar, nlp_label, custom_msg=sim_msg)}
@@ -493,6 +516,19 @@ def master_detector_v12(text, url, image):
493
  img_msg = "ℹ️ ပုံမပါဝင်သည့်အတွက် Visual Analysis မပြုလုပ်ပါ။" if is_myanmar else "ℹ️ No image for visual analysis."
494
  image_bars_html = f'<div style="padding:12px; background:#f1f5f9; border-radius:8px; font-size:0.75rem; color:#475569; text-align:center;">{img_msg}</div>'
495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  # --- 🗂️ 6. Final Status & Dynamic Color Logic ---
497
  if final >= 75:
498
  main_bg, accent_c, status = "#ecfdf5", "#059669", "✅ ယုံကြည်စိတ်ချရသော သတင်း (RELIABLE VERDICT)"
@@ -500,19 +536,26 @@ def master_detector_v12(text, url, image):
500
  main_bg, accent_c, status = "#f8fafc", "#64748b", "⚖️ အတည်ပြုရန်ခက်ခဲသော သတင်း (INCONCLUSIVE / NEUTRAL)"
501
  else:
502
  main_bg, accent_c, status = "#fef2f2", "#dc2626", "🚨 သတင်းတု / အန္တရာယ်ရှိသောသတင်း (FAKE / HIGH RISK)"
503
-
504
  # --- 📝 7. Analysis & Recommendations ---
505
  analysis_header = "🔎 အသေးစိတ် ဆန်းစစ်ချက်" if is_myanmar else "🔎 Detailed Reasoning"
506
  tips_header = "🛡️ အကြံပြုချက်နှင့် သတိပြုရန်" if is_myanmar else "🛡️ Recommendations"
507
  reasons = []
508
  tips = []
509
-
510
  if final >= 75:
511
- reasons.append("✅ သတင်းရင်းမြစ်နှင့်ချကကား ခိုင်မာမှုရှိသည်။")
 
 
 
 
 
512
  tips.append("💡 ဤသတင်းသည် ယုံကြည်စိတ်ချရသဖြင��် ဝေမျှနိုင်ပါသည်။")
 
513
  elif final >= 45 and final < 75:
514
  reasons.append("⚖️ အချက်အလက်များမှာ အမှန်နှင့် အမှား ရောထွေးနေနိုင်ပါသည်။ (သို့) လုံလောက်သော သက်သေအထောက်အထား မတွေ့ရသေးပါ။")
515
  tips.append("💡 ဤသတင်းကို ချက်ချင်းမယုံကြည်ဘဲ အခြားတရားဝင် မီဒီယာကြီးများတွင် ထပ်မံစစ်ဆေးရန် အကြံပြုအပ်ပါသည်။")
 
516
  else:
517
  if nlp_label == "Fake": reasons.append("⚠️ AI စနစ်မှ ဤစာသားသည် သတင်းအတု/Clickbait ပုံစံဖြစ်နေကြောင်း တွေ့ရှိရသည်။")
518
 
@@ -522,18 +565,17 @@ def master_detector_v12(text, url, image):
522
  reasons.append(f"❌ သတင်းရင်းမြစ် ({src_msg}) သည် စိတ်မချရပါ။")
523
 
524
  tips.append("💡 သတင်းအမှားဖြစ်နိုင်ခြေ အလွန်များသဖြင့် အခြားသူများထံ ဆက်လက်မဝေမျှရန် အသိပေးအပ်ပါသည်။")
525
-
526
  reasons_html = "".join([f"<li style='margin-bottom:5px;'>{r}</li>" for r in reasons])
527
  tips_html = "".join([f"<li style='margin-bottom:6px;'>{t}</li>" for t in tips])
528
 
529
- # --- 🌐 8. Final HTML Output ---
530
  return f"""
531
  <div style="background: {main_bg}; padding: 22px; border-radius: 15px; border: 1px solid {accent_c}33; font-family: sans-serif; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
532
  <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
533
  <h3 style="margin: 0; color: {accent_c}; font-size: 1.15rem; font-weight: 800;">{status}</h3>
534
  <span style="background: {accent_c}; color: white; padding: 5px 15px; border-radius: 25px; font-weight: 800;">{final:.1f}%</span>
535
  </div>
536
-
537
  <div style="background: white; padding: 18px; border-radius: 12px; box-shadow: 0 2px 4px rgba(0,0,0,0.03);">
538
  <b style="font-size: 0.85rem; color: #1e293b; display: block; margin-bottom: 15px; text-transform: uppercase;">📊 Verification Metrics:</b>
539
  {create_bar("Source Trust", src_score, "#3b82f6", is_myanmar, nlp_label)}
@@ -542,22 +584,23 @@ def master_detector_v12(text, url, image):
542
  <hr style="border: 0; border-top: 1px solid #f1f5f9; margin: 18px 0;">
543
  {image_bars_html}
544
  </div>
545
-
546
  <div style="background: {("#f0fdf4" if final >= 75 else "#f8fafc" if final >= 45 else "#fef2f2")}; padding: 15px; border-radius: 10px; border-left: 5px solid {accent_c}; margin-top: 15px;">
547
  <b style="color: {accent_c}; display: block; margin-bottom: 8px;">{analysis_header}</b>
548
  <ul style="margin: 0; padding-left: 20px; color: #1e293b; font-size: 0.95rem;">{reasons_html if reasons_html else "<li>Analysis complete.</li>"}</ul>
549
  </div>
550
-
551
  <div style="background: #eff6ff; padding: 15px; border-radius: 10px; border-left: 5px solid #2563eb; margin-top: 12px;">
552
  <b style="color: #1e40af; display: block; margin-bottom: 8px;">{tips_header}</b>
553
  <ul style="margin: 0; padding-left: 20px; color: #1e3a8a; font-size: 0.95rem;">{tips_html}</ul>
554
  </div>
555
-
556
  </div>
557
  """
558
  except Exception as e:
559
  import traceback
560
- return f"<div style='color:red; padding:20px; border:1px solid red; border-radius:10px;'><b>System Error:</b> {str(e)}<br><pre style='font-size:0.7rem;'>{traceback.format_exc()}</pre></div>"
 
 
 
 
561
 
562
 
563
  # --- 4. MODERN UI DESIGN ---
@@ -640,4 +683,4 @@ with gr.Blocks(css=custom_css) as demo:
640
  clear.click(lambda: ["", "", None, empty_html], outputs=[txt, url, img, output])
641
 
642
  if __name__ == "__main__":
643
- demo.launch()
 
272
 
273
  @staticmethod
274
  def get_nlp_prediction(text):
275
+
276
  if not text or len(text.split()) < 3: return 10.0
277
 
278
  # ၁။ AI Model မှ ရလဒ်ယူခြင်း
279
  inputs = tokenizer(text, max_length=512, padding="max_length", truncation=True, return_tensors="pt").to(device)
280
+ import torch
281
  with torch.no_grad():
282
  outputs = nlp_model(**inputs)
283
  probs = torch.nn.functional.softmax(outputs.logits, dim=-1)[0]
284
 
285
  real_score = probs[0].item() * 100
286
 
287
+
288
+ text_lower = text.lower()
289
+ penalty = 0
290
+
291
+ # (က) Health Scam ဖမ်းရန် (WHO/သုတေသန နာမည်သုံးပြီး လိမ်ထားလျှင်)
292
+ health_keywords = ["ကျန်းမာရေး", "ရောဂါ", "ဆေး", "who", "သုတေသန", "အတည်ပြု"]
293
+ if any(kw in text_lower for kw in health_keywords):
294
+ scam_words = ["၁၀၀%", "အာမခံ", "ချက်ချင်း", "လျှို့ဝှက်ချက်", "မဖြစ်မနေ", "ပျောက်ကင်း", "လုံးဝကာကွယ်", "အထူးသဖြင့်", "ပိုမိုထိရောက်"]
295
+ if any(sw in text_lower for sw in scam_words):
296
+ penalty += 35 # ကျန်းမာရေးလိမ်လည်မှုဖြစ်၍ အမှတ်များများလျှော့မည်
297
+
298
+ # (ခ) Cele News မှန်လျှင် Penalty မထိစေရန် ကာကွယ်ခြင်း
299
+ cele_keywords = ["မင်းသား", "မင်းသမီး", "အဆိုတော်", "သရုပ်ဆောင်", "ဆယ်လီ", "လက်ထပ်", "celebrity"]
300
+ is_cele = any(kw in text_lower for kw in cele_keywords)
301
+
302
+ # ၂။ Case 2 & 3 အတွက် အထူး Red Flags (Heuristics) - (ညီမ၏ မူလ Code အတိုင်း)
303
  urgency_patterns = [
304
  "ပိတ်သိမ်းသွားမည်", "ပိတ်သိမ်းတော့မယ်", "အမြန်ဆုံး", "လက်ဆင့်ကမ်း",
305
  "အတွင်းသတင်း", "Update ပြုလုပ်ရပါမည်", "Personal Information",
306
  "အကောင့်ပိတ်သိမ်း", "ယာယီပိတ်သိမ်း", "မယုံနိုင်စရာ", "၁၀၀% အမှန်"
307
  ]
308
 
309
+ if is_cele:
310
+ # ဆယ်လီသတင်းဆိုလျှင် "မယုံနိုင်စရာ" ကဲ့သို့သော စကားလုံးများအတွက် Penalty မပေးတော့ပါ။
311
+ # Clickbait လင့်ခ်နှိပ်ခိုင်းတာမျိုးကိုပဲ သီးသန့်စစ်ပါမည်။
312
+ clickbait_patterns = ["ဗီဒီယိုကြည့်ရန်", "ရှယ်ထား", "လင့်ခ်ဝင်ကြည့်", "ဖုန်ဘေလ်", "က်ဆော"]
313
+ for pattern in clickbait_patterns:
314
+ if pattern in text_lower:
315
+ penalty += 20
316
+ else:
317
+
318
+ for pattern in urgency_patterns:
319
+ if pattern in text:
320
+ penalty += 20 # တစ်ခုပါတိုင်း ၂၀% လျှော့ချမည်
321
 
322
  # ၃။ AI က ၉၀% ကျော် အစစ်လို့ပြောရင်တောင် Penalty ပါရင် Score ကို ချက်ချင်းချမည်
323
  final_score = real_score - penalty
324
 
325
  # ၄။ Logic Correction (Case 2/3 Fix)
326
  # AI က သိပ်မသေချာဘူး (၇၅% အောက်) ဆိုရင် 'သံသယဖြစ်ဖွယ်' ဘက်ကို ပိုပို့မည်
327
+ if final_score < 75:final_score = final_score * 0.6 # Score ကို ထပ်လျှော့ချခြင်း
 
328
 
329
  return round(max(5, final_score), 2)
330
 
331
+
332
+
333
  @staticmethod
334
  def check_rss_similarity(headline, url=""):
335
  import requests
 
351
  break
352
 
353
  feeds = [
354
+ "https://burmese.voanews.com/api/z$y_iqve_t",
355
+ "https://www.rfa.org/burmese/rss2.xml",
356
  "https://www.bbc.com/burmese/index.xml",
357
+ "https://burmese.dvb.no/feed",
358
+ "https://www.mizzimaburmese.com/rss",
359
+ "https://www.khitthitnews.com/feed",
360
+ "https://burmese.irrawaddy.com/feed",
361
+ "https://www.myanmarcelebrity.com/feeds/posts/default?alt=rss",
362
+ "https://popularmyanmar.com/feed/"
363
  ]
364
 
365
  headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}
 
391
 
392
 
393
 
 
394
  # --- 3. MASTER ENGINE (Final Presentation Version) ---
395
  def master_detector_v12(text, url, image):
396
  try:
 
399
  # ၁။ 🚨 Empty Input Check (စာသားမပါလျှင်)
400
  if not text or not text.strip():
401
  return "<div style='color:#dc2626; padding:20px; text-align:center; background:#fef2f2; border-radius:10px; border:1px solid #fca5a5;'><b>⚠️ ကျေးဇူးပြု၍ စစ်ဆေးလိုသော သတင်းစာသားကို ထည့်သွင်းပါ။</b></div>"
402
+
403
  # ၂။ 🚨 Short Text Check ("I don't know" Logic - စာသားတိုလွန်းလျှင်)
404
  words = text.split()
405
  if len(words) < 10:
 
410
  AI မှ တိကျစွာ ဆန်းစစ်နိုင်ရန်အတွက် အနည်းဆုံး စကားလုံး (၁၀) လုံးနှင့်အထက် ပါဝင်သော သတင်းအပြည့်အစုံကို ထည့်သွင်းပေးပါ။
411
  </div>
412
  """
413
+
414
  # URL ပါ၊ မပါ စစ်ဆေးခြင်း
415
  has_url = bool(url and url.strip() != "")
416
  is_myanmar = bool(re.search(r'[\u1000-\u109F]', text))
417
+
418
  # --- 📊 3. UI Progress Bar ဖန်တီးပေးသော Helper Function ---
419
  def create_bar(label, value, bar_color, is_mm, nlp_label_local, custom_msg=None):
420
  if custom_msg:
 
435
  elif label == "Visual Context":
436
  explainer = ("✅ ပုံနှင့်စာသား ကိုက်ညီမှုရှိသည်။" if value > 72 else "⚠️ ပုံနှင့်စာသား တစ်ခြားစီဖြစ်နေသည်။") if is_mm else ("✅ Context matches." if value > 72 else "⚠️ Context mismatch.")
437
  else: explainer = ""
 
438
  return f"""
439
  <div style="margin-bottom: 12px;">
440
  <div style="display: flex; justify-content: space-between; font-size: 0.8rem; color: #475569; margin-bottom: 3px;">
 
445
  </div>
446
  <div style="font-size: 0.72rem; color: #1e293b; margin-top: 3px; line-height: 1.3; font-weight: 500;">{explainer}</div>
447
  </div>"""
448
+
449
  # --- 🔍 4. Core Metrics Calculations ---
450
  url_image = v.extract_image_from_url(url) if has_url else None
451
  src_score, src_msg = v.get_source_score(url) if has_url else (0, "No URL")
452
  rss_score = v.check_rss_similarity(text, url=url)
453
  nlp_score = v.get_nlp_prediction(text)
454
+
455
  # NLP Score Labeling
456
  if nlp_score >= 65:
457
  nlp_label = "Real"; nlp_val = nlp_score; ai_c = "#10b981"
 
459
  nlp_label = "Fake"; nlp_val = 100 - nlp_score; ai_c = "#dc2626"
460
  else:
461
  nlp_label = "Neutral"; nlp_val = nlp_score; ai_c = "#94a3b8"
462
+
463
  # --- 🖼️ 5. Image Processing & Zero-shot Classification ---
464
  image_bars_html = ""
465
  img_msg_extra = ""
466
  sim_msg = ""
467
+
468
  if image:
469
  # ပြည်တွင်း/ပြည်ပ မြင်ကွင်းခွဲခြားခြင်း (Zero-shot CLIP)
470
  try:
 
476
  loc_embs = clip_model.encode(loc_prompts)
477
  img_emb_local = clip_model.encode(img_obj)
478
  loc_scores = util.cos_sim(img_emb_local, loc_embs)[0]
 
479
  if loc_scores[1] > loc_scores[0] + 0.02:
480
  img_msg_extra = "<br><span style='color:#dc2626; font-weight:600;'>🌍 AI Visual Scan: ဤပုံသည် ပြည်ပနိုင်ငံမှ မြင်ကွင်းဖြစ်နိုင်ခြေများပါသည်။ (Foreign Image Detected)</span>"
481
  elif loc_scores[0] > loc_scores[1] + 0.02:
482
  img_msg_extra = "<br><span style='color:#059669; font-weight:600;'>🇲🇲 AI Visual Scan: ဤပုံသည် ပြည်တွင်းမှ မြင်ကွင်းဖြစ်နိုင်ခြေများပါသည်။ (Domestic Image)</span>"
483
  except Exception as e:
484
  pass # Error တက်လျှင် ကျော်သွားမည်
485
+
486
  img_ela_score, _ = v.perform_ela(image)
487
  img_sim_score, sim_msg_original = v.get_image_text_similarity(image, text, url=url, url_image_path=url_image)
488
 
489
  # Combine image similarity message with location detection
490
  sim_msg = sim_msg_original + img_msg_extra
491
+
492
  # ⚖️ Dynamic Weighting for Image Case
493
  if has_url:
494
  weights = {'source': 0.20, 'nlp': 0.35, 'rss': 0.15, 'ela': 0.10, 'sim': 0.20}
 
499
  final = (src_score * weights['source']) + (nlp_score * weights['nlp']) + \
500
  (rss_score * weights['rss']) + (img_ela_score * weights['ela']) + \
501
  (img_sim_score * weights['sim'])
502
+
503
  image_bars_html = f"""
504
  {create_bar("Image Integrity", img_ela_score, "#f59e0b", is_myanmar, nlp_label)}
505
  {create_bar("Visual Context", img_sim_score, "#06b6d4", is_myanmar, nlp_label, custom_msg=sim_msg)}
 
516
  img_msg = "ℹ️ ပုံမပါဝင်သည့်အတွက် Visual Analysis မပြုလုပ်ပါ။" if is_myanmar else "ℹ️ No image for visual analysis."
517
  image_bars_html = f'<div style="padding:12px; background:#f1f5f9; border-radius:8px; font-size:0.75rem; color:#475569; text-align:center;">{img_msg}</div>'
518
 
519
+
520
+ # --- 🌟 5.1 Fact-Verification Override (The Veto Power - For Cele News ONLY) 🌟 ---
521
+
522
+ is_corroborated = rss_score >= 70
523
+ cele_keywords = ["မင်းသား", "မင်းသမီး", "အဆိုတော်", "သရုပ်ဆောင်", "ဆယ်လီ", "လက်ထပ်", "celebrity"]
524
+ is_cele_news_context = any(kw in text.lower() for kw in cele_keywords)
525
+
526
+ if is_corroborated and is_cele_news_context:
527
+ final = max(final, 85.0)
528
+ if nlp_label == "Fake":
529
+ nlp_label = "Real (Overridden by Cele Fact-Check)"
530
+
531
+
532
  # --- 🗂️ 6. Final Status & Dynamic Color Logic ---
533
  if final >= 75:
534
  main_bg, accent_c, status = "#ecfdf5", "#059669", "✅ ယုံကြည်စိတ်ချရသော သတင်း (RELIABLE VERDICT)"
 
536
  main_bg, accent_c, status = "#f8fafc", "#64748b", "⚖️ အတည်ပြုရန်ခက်ခဲသော သတင်း (INCONCLUSIVE / NEUTRAL)"
537
  else:
538
  main_bg, accent_c, status = "#fef2f2", "#dc2626", "🚨 သတင်းတု / အန္တရာယ်ရှိသောသတင်း (FAKE / HIGH RISK)"
539
+
540
  # --- 📝 7. Analysis & Recommendations ---
541
  analysis_header = "🔎 အသေးစိတ် ဆန်းစစ်ချက်" if is_myanmar else "🔎 Detailed Reasoning"
542
  tips_header = "🛡️ အကြံပြုချက်နှင့် သတိပြုရန်" if is_myanmar else "🛡️ Recommendations"
543
  reasons = []
544
  tips = []
545
+
546
  if final >= 75:
547
+ # 🌟 Cele News Veto လုပ်လုပခဲ့လှင် Message ပြောင်းပြမည် 🌟
548
+ if is_corroborated and is_cele_news_context:
549
+ reasons.append("🌟 <b>Cele News Verified:</b> ဤအနုပညာသတင်းကို အခြားသော တရားဝင် မီဒီယာများတွင်ပါ အတိအကျ ဖော်ပြထားသဖြင့် သတင်းအမှန်ဖြစ်ကြောင်း အတည်ပြုပါသည်။")
550
+ else:
551
+ reasons.append("✅ သတင်းရင်းမြစ်နှင့် အချက်အလက်များ ခိုင်မာမှုရှိသည်။")
552
+
553
  tips.append("💡 ဤသတင်းသည် ယုံကြည်စိတ်ချရသဖြင��် ဝေမျှနိုင်ပါသည်။")
554
+
555
  elif final >= 45 and final < 75:
556
  reasons.append("⚖️ အချက်အလက်များမှာ အမှန်နှင့် အမှား ရောထွေးနေနိုင်ပါသည်။ (သို့) လုံလောက်သော သက်သေအထောက်အထား မတွေ့ရသေးပါ။")
557
  tips.append("💡 ဤသတင်းကို ချက်ချင်းမယုံကြည်ဘဲ အခြားတရားဝင် မီဒီယာကြီးများတွင် ထပ်မံစစ်ဆေးရန် အကြံပြုအပ်ပါသည်။")
558
+
559
  else:
560
  if nlp_label == "Fake": reasons.append("⚠️ AI စနစ်မှ ဤစာသားသည် သတင်းအတု/Clickbait ပုံစံဖြစ်နေကြောင်း တွေ့ရှိရသည်။")
561
 
 
565
  reasons.append(f"❌ သတင်းရင်းမြစ် ({src_msg}) သည် စိတ်မချရပါ။")
566
 
567
  tips.append("💡 သတင်းအမှားဖြစ်နိုင်ခြေ အလွန်များသဖြင့် အခြားသူများထံ ဆက်လက်မဝေမျှရန် အသိပေးအပ်ပါသည်။")
568
+
569
  reasons_html = "".join([f"<li style='margin-bottom:5px;'>{r}</li>" for r in reasons])
570
  tips_html = "".join([f"<li style='margin-bottom:6px;'>{t}</li>" for t in tips])
571
 
572
+ # --- 🌐 8. Final HTML Output
573
  return f"""
574
  <div style="background: {main_bg}; padding: 22px; border-radius: 15px; border: 1px solid {accent_c}33; font-family: sans-serif; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
575
  <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
576
  <h3 style="margin: 0; color: {accent_c}; font-size: 1.15rem; font-weight: 800;">{status}</h3>
577
  <span style="background: {accent_c}; color: white; padding: 5px 15px; border-radius: 25px; font-weight: 800;">{final:.1f}%</span>
578
  </div>
 
579
  <div style="background: white; padding: 18px; border-radius: 12px; box-shadow: 0 2px 4px rgba(0,0,0,0.03);">
580
  <b style="font-size: 0.85rem; color: #1e293b; display: block; margin-bottom: 15px; text-transform: uppercase;">📊 Verification Metrics:</b>
581
  {create_bar("Source Trust", src_score, "#3b82f6", is_myanmar, nlp_label)}
 
584
  <hr style="border: 0; border-top: 1px solid #f1f5f9; margin: 18px 0;">
585
  {image_bars_html}
586
  </div>
 
587
  <div style="background: {("#f0fdf4" if final >= 75 else "#f8fafc" if final >= 45 else "#fef2f2")}; padding: 15px; border-radius: 10px; border-left: 5px solid {accent_c}; margin-top: 15px;">
588
  <b style="color: {accent_c}; display: block; margin-bottom: 8px;">{analysis_header}</b>
589
  <ul style="margin: 0; padding-left: 20px; color: #1e293b; font-size: 0.95rem;">{reasons_html if reasons_html else "<li>Analysis complete.</li>"}</ul>
590
  </div>
 
591
  <div style="background: #eff6ff; padding: 15px; border-radius: 10px; border-left: 5px solid #2563eb; margin-top: 12px;">
592
  <b style="color: #1e40af; display: block; margin-bottom: 8px;">{tips_header}</b>
593
  <ul style="margin: 0; padding-left: 20px; color: #1e3a8a; font-size: 0.95rem;">{tips_html}</ul>
594
  </div>
 
595
  </div>
596
  """
597
  except Exception as e:
598
  import traceback
599
+ return f"<div style='color:red; padding:20px; border:1px solid red; border-radius:10px;'><b>System Error:</b> {str(e)}<br><pre style='font-size:0.7rem;'>{traceback.format_exc()}</pre></div>"
600
+
601
+
602
+
603
+
604
 
605
 
606
  # --- 4. MODERN UI DESIGN ---
 
683
  clear.click(lambda: ["", "", None, empty_html], outputs=[txt, url, img, output])
684
 
685
  if __name__ == "__main__":
686
+ demo.launch(share=True)