Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
fix: LaTeX latex-style markers (rightarrow, times, etc) -> unicode at render time + system prompt prohibits LaTeX
Browse files- app.py +1 -0
- static/script.js +44 -0
app.py
CHANGED
|
@@ -36,6 +36,7 @@ SYSTEM_PROMPT = """๋น์ ์ ์ ๋จ๊ด์ฃผ ํตํฉํน๋ณ์๋ฏผ๊ณผ ํจ๊ปํ๋ AI
|
|
| 36 |
ใ์ถ๋ ฅ ํ์ โ ์ ๋ ๊ท์นใ
|
| 37 |
- thought / <think> / ๋ถ์ ๊ณผ์ / ์๊ธฐ ์ ๊ฒ ๋ชจ๋ ์ถ๋ ฅ ๊ธ์ง. **์ฒซ ์ค๋ถํฐ ๊ณง๋ฐ๋ก ์ ์คํ ๋ณธ๋ฌธ**์ผ๋ก ์์.
|
| 38 |
- ํ๊ตญ์ด ๋งํฌ๋ค์ด, ๊ฐ๊ฒฐํ๊ฒ. ํยท๋ฆฌ์คํธ ํ์ฉ.
|
|
|
|
| 39 |
|
| 40 |
ใ๋ต๋ณ ์์นใ
|
| 41 |
- ์ถ์ฒ ์๋ ์ฌ์ค๋ง, ์ถ์ธก์ '์ถ์ ' ํ๊ธฐ.
|
|
|
|
| 36 |
ใ์ถ๋ ฅ ํ์ โ ์ ๋ ๊ท์นใ
|
| 37 |
- thought / <think> / ๋ถ์ ๊ณผ์ / ์๊ธฐ ์ ๊ฒ ๋ชจ๋ ์ถ๋ ฅ ๊ธ์ง. **์ฒซ ์ค๋ถํฐ ๊ณง๋ฐ๋ก ์ ์คํ ๋ณธ๋ฌธ**์ผ๋ก ์์.
|
| 38 |
- ํ๊ตญ์ด ๋งํฌ๋ค์ด, ๊ฐ๊ฒฐํ๊ฒ. ํยท๋ฆฌ์คํธ ํ์ฉ.
|
| 39 |
+
- **LaTeX ์์ ํ๊ธฐ ๊ธ์ง** (`$\rightarrow$` ๊ฐ์ ํ๊ธฐ X). ํ์ดํยท๊ธฐํธ๋ ์ ๋์ฝ๋๋ก ์ง์ ์์ฑ: โ โ โ ร รท ยฑ โ โค โฅ โ โ % ยฐ (์: "๊ด์ฃผ โ ์ ๋จ")
|
| 40 |
|
| 41 |
ใ๋ต๋ณ ์์นใ
|
| 42 |
- ์ถ์ฒ ์๋ ์ฌ์ค๋ง, ์ถ์ธก์ '์ถ์ ' ํ๊ธฐ.
|
static/script.js
CHANGED
|
@@ -51,8 +51,52 @@ function fileSizeLabel(kb) {
|
|
| 51 |
return kb >= 1024 ? `${(kb/1024).toFixed(1)}MB` : `${kb}KB`;
|
| 52 |
}
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
function renderMarkdown(md) {
|
| 55 |
if (!md) return "";
|
|
|
|
| 56 |
if (window.marked && window.DOMPurify) {
|
| 57 |
return DOMPurify.sanitize(marked.parse(md));
|
| 58 |
}
|
|
|
|
| 51 |
return kb >= 1024 ? `${(kb/1024).toFixed(1)}MB` : `${kb}KB`;
|
| 52 |
}
|
| 53 |
|
| 54 |
+
// LaTeX ์์ โ ์ ๋์ฝ๋ (๋ชจ๋ธ์ด $\rightarrow$ ๊ฐ์ ํ๊ธฐ ์ถ๋ ฅ ์ ์ฌ๋์ด ์ฝ์ ์ ์๊ฒ)
|
| 55 |
+
const LATEX_MAP = {
|
| 56 |
+
"rightarrow": "โ", "to": "โ", "Rightarrow": "โ", "longrightarrow": "โ",
|
| 57 |
+
"leftarrow": "โ", "Leftarrow": "โ", "leftrightarrow": "โ", "Leftrightarrow": "โ",
|
| 58 |
+
"uparrow": "โ", "downarrow": "โ",
|
| 59 |
+
"times": "ร", "div": "รท", "pm": "ยฑ", "mp": "โ",
|
| 60 |
+
"cdot": "ยท", "bullet": "โข", "circ": "โ", "ast": "โ",
|
| 61 |
+
"approx": "โ", "sim": "โผ", "simeq": "โ", "cong": "โ
", "equiv": "โก",
|
| 62 |
+
"le": "โค", "leq": "โค", "ge": "โฅ", "geq": "โฅ", "neq": "โ ", "ne": "โ ",
|
| 63 |
+
"ll": "โช", "gg": "โซ", "subset": "โ", "supset": "โ", "subseteq": "โ", "supseteq": "โ",
|
| 64 |
+
"in": "โ", "notin": "โ", "cap": "โฉ", "cup": "โช", "emptyset": "โ
",
|
| 65 |
+
"infty": "โ", "partial": "โ", "nabla": "โ", "forall": "โ", "exists": "โ",
|
| 66 |
+
"sum": "โ", "prod": "โ", "int": "โซ", "sqrt": "โ",
|
| 67 |
+
"alpha": "ฮฑ", "beta": "ฮฒ", "gamma": "ฮณ", "delta": "ฮด", "epsilon": "ฮต", "varepsilon": "ฮต",
|
| 68 |
+
"zeta": "ฮถ", "eta": "ฮท", "theta": "ฮธ", "vartheta": "ฯ", "iota": "ฮน", "kappa": "ฮบ",
|
| 69 |
+
"lambda": "ฮป", "mu": "ฮผ", "nu": "ฮฝ", "xi": "ฮพ", "pi": "ฯ", "varpi": "ฯ",
|
| 70 |
+
"rho": "ฯ", "varrho": "ฯฑ", "sigma": "ฯ", "varsigma": "ฯ", "tau": "ฯ",
|
| 71 |
+
"upsilon": "ฯ
", "phi": "ฯ", "varphi": "ฯ", "chi": "ฯ", "psi": "ฯ", "omega": "ฯ",
|
| 72 |
+
"Gamma": "ฮ", "Delta": "ฮ", "Theta": "ฮ", "Lambda": "ฮ", "Xi": "ฮ", "Pi": "ฮ ",
|
| 73 |
+
"Sigma": "ฮฃ", "Upsilon": "ฮฅ", "Phi": "ฮฆ", "Psi": "ฮจ", "Omega": "ฮฉ",
|
| 74 |
+
"degree": "ยฐ", "prime": "โฒ", "dprime": "โณ",
|
| 75 |
+
"ldots": "โฆ", "cdots": "โฏ", "vdots": "โฎ", "ddots": "โฑ",
|
| 76 |
+
"%": "%", "&": "&", "_": "_", "#": "#",
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
function deLatex(text) {
|
| 80 |
+
if (!text || typeof text !== "string") return text;
|
| 81 |
+
// $\command$ โ unicode (๋๋ถ๋ถ์ ์ผ์ด์ค)
|
| 82 |
+
text = text.replace(/\$\\([a-zA-Z]+)\$/g, (m, cmd) => LATEX_MAP[cmd] || m);
|
| 83 |
+
// \(...\) inline math, \[...\] display math ๋ด๋ถ์์๋ ๋จ์ผ ๋ช
๋ น์ด ๋ณํ
|
| 84 |
+
text = text.replace(/\\\(\s*\\([a-zA-Z]+)\s*\\\)/g, (m, cmd) => LATEX_MAP[cmd] || m);
|
| 85 |
+
text = text.replace(/\\\[\s*\\([a-zA-Z]+)\s*\\\]/g, (m, cmd) => LATEX_MAP[cmd] || m);
|
| 86 |
+
// bare \command (math env ๋ฐ) โ ํ๊ตญ์ด ๋ณธ๋ฌธ์์ ๋น๋ฒ
|
| 87 |
+
text = text.replace(/\\([a-zA-Z]+)(?![a-zA-Z])/g, (m, cmd) => LATEX_MAP[cmd] || m);
|
| 88 |
+
// ๋จ์ $math$ โ math ๋ด๋ถ์ \rightarrow ๋ฑ ์ฒ๋ฆฌ (์์์ ์ฒ๋ฆฌ ๋ชป ํ ์ผ์ด์ค)
|
| 89 |
+
text = text.replace(/\$([^$\n]{1,30})\$/g, (m, inner) => {
|
| 90 |
+
const replaced = inner.replace(/\\([a-zA-Z]+)/g, (mm, cmd) => LATEX_MAP[cmd] || mm);
|
| 91 |
+
// ๋ณํ๋๊ณ LaTeX ํ์ ์์ผ๋ฉด $ ์ ๊ฑฐ
|
| 92 |
+
return /[\\{}]/.test(replaced) ? m : replaced;
|
| 93 |
+
});
|
| 94 |
+
return text;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
function renderMarkdown(md) {
|
| 98 |
if (!md) return "";
|
| 99 |
+
md = deLatex(md); // โญ LaTeX โ unicode ๋ณํ
|
| 100 |
if (window.marked && window.DOMPurify) {
|
| 101 |
return DOMPurify.sanitize(marked.parse(md));
|
| 102 |
}
|