Spaces:
Running
Running
Upload webapp/app.py with huggingface_hub
Browse files- webapp/app.py +30 -5
webapp/app.py
CHANGED
|
@@ -160,8 +160,9 @@ try a real trader below.</p></div>
|
|
| 160 |
tag = r.verdict_tag or "thin"
|
| 161 |
pct = int(round(r.trader_score * 100))
|
| 162 |
short = f"{r.wallet[:8]}…{r.wallet[-6:]}"
|
|
|
|
| 163 |
body = f"""
|
| 164 |
-
<div class=hero><
|
| 165 |
<h1 style="margin:6px 0">Trader score: {r.trader_score:.2f}
|
| 166 |
<span class="tag {tag}">{TAGLABEL.get(tag,tag.upper())}</span></h1>
|
| 167 |
<div class=bar style="max-width:360px"><i style="width:{pct}%"></i></div>
|
|
@@ -181,6 +182,31 @@ try a real trader below.</p></div>
|
|
| 181 |
|
| 182 |
|
| 183 |
_TABLE_RE = re.compile(r"^\|(.+)\|\s*$")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
|
| 186 |
def _md_to_html(md: str) -> str:
|
|
@@ -194,8 +220,8 @@ def _md_to_html(md: str) -> str:
|
|
| 194 |
cells = [[c.strip() for c in r.strip("|").split("|")] for r in rows]
|
| 195 |
body = cells[2:] if len(cells) > 1 and set("".join(cells[1])) <= set("-: ") else cells[1:]
|
| 196 |
head = cells[0]
|
| 197 |
-
h = "".join(f"<th>{
|
| 198 |
-
b = "".join("<tr>" + "".join(f"<td>{
|
| 199 |
out.append(f"<table><thead><tr>{h}</tr></thead><tbody>{b}</tbody></table>")
|
| 200 |
rows.clear()
|
| 201 |
|
|
@@ -216,8 +242,7 @@ def _md_to_html(md: str) -> str:
|
|
| 216 |
elif s == "---":
|
| 217 |
out.append("<hr style='border:0;border-top:1px solid var(--line)'>")
|
| 218 |
else:
|
| 219 |
-
|
| 220 |
-
out.append(f"<p class=mut>{escape(s)}</p>")
|
| 221 |
flush_table()
|
| 222 |
return "\n".join(out)
|
| 223 |
|
|
|
|
| 160 |
tag = r.verdict_tag or "thin"
|
| 161 |
pct = int(round(r.trader_score * 100))
|
| 162 |
short = f"{r.wallet[:8]}…{r.wallet[-6:]}"
|
| 163 |
+
prof = f"https://polymarket.com/profile/{r.wallet}"
|
| 164 |
body = f"""
|
| 165 |
+
<div class=hero><a class="pill mono" href="{escape(prof, quote=True)}" target=_blank rel=noopener title="Verify on Polymarket" style="display:inline-block;margin-bottom:10px;text-decoration:none">{escape(r.wallet)} ↗</a>
|
| 166 |
<h1 style="margin:6px 0">Trader score: {r.trader_score:.2f}
|
| 167 |
<span class="tag {tag}">{TAGLABEL.get(tag,tag.upper())}</span></h1>
|
| 168 |
<div class=bar style="max-width:360px"><i style="width:{pct}%"></i></div>
|
|
|
|
| 182 |
|
| 183 |
|
| 184 |
_TABLE_RE = re.compile(r"^\|(.+)\|\s*$")
|
| 185 |
+
_LINK_RE = re.compile(r"\[([^\]]+)\]\((https?://[^\s)]+)\)")
|
| 186 |
+
_BOLD_RE = re.compile(r"\*\*([^*]+)\*\*")
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def _inline(text: str) -> str:
|
| 190 |
+
"""Escape text, then render inline **bold** and [label](https url) links.
|
| 191 |
+
Links are restricted to http/https so escaped content stays injection-safe."""
|
| 192 |
+
out, i = [], 0
|
| 193 |
+
for mm in _LINK_RE.finditer(text):
|
| 194 |
+
out.append(_bold(text[i:mm.start()]))
|
| 195 |
+
label, url = mm.group(1), mm.group(2)
|
| 196 |
+
out.append(f'<a href="{escape(url, quote=True)}" target=_blank rel=noopener>{escape(label)}</a>')
|
| 197 |
+
i = mm.end()
|
| 198 |
+
out.append(_bold(text[i:]))
|
| 199 |
+
return "".join(out)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def _bold(text: str) -> str:
|
| 203 |
+
parts, i = [], 0
|
| 204 |
+
for mm in _BOLD_RE.finditer(text):
|
| 205 |
+
parts.append(escape(text[i:mm.start()]))
|
| 206 |
+
parts.append(f"<b>{escape(mm.group(1))}</b>")
|
| 207 |
+
i = mm.end()
|
| 208 |
+
parts.append(escape(text[i:]))
|
| 209 |
+
return "".join(parts)
|
| 210 |
|
| 211 |
|
| 212 |
def _md_to_html(md: str) -> str:
|
|
|
|
| 220 |
cells = [[c.strip() for c in r.strip("|").split("|")] for r in rows]
|
| 221 |
body = cells[2:] if len(cells) > 1 and set("".join(cells[1])) <= set("-: ") else cells[1:]
|
| 222 |
head = cells[0]
|
| 223 |
+
h = "".join(f"<th>{_inline(c)}</th>" for c in head)
|
| 224 |
+
b = "".join("<tr>" + "".join(f"<td>{_inline(c)}</td>" for c in r) + "</tr>" for r in body)
|
| 225 |
out.append(f"<table><thead><tr>{h}</tr></thead><tbody>{b}</tbody></table>")
|
| 226 |
rows.clear()
|
| 227 |
|
|
|
|
| 242 |
elif s == "---":
|
| 243 |
out.append("<hr style='border:0;border-top:1px solid var(--line)'>")
|
| 244 |
else:
|
| 245 |
+
out.append(f"<p class=mut>{_inline(s.replace('_', ''))}</p>")
|
|
|
|
| 246 |
flush_table()
|
| 247 |
return "\n".join(out)
|
| 248 |
|