LinJennyLin commited on
Commit
9a1d517
·
verified ·
1 Parent(s): f9ae913

Upload webapp/app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. webapp/app.py +119 -6
webapp/app.py CHANGED
@@ -93,6 +93,22 @@ line-height:1.65;max-width:64ch}ul.explain b{color:var(--ink)}
93
  .digest h2{font-size:19px;margin:28px 0 6px;letter-spacing:-.01em}
94
  .digest h2:first-child{margin-top:4px}
95
  .digest .lead{font-size:15px;color:var(--mut);margin:0 0 6px}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  @media (max-width:640px){
97
  .wrap{padding:20px 14px}
98
  .hero h1{font-size:26px}.hero p{font-size:16px}
@@ -177,7 +193,7 @@ def page(title: str, body: str, desc: str = "", path: str = "/") -> str:
177
  <script type="application/ld+json">{JSONLD}</script>
178
  <style>{CSS}</style></head><body><div class=wrap>
179
  <div class=nav><a class=brand href="/"><span>◆</span> {BRAND}</a>
180
- <div class=navlinks><a href="/">Score a wallet</a><a href="/digest">Daily digest</a></div></div>
181
  {body}
182
  <div class=foot>Built from Polymarket public data. <b>Flow intelligence, not financial
183
  advice.</b> Consistency scoring ≠ guaranteed profit. Past performance is not predictive.</div>
@@ -192,7 +208,7 @@ def robots():
192
 
193
  @app.route("/sitemap.xml")
194
  def sitemap():
195
- urls = ["/", "/digest"]
196
  items = "".join(f"<url><loc>{SITE_URL}{u}</loc></url>" for u in urls)
197
  xml = ('<?xml version="1.0" encoding="UTF-8"?>'
198
  '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
@@ -377,24 +393,27 @@ def digest():
377
  SUBSCRIBERS_DATASET = "sharpflowapp/subscribers"
378
 
379
 
380
- def _persist_subscriber(email: str, ts: str) -> None:
381
  """Durably record a signup in a private HF dataset so it survives the Space's
382
  ephemeral filesystem. Append-only (one file per signup) to dodge races.
383
- Best-effort: never let a storage hiccup break the signup UX."""
 
384
  token = os.environ.get("HF_TOKEN")
385
  if not token:
386
  return
387
  try:
388
  import hashlib
389
  import io
 
390
 
391
  from huggingface_hub import HfApi
392
 
 
393
  key = hashlib.sha1(email.encode()).hexdigest()[:12]
394
  api = HfApi(token=token)
395
  api.upload_file(
396
- path_or_fileobj=io.BytesIO(f"{email},{ts}\n".encode()),
397
- path_in_repo=f"emails/{ts[:10]}_{key}.csv",
398
  repo_id=SUBSCRIBERS_DATASET,
399
  repo_type="dataset",
400
  )
@@ -424,6 +443,100 @@ def subscribe():
424
  f"<p class='mut small' style='margin-top:10px'>Meanwhile, score any wallet above.</p></div>")
425
 
426
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
  if __name__ == "__main__":
428
  port = int(os.environ.get("PORT", "5055"))
429
  app.run(host="127.0.0.1", port=port, debug=False)
 
93
  .digest h2{font-size:19px;margin:28px 0 6px;letter-spacing:-.01em}
94
  .digest h2:first-child{margin-top:4px}
95
  .digest .lead{font-size:15px;color:var(--mut);margin:0 0 6px}
96
+ .tiers{display:grid;grid-template-columns:repeat(3,1fr);gap:16px;margin:18px 0}
97
+ .tier{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:22px;
98
+ display:flex;flex-direction:column}
99
+ .tier.feat{border-color:var(--acc);box-shadow:inset 0 0 0 1px var(--acc)}
100
+ .tier h3{margin:0;font-size:18px}
101
+ .tier .price{font-size:30px;font-weight:800;letter-spacing:-.02em;margin:8px 0 0}
102
+ .tier .price small{font-size:14px;font-weight:600;color:var(--mut)}
103
+ .tier .soon{display:inline-block;margin:8px 0 0;font-size:12px;font-weight:700;
104
+ color:var(--acc);background:#0c3138;padding:3px 10px;border-radius:999px}
105
+ .tier .live{display:inline-block;margin:8px 0 0;font-size:12px;font-weight:700;
106
+ color:var(--acc2);background:#0c2c28;padding:3px 10px;border-radius:999px}
107
+ .tier ul.feats{list-style:none;margin:14px 0 18px;padding:0;flex:1}
108
+ .tier ul.feats li{margin:9px 0;padding-left:22px;position:relative;color:var(--body);line-height:1.5}
109
+ .tier ul.feats li:before{content:'\\2713';position:absolute;left:0;color:var(--acc);font-weight:700}
110
+ .tier .cta{margin-top:auto}
111
+ @media (max-width:760px){.tiers{grid-template-columns:1fr}}
112
  @media (max-width:640px){
113
  .wrap{padding:20px 14px}
114
  .hero h1{font-size:26px}.hero p{font-size:16px}
 
193
  <script type="application/ld+json">{JSONLD}</script>
194
  <style>{CSS}</style></head><body><div class=wrap>
195
  <div class=nav><a class=brand href="/"><span>◆</span> {BRAND}</a>
196
+ <div class=navlinks><a href="/">Score a wallet</a><a href="/digest">Daily digest</a><a href="/pricing">Pricing</a></div></div>
197
  {body}
198
  <div class=foot>Built from Polymarket public data. <b>Flow intelligence, not financial
199
  advice.</b> Consistency scoring ≠ guaranteed profit. Past performance is not predictive.</div>
 
208
 
209
  @app.route("/sitemap.xml")
210
  def sitemap():
211
+ urls = ["/", "/digest", "/pricing"]
212
  items = "".join(f"<url><loc>{SITE_URL}{u}</loc></url>" for u in urls)
213
  xml = ('<?xml version="1.0" encoding="UTF-8"?>'
214
  '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
 
393
  SUBSCRIBERS_DATASET = "sharpflowapp/subscribers"
394
 
395
 
396
+ def _persist_subscriber(email: str, ts: str, kind: str = "digest") -> None:
397
  """Durably record a signup in a private HF dataset so it survives the Space's
398
  ephemeral filesystem. Append-only (one file per signup) to dodge races.
399
+ `kind` tags intent (digest signup vs. a paid-tier waitlist) so we can measure
400
+ willingness-to-pay. Best-effort: never let a storage hiccup break signup UX."""
401
  token = os.environ.get("HF_TOKEN")
402
  if not token:
403
  return
404
  try:
405
  import hashlib
406
  import io
407
+ import re as _re
408
 
409
  from huggingface_hub import HfApi
410
 
411
+ safe = _re.sub(r"[^a-z0-9_]+", "", kind.lower())[:24] or "digest"
412
  key = hashlib.sha1(email.encode()).hexdigest()[:12]
413
  api = HfApi(token=token)
414
  api.upload_file(
415
+ path_or_fileobj=io.BytesIO(f"{email},{ts},{safe}\n".encode()),
416
+ path_in_repo=f"emails/{ts[:10]}_{safe}_{key}.csv",
417
  repo_id=SUBSCRIBERS_DATASET,
418
  repo_type="dataset",
419
  )
 
443
  f"<p class='mut small' style='margin-top:10px'>Meanwhile, score any wallet above.</p></div>")
444
 
445
 
446
+ def _waitlist_form(tier: str, cta: str) -> str:
447
+ return (f"<form action='/waitlist' method=post class=cta>"
448
+ f"<input type=hidden name=tier value='{escape(tier, quote=True)}'>"
449
+ f"<input type=email name=email placeholder='you@email.com' required "
450
+ f"style='margin-bottom:10px'>"
451
+ f"<button type=submit style='width:100%'>{escape(cta)}</button></form>")
452
+
453
+
454
+ @app.route("/pricing")
455
+ def pricing():
456
+ free_cta = (f"<form action='/subscribe' method=post class=cta>"
457
+ f"<input type=email name=email placeholder='you@email.com' required "
458
+ f"style='margin-bottom:10px'>"
459
+ f"<button type=submit style='width:100%'>Get the free digest</button></form>")
460
+ tiers = f"""
461
+ <div class=tiers>
462
+ <div class=tier>
463
+ <h3>Free</h3>
464
+ <div class=price>$0</div>
465
+ <span class=live>Live now</span>
466
+ <ul class=feats>
467
+ <li>Daily smart-money digest</li>
468
+ <li>Top 5 consistent traders</li>
469
+ <li>Signal score on every move</li>
470
+ <li>Delivered ~24h delayed</li>
471
+ </ul>
472
+ {free_cta}
473
+ </div>
474
+ <div class="tier feat">
475
+ <h3>Pro</h3>
476
+ <div class=price>$19<small>/mo</small></div>
477
+ <span class=soon>Coming soon · join waitlist</span>
478
+ <ul class=feats>
479
+ <li><b>Real-time</b> Telegram alerts</li>
480
+ <li>All ~15 tracked traders (not just 5)</li>
481
+ <li>Your own custom wallet watchlist</li>
482
+ <li>No 24h delay</li>
483
+ </ul>
484
+ {_waitlist_form("pro", "Join the Pro waitlist")}
485
+ </div>
486
+ <div class=tier>
487
+ <h3>Trader</h3>
488
+ <div class=price>$49<small>/mo</small></div>
489
+ <span class=soon>Coming soon · join waitlist</span>
490
+ <ul class=feats>
491
+ <li>Everything in Pro</li>
492
+ <li>Webhook / API access</li>
493
+ <li>Faster polling</li>
494
+ <li>Backtest any trader on demand</li>
495
+ </ul>
496
+ {_waitlist_form("trader", "Join the Trader waitlist")}
497
+ </div>
498
+ </div>"""
499
+ body = f"""
500
+ <div class=hero><h1>Simple pricing</h1>
501
+ <p>Start free today. The paid tiers are in build — join a waitlist and you'll be first
502
+ in when real-time alerts go live, at this early-bird price.</p></div>
503
+ {tiers}
504
+ <div class=card><p class="mut small" style="margin:0">Flow intelligence, not financial
505
+ advice. Consistency scoring ≠ guaranteed profit. Waitlist just means we email you when
506
+ the tier opens — no charge, no card, unsubscribe anytime.</p></div>
507
+ """
508
+ return page(
509
+ f"{BRAND} — Pricing",
510
+ body,
511
+ desc="SharpFlow pricing: a free daily Polymarket smart-money digest, plus Pro "
512
+ "real-time alerts and a Trader API tier (coming soon — join the waitlist).",
513
+ path="/pricing")
514
+
515
+
516
+ @app.route("/waitlist", methods=["POST"])
517
+ def waitlist():
518
+ email = (request.form.get("email") or "").strip().lower()
519
+ tier = (request.form.get("tier") or "pro").strip().lower()
520
+ tier = tier if tier in ("pro", "trader") else "pro"
521
+ if "@" in email and "." in email:
522
+ ts = datetime.now(timezone.utc).isoformat()
523
+ _persist_subscriber(email, ts, kind=f"waitlist_{tier}")
524
+ msg = f"You're on the {tier.title()} waitlist."
525
+ sub = ("We'll email you the moment it opens — at the early-bird price, no card "
526
+ "needed now.")
527
+ else:
528
+ msg = "That email didn't look right — try again."
529
+ sub = "Head back to pricing and re-enter it."
530
+ return page(f"{BRAND} — waitlist",
531
+ f"<div class=hero><h1>{escape(msg)}</h1><p>{escape(sub)}</p></div>"
532
+ f"<div class=card><p class=mut style='margin:0 0 12px'>Meanwhile, the free "
533
+ f"digest is live today:</p>"
534
+ f"<form action='/subscribe' method=post class=row>"
535
+ f"<input type=email name=email placeholder='you@email.com' required>"
536
+ f"<button type=submit>Get the free digest</button></form></div>",
537
+ path="/pricing")
538
+
539
+
540
  if __name__ == "__main__":
541
  port = int(os.environ.get("PORT", "5055"))
542
  app.run(host="127.0.0.1", port=port, debug=False)