Update backend/lens_core.py
Browse files224 unmodified lines22522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625731 unmodified lines289290291292293294295296297113 unmodified lines4114124134144154164172 unmodified lines4204214224234244254264271076 unmodified lines1504150515061507150815091510224 unmodified lines),}AI_PROMPT_USER_BY_LANG = {"th": """เป้าหมายภาษา: ไทยแปลข้อความ OCR ในมังงะเป็นภาษาไทยธรรมชาติแบบบทสนทนาคงน้ำเสียง/อารมณ์ให้เหมาะกับบริบทสั้น กระชับ อ่านลื่น ห้ามใส่คำอธิบายหรือบรรยายเพิ่มคงชื่อเฉพาะ/ศัพท์เฉพาะให้สม่ำเสมอ และส่งออกเป็นข้อความไทยเท่านั้น""".strip(),"en": """Style preferences:- Keep English dialogue concise and conversational.- Keep lines short for speech bubbles.- Keep names and recurring terms consistent.- Keep SFX short; avoid very long repeated characters.""".strip(),"ja": """Style preferences:- Keep Japanese dialogue concise and natural for manga.- Keep lines short for speech bubbles.- Keep names and recurring terms consistent.- Keep SFX short; avoid very long repeated characters.""".strip(),"default": """Style preferences:- Keep dialogue concise, spoken, and faithful to tone.- Keep lines short for speech bubbles.- Keep names and recurring terms consistent.- Keep SFX short; avoid very long repeated characters.""".strip(),}AI_PROMPT_RESPONSE_CONTRACT_JSON = ("Return ONLY valid JSON (no markdown, no extra text).\n"31 unmodified lines_TP_HTML_EPS_PX = 0.0ZWSP = "\u200b"def ai_prompt_user_default(lang: str, model: str = "auto") -> str:l = _normalize_lang(lang)return (AI_PROMPT_USER_BY_LANG.get(l) or AI_PROMPT_USER_BY_LANG.get("default") or "").strip()def _active_ai_contract() -> str:return AI_PROMPT_RESPONSE_CONTRACT_JSON if DO_AI_JSON else AI_PROMPT_RESPONSE_CONTRACT_TEXT113 unmodified linesdata_text = data_template.format(input_json=input_json)style = AI_LANG_STYLE.get(lang) or AI_LANG_STYLE.get("default") or ""editable = (ai_prompt_user_default(lang) or "").strip()system_parts = [AI_PROMPT_SYSTEM_BASE]if style:2 unmodified linessystem_text = "\n\n".join([p for p in system_parts if p])user_parts = []if editable:user_parts.append(editable)user_parts.append(data_text)return system_text, user_parts1076 unmodified linesjson.dumps({"sys": AI_PROMPT_SYSTEM_BASE,"edit": AI_PROMPT_USER_BY_LANG,"contract": _active_ai_contract(),"data": _active_ai_data_template(),"style": AI_LANG_STYLE.get(lang) or AI_LANG_STYLE.get("default") or "",224 unmodified lines22522622722822923031 unmodified lines262263264265266267113 unmodified lines3813823833843853862 unmodified lines3893903913923933941076 unmodified lines147114721473147414751476224 unmodified lines),}AI_PROMPT_RESPONSE_CONTRACT_JSON = ("Return ONLY valid JSON (no markdown, no extra text).\n"31 unmodified lines_TP_HTML_EPS_PX = 0.0ZWSP = "\u200b"def _active_ai_contract() -> str:return AI_PROMPT_RESPONSE_CONTRACT_JSON if DO_AI_JSON else AI_PROMPT_RESPONSE_CONTRACT_TEXT113 unmodified linesdata_text = data_template.format(input_json=input_json)style = AI_LANG_STYLE.get(lang) or AI_LANG_STYLE.get("default") or ""system_parts = [AI_PROMPT_SYSTEM_BASE]if style:2 unmodified linessystem_text = "\n\n".join([p for p in system_parts if p])user_parts = []user_parts.append(data_text)return system_text, user_parts1076 unmodified linesjson.dumps({"sys": AI_PROMPT_SYSTEM_BASE,"contract": _active_ai_contract(),"data": _active_ai_data_template(),"style": AI_LANG_STYLE.get(lang) or AI_LANG_STYLE.get("default") or "",
backend/lens_core.py-34