Spaces:
Running
Running
Upload webapp/app.py with huggingface_hub
Browse files- webapp/app.py +77 -17
webapp/app.py
CHANGED
|
@@ -38,45 +38,55 @@ BRAND = "SharpFlow"
|
|
| 38 |
TAGLINE = "The Polymarket smart-money tracker whale trackers miss."
|
| 39 |
|
| 40 |
CSS = """
|
| 41 |
-
:root{--bg:#
|
| 42 |
-
--warn:#d29922;--bad:#f85149;--line:#
|
| 43 |
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);
|
| 44 |
-
font:16px/1.55 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
.hero{margin:28px 0 10px}.hero h1{font-size:34px;line-height:1.15;margin:0 0 10px;letter-spacing:-.02em}
|
| 48 |
.hero p{color:var(--mut);font-size:18px;margin:0}
|
| 49 |
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:22px;margin:18px 0}
|
| 50 |
input[type=text],input[type=email]{width:100%;padding:13px 14px;border-radius:10px;
|
| 51 |
-
border:1px solid var(--line);background:
|
|
|
|
| 52 |
.row{display:flex;gap:10px;flex-wrap:wrap}.row>*{flex:1;min-width:180px}
|
| 53 |
-
button{background:var(--acc);color:#
|
| 54 |
-
font-weight:700;font-size:15px;cursor:pointer;
|
|
|
|
| 55 |
button.ghost{background:transparent;color:var(--ink);border:1px solid var(--line)}
|
| 56 |
.mut{color:var(--mut)}.small{font-size:13px}.mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
|
| 57 |
.tag{display:inline-block;padding:3px 10px;border-radius:999px;font-size:12px;font-weight:700}
|
| 58 |
-
.tag.watch{background:#
|
| 59 |
.tag.maker{background:#3a1414;color:var(--bad)}.tag.inconsistent{background:#2a2033;color:#c98bff}
|
| 60 |
-
.tag.thin,.tag.bad{background:#
|
| 61 |
.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-top:14px}
|
| 62 |
-
.metric{background:
|
| 63 |
.metric .k{color:var(--mut);font-size:12px}.metric .v{font-size:20px;font-weight:700;margin-top:2px}
|
| 64 |
-
.bar{height:8px;background:
|
| 65 |
-
.bar>i{display:block;height:100%;background:var(--acc)}
|
| 66 |
table{border-collapse:collapse;width:100%;font-size:14px}th,td{border-bottom:1px solid var(--line);
|
| 67 |
padding:8px 6px;text-align:left}th{color:var(--mut);font-weight:600}
|
|
|
|
| 68 |
.foot{color:var(--mut);font-size:12px;margin-top:26px;border-top:1px solid var(--line);padding-top:16px}
|
| 69 |
.pill{border:1px solid var(--line);border-radius:999px;padding:4px 12px;font-size:13px;color:var(--mut)}
|
| 70 |
.nav{display:flex;align-items:center;justify-content:space-between;gap:16px;
|
| 71 |
padding-bottom:12px;border-bottom:1px solid var(--line)}
|
| 72 |
.nav .brand{text-decoration:none;color:var(--ink)}
|
| 73 |
.navlinks{display:flex;gap:20px}.navlinks a{color:var(--mut);font-weight:600;font-size:14px}
|
| 74 |
-
.navlinks a:hover{color:var(--
|
| 75 |
.examples{margin-top:14px;display:flex;flex-wrap:wrap;gap:8px;align-items:center}
|
| 76 |
.exlabel{color:var(--mut);font-size:13px;margin-right:2px}
|
| 77 |
-
.chip{border:1px solid var(--line);background:
|
| 78 |
padding:6px 12px;font-size:13px;color:var(--ink)}
|
| 79 |
.chip:hover{border-color:var(--acc);color:var(--acc)}
|
|
|
|
|
|
|
| 80 |
"""
|
| 81 |
|
| 82 |
# Real wallets that showcase the product's judgement β one to follow, one too big
|
|
@@ -100,6 +110,25 @@ TAGLABEL = {"watch": "WORTH WATCHING", "whale": "MEGA-WHALE",
|
|
| 100 |
"thin": "TOO THIN", "bad": "INVALID"}
|
| 101 |
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
def page(title: str, body: str) -> str:
|
| 104 |
return f"""<!doctype html><html lang=en><head><meta charset=utf-8>
|
| 105 |
<meta name=viewport content="width=device-width,initial-scale=1">
|
|
@@ -255,7 +284,8 @@ def digest():
|
|
| 255 |
"<div class=hero><h1>No digest yet</h1>"
|
| 256 |
"<p class=mut>Run <code>python scripts/05_digest.py</code> to generate one.</p></div>")
|
| 257 |
md = files[-1].read_text(encoding="utf-8")
|
| 258 |
-
body =
|
|
|
|
| 259 |
f"<div class=card><b>Want it daily by email?</b>" \
|
| 260 |
f"<form action='/subscribe' method=post class=row style='margin-top:10px'>" \
|
| 261 |
f"<input type=email name=email placeholder='you@email.com' required>" \
|
|
@@ -263,17 +293,47 @@ def digest():
|
|
| 263 |
return page(f"{BRAND} β daily digest", body)
|
| 264 |
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
@app.route("/subscribe", methods=["POST"])
|
| 267 |
def subscribe():
|
| 268 |
email = (request.form.get("email") or "").strip().lower()
|
| 269 |
if "@" in email and "." in email:
|
|
|
|
| 270 |
path = cache_path(_cfg, "subscribers.csv")
|
| 271 |
new = not path.exists()
|
| 272 |
with path.open("a", newline="") as f:
|
| 273 |
w = csv.writer(f)
|
| 274 |
if new:
|
| 275 |
w.writerow(["email", "ts_utc"])
|
| 276 |
-
w.writerow([email,
|
|
|
|
| 277 |
msg = "You're in. First digest lands next run."
|
| 278 |
else:
|
| 279 |
msg = "That email didn't look right β try again."
|
|
|
|
| 38 |
TAGLINE = "The Polymarket smart-money tracker whale trackers miss."
|
| 39 |
|
| 40 |
CSS = """
|
| 41 |
+
:root{--bg:#0a0f14;--card:#111820;--ink:#e6edf3;--mut:#7d8da0;--acc:#22d3ee;
|
| 42 |
+
--acc2:#14b8a6;--warn:#d29922;--bad:#f85149;--line:#1c2531;--inset:#0c131b}
|
| 43 |
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);
|
| 44 |
+
font:16px/1.55 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;
|
| 45 |
+
background-image:radial-gradient(900px 500px at 80% -10%,rgba(34,211,238,.10),transparent 70%),
|
| 46 |
+
radial-gradient(700px 400px at -10% 10%,rgba(20,184,166,.08),transparent 70%)}
|
| 47 |
+
a{color:var(--acc);text-decoration:none}a:hover{text-decoration:underline}
|
| 48 |
+
.wrap{max-width:820px;margin:0 auto;padding:32px 20px}
|
| 49 |
+
.brand{font-weight:800;font-size:22px;letter-spacing:-.02em}
|
| 50 |
+
.brand span{background:linear-gradient(135deg,var(--acc),var(--acc2));
|
| 51 |
+
-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent}
|
| 52 |
.hero{margin:28px 0 10px}.hero h1{font-size:34px;line-height:1.15;margin:0 0 10px;letter-spacing:-.02em}
|
| 53 |
.hero p{color:var(--mut);font-size:18px;margin:0}
|
| 54 |
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:22px;margin:18px 0}
|
| 55 |
input[type=text],input[type=email]{width:100%;padding:13px 14px;border-radius:10px;
|
| 56 |
+
border:1px solid var(--line);background:var(--inset);color:var(--ink);font-size:15px}
|
| 57 |
+
input:focus{outline:none;border-color:var(--acc);box-shadow:0 0 0 3px rgba(34,211,238,.15)}
|
| 58 |
.row{display:flex;gap:10px;flex-wrap:wrap}.row>*{flex:1;min-width:180px}
|
| 59 |
+
button{background:linear-gradient(135deg,var(--acc),var(--acc2));color:#04121a;border:0;
|
| 60 |
+
border-radius:10px;padding:13px 18px;font-weight:700;font-size:15px;cursor:pointer;
|
| 61 |
+
white-space:nowrap;flex:0 0 auto}button:hover{filter:brightness(1.08)}
|
| 62 |
button.ghost{background:transparent;color:var(--ink);border:1px solid var(--line)}
|
| 63 |
.mut{color:var(--mut)}.small{font-size:13px}.mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
|
| 64 |
.tag{display:inline-block;padding:3px 10px;border-radius:999px;font-size:12px;font-weight:700}
|
| 65 |
+
.tag.watch{background:#0c3138;color:var(--acc)}.tag.whale{background:#3a2f10;color:var(--warn)}
|
| 66 |
.tag.maker{background:#3a1414;color:var(--bad)}.tag.inconsistent{background:#2a2033;color:#c98bff}
|
| 67 |
+
.tag.thin,.tag.bad{background:#1a222c;color:var(--mut)}
|
| 68 |
.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin-top:14px}
|
| 69 |
+
.metric{background:var(--inset);border:1px solid var(--line);border-radius:10px;padding:12px}
|
| 70 |
.metric .k{color:var(--mut);font-size:12px}.metric .v{font-size:20px;font-weight:700;margin-top:2px}
|
| 71 |
+
.bar{height:8px;background:var(--inset);border-radius:6px;overflow:hidden;margin-top:6px}
|
| 72 |
+
.bar>i{display:block;height:100%;background:linear-gradient(90deg,var(--acc),var(--acc2))}
|
| 73 |
table{border-collapse:collapse;width:100%;font-size:14px}th,td{border-bottom:1px solid var(--line);
|
| 74 |
padding:8px 6px;text-align:left}th{color:var(--mut);font-weight:600}
|
| 75 |
+
tbody tr:hover{background:rgba(34,211,238,.04)}
|
| 76 |
.foot{color:var(--mut);font-size:12px;margin-top:26px;border-top:1px solid var(--line);padding-top:16px}
|
| 77 |
.pill{border:1px solid var(--line);border-radius:999px;padding:4px 12px;font-size:13px;color:var(--mut)}
|
| 78 |
.nav{display:flex;align-items:center;justify-content:space-between;gap:16px;
|
| 79 |
padding-bottom:12px;border-bottom:1px solid var(--line)}
|
| 80 |
.nav .brand{text-decoration:none;color:var(--ink)}
|
| 81 |
.navlinks{display:flex;gap:20px}.navlinks a{color:var(--mut);font-weight:600;font-size:14px}
|
| 82 |
+
.navlinks a:hover{color:var(--acc);text-decoration:none}
|
| 83 |
.examples{margin-top:14px;display:flex;flex-wrap:wrap;gap:8px;align-items:center}
|
| 84 |
.exlabel{color:var(--mut);font-size:13px;margin-right:2px}
|
| 85 |
+
.chip{border:1px solid var(--line);background:var(--inset);border-radius:999px;
|
| 86 |
padding:6px 12px;font-size:13px;color:var(--ink)}
|
| 87 |
.chip:hover{border-color:var(--acc);color:var(--acc)}
|
| 88 |
+
ul.explain{margin:8px 0 0;padding-left:20px}ul.explain li{margin:6px 0;color:var(--mut)}
|
| 89 |
+
ul.explain b{color:var(--ink)}
|
| 90 |
"""
|
| 91 |
|
| 92 |
# Real wallets that showcase the product's judgement β one to follow, one too big
|
|
|
|
| 110 |
"thin": "TOO THIN", "bad": "INVALID"}
|
| 111 |
|
| 112 |
|
| 113 |
+
DIGEST_EXPLAINER = """
|
| 114 |
+
<div class=hero><h1>Daily smart-money digest</h1>
|
| 115 |
+
<p>The mid-size Polymarket traders who win consistently β and the boldest bets they
|
| 116 |
+
just made.</p></div>
|
| 117 |
+
<div class=card><h3 style="margin:0 0 8px">What am I looking at?</h3>
|
| 118 |
+
<ul class=explain>
|
| 119 |
+
<li><b>Top moves right now</b> β the highest-signal bets our tracked traders placed
|
| 120 |
+
recently. <b>Signal βββββ</b> blends the trader's track record with how big this bet
|
| 121 |
+
is <i>for them</i> (conviction) and how far the price is from a coin-flip (edge).
|
| 122 |
+
More dots = stronger.</li>
|
| 123 |
+
<li><b>The traders we're tracking</b> β the vetted wallets themselves. These are
|
| 124 |
+
<b>mid-size traders whale trackers skip</b> (not $10k+ whales, not market-makers),
|
| 125 |
+
scored on consistency, repeatability and copyability β <i>not</i> size. Tap any
|
| 126 |
+
address to verify it live on Polymarket.</li>
|
| 127 |
+
</ul>
|
| 128 |
+
<p class="mut small" style="margin:10px 0 0">Flow intelligence, not financial advice.</p></div>
|
| 129 |
+
"""
|
| 130 |
+
|
| 131 |
+
|
| 132 |
def page(title: str, body: str) -> str:
|
| 133 |
return f"""<!doctype html><html lang=en><head><meta charset=utf-8>
|
| 134 |
<meta name=viewport content="width=device-width,initial-scale=1">
|
|
|
|
| 284 |
"<div class=hero><h1>No digest yet</h1>"
|
| 285 |
"<p class=mut>Run <code>python scripts/05_digest.py</code> to generate one.</p></div>")
|
| 286 |
md = files[-1].read_text(encoding="utf-8")
|
| 287 |
+
body = DIGEST_EXPLAINER \
|
| 288 |
+
+ f"<div class=card>{_md_to_html(md)}</div>" \
|
| 289 |
f"<div class=card><b>Want it daily by email?</b>" \
|
| 290 |
f"<form action='/subscribe' method=post class=row style='margin-top:10px'>" \
|
| 291 |
f"<input type=email name=email placeholder='you@email.com' required>" \
|
|
|
|
| 293 |
return page(f"{BRAND} β daily digest", body)
|
| 294 |
|
| 295 |
|
| 296 |
+
SUBSCRIBERS_DATASET = "sharpflowapp/subscribers"
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def _persist_subscriber(email: str, ts: str) -> None:
|
| 300 |
+
"""Durably record a signup in a private HF dataset so it survives the Space's
|
| 301 |
+
ephemeral filesystem. Append-only (one file per signup) to dodge races.
|
| 302 |
+
Best-effort: never let a storage hiccup break the signup UX."""
|
| 303 |
+
token = os.environ.get("HF_TOKEN")
|
| 304 |
+
if not token:
|
| 305 |
+
return
|
| 306 |
+
try:
|
| 307 |
+
import hashlib
|
| 308 |
+
import io
|
| 309 |
+
|
| 310 |
+
from huggingface_hub import HfApi
|
| 311 |
+
|
| 312 |
+
key = hashlib.sha1(email.encode()).hexdigest()[:12]
|
| 313 |
+
api = HfApi(token=token)
|
| 314 |
+
api.upload_file(
|
| 315 |
+
path_or_fileobj=io.BytesIO(f"{email},{ts}\n".encode()),
|
| 316 |
+
path_in_repo=f"emails/{ts[:10]}_{key}.csv",
|
| 317 |
+
repo_id=SUBSCRIBERS_DATASET,
|
| 318 |
+
repo_type="dataset",
|
| 319 |
+
)
|
| 320 |
+
except Exception:
|
| 321 |
+
pass
|
| 322 |
+
|
| 323 |
+
|
| 324 |
@app.route("/subscribe", methods=["POST"])
|
| 325 |
def subscribe():
|
| 326 |
email = (request.form.get("email") or "").strip().lower()
|
| 327 |
if "@" in email and "." in email:
|
| 328 |
+
ts = datetime.now(timezone.utc).isoformat()
|
| 329 |
path = cache_path(_cfg, "subscribers.csv")
|
| 330 |
new = not path.exists()
|
| 331 |
with path.open("a", newline="") as f:
|
| 332 |
w = csv.writer(f)
|
| 333 |
if new:
|
| 334 |
w.writerow(["email", "ts_utc"])
|
| 335 |
+
w.writerow([email, ts])
|
| 336 |
+
_persist_subscriber(email, ts)
|
| 337 |
msg = "You're in. First digest lands next run."
|
| 338 |
else:
|
| 339 |
msg = "That email didn't look right β try again."
|