Spaces:
Runtime error
Runtime error
Update backend/lens_core.py
Browse files224 unmodified lines22522622722822923023123223323423523623723823924024124224324424524624724824925025125225325422822923031 unmodified lines262263264292293294265266267113 unmodified lines3813823834143843853862 unmodified lines3893903914234243923933941076 unmodified lines1471147214731507147414751476224 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 lines data_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 lines system_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_parts
1076 unmodified lines json.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 "",backend/lens_core.py-34