yonilev commited on
Commit
dc3c38e
Β·
verified Β·
1 Parent(s): ba19335

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -3
app.py CHANGED
@@ -72,7 +72,11 @@ def _lazy_init():
72
  BASE_MODEL, device_map="cpu",
73
  torch_dtype=torch.float32, attn_implementation="eager")
74
  model = PeftModel.from_pretrained(base, MODEL_REPO)
75
- print("βœ… CPU: fine-tuned adapter loaded")
 
 
 
 
76
  except Exception as e:
77
  print(f"⚠ adapter failed ({e}); base model (CPU)")
78
  model = AutoModelForCausalLM.from_pretrained(
@@ -135,7 +139,9 @@ def model_parse(raw_text):
135
  out = model.generate(**enc, max_new_tokens=128, do_sample=False,
136
  pad_token_id=tok.pad_token_id)
137
  decoded = tok.decode(out[0, enc["input_ids"].shape[1]:], skip_special_tokens=True)
138
- return _extract_json(decoded)
 
 
139
 
140
 
141
  # ═════════════════════════════════════════════════════════════════════════════
@@ -668,7 +674,35 @@ def _start_discord_bot():
668
  # ═════════════════════════════════════════════════════════════════════════════
669
  # 9. Launch
670
  # ═════════════════════════════════════════════════════════════════════════════
671
- _start_discord_bot()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
672
 
673
  if __name__ == "__main__":
674
  demo.launch(css=CSS)
 
72
  BASE_MODEL, device_map="cpu",
73
  torch_dtype=torch.float32, attn_implementation="eager")
74
  model = PeftModel.from_pretrained(base, MODEL_REPO)
75
+ try:
76
+ model = model.merge_and_unload() # flatten LoRA β†’ base (fixes CPU/PEFT forward quirks)
77
+ print("βœ… CPU: fine-tuned adapter loaded + merged")
78
+ except Exception as _me:
79
+ print(f"⚠ merge_and_unload failed ({_me}); using PEFT-wrapped model")
80
  except Exception as e:
81
  print(f"⚠ adapter failed ({e}); base model (CPU)")
82
  model = AutoModelForCausalLM.from_pretrained(
 
139
  out = model.generate(**enc, max_new_tokens=128, do_sample=False,
140
  pad_token_id=tok.pad_token_id)
141
  decoded = tok.decode(out[0, enc["input_ids"].shape[1]:], skip_special_tokens=True)
142
+ parsed = _extract_json(decoded)
143
+ print(f"πŸ”Ž PARSE in={raw_text!r} | json_ok={parsed is not None} | raw_out={decoded!r}", flush=True)
144
+ return parsed
145
 
146
 
147
  # ═════════════════════════════════════════════════════════════════════════════
 
674
  # ═════════════════════════════════════════════════════════════════════════════
675
  # 9. Launch
676
  # ═════════════════════════════════════════════════════════════════════════════
677
+ # ── TEMP diagnostics β€” remove once model + egress are confirmed ──
678
+ def _probe_discord():
679
+ import socket, urllib.request
680
+ try:
681
+ s = socket.create_connection(("discord.com", 443), timeout=8); s.close()
682
+ print("🩺 PROBE tcp discord.com:443 β†’ OK (TCP reachable)", flush=True)
683
+ except Exception as e:
684
+ print(f"🩺 PROBE tcp discord.com:443 β†’ FAIL {type(e).__name__}: {e}", flush=True)
685
+ return
686
+ try:
687
+ req = urllib.request.Request("https://discord.com/api/v10/gateway",
688
+ headers={"User-Agent": "probe"})
689
+ with urllib.request.urlopen(req, timeout=8) as r:
690
+ print(f"🩺 PROBE https discord.com β†’ OK status={r.status} (EGRESS OPEN)", flush=True)
691
+ except Exception as e:
692
+ print(f"🩺 PROBE https discord.com β†’ FAIL {type(e).__name__}: {e} (EGRESS BLOCKED)", flush=True)
693
+
694
+ def _startup_selftest():
695
+ try:
696
+ _lazy_init()
697
+ for t in ["Χ§Χ™Χ‘ΧœΧͺΧ™ 500 שקל ΧžΧžΧ©Χ” גל Χ™Χ™Χ’Χ•Χ₯",
698
+ 'Χ§ΧžΧ€Χ™Χ™ΧŸ Χ¨Χ‘-Χ’Χ¨Χ•Χ¦Χ™ ΧœΧžΧ’Χ’Χœ Χ‘Χ’"מ, 17699β‚ͺ, ΧžΧ–Χ•ΧžΧŸ']:
699
+ model_parse(t)
700
+ except Exception as e:
701
+ print(f"πŸ”Ž SELFTEST error: {e}", flush=True)
702
+
703
+ _probe_discord()
704
+ _startup_selftest()
705
+ # _start_discord_bot() # disabled until egress is confirmed (avoids crash spam in logs)
706
 
707
  if __name__ == "__main__":
708
  demo.launch(css=CSS)