polygrapher / README.md
dhruv575
README fix
5c87af0
metadata
title: Polygrapher
emoji: 🦝
colorFrom: red
colorTo: purple
sdk: docker
sdk_version: 0.0.1
app_file: app/main.py
pinned: false

Polygrapher Backend

This directory hosts the Hugging Face Space for generating the Polygraph newsletter. It wraps the existing email3.py script with a FastAPI service and adds tooling to validate and swap HTML templates without needing local scripts.

API Surface

Method Path Description
GET / Basic service readiness ping for Hugging Face Spaces
GET /health Simple readiness signal for monitors
GET /api/menu Builds the selection menu; placeholders are used if upstream APIs fail
POST /api/generate Runs email3.py with posted selections/commentary and returns the HTML + filename
POST /api/templates/validate Ensures a template zip includes index.html, fonts/, images/
POST /api/templates/install Backs up the current bundle, installs the new one, injects the shared header
GET /api/templates/active Lists files inside the active template directory (fonts, images, index)
POST /api/templates/header Updates the global header.png and mirrors it into the active template
POST /api/templates/upload/font Upload a single font file into the active template
POST /api/templates/upload/image Upload a single image file into the active template
POST /api/templates/upload/index Replace the active index.html file
POST /api/templates/templateify Calls GPT-5.1 to convert raw HTML into a tokenized template

Environment

Existing values in .env cover external services. Additional knobs:

Variable Purpose Default
POLYGRAPH_DEFAULT_NUM_ITEMS Default items per section 10
POLYGRAPH_SKIP_DUB Skip Dub tracking link creation false
POLYGRAPH_TEMPLATE_DIR Active template directory polygraph(email)/polygraph(email)
POLYGRAPH_TEMPLATE_ARCHIVE Location for zipped backups template_archive
POLYGRAPH_HEADER_PATH Header asset read by email3.py header.png
POLYGRAPH_HEADER_LINK URL used for the hero image https://polymarket.com
SUPABASE_URL / SUPABASE_SERVICE_KEY Storage bucket connection required
OPENAI_API_KEY Used by the templateify endpoint required

Implementation Notes

  • email3.py falls back to hardcoded whale-move/comment examples if ClickHouse or the Gamma API returns errors so the workflow remains functional without creds.
  • The hero starts directly with the provided header.png at 500px width (no date strip or secondary Poly logo). All major boxes are wrapped in anchors to make the sections fully clickable.
  • TemplateManager hydrates the active template from Supabase storage on startup, archives previous bundles as previous_template_<unix>.zip, and automatically copies the latest header.png into the template�s images/ folder when new bundles are uploaded.
  • /api/templates/header lets the frontend upload a new hero image; the file is saved to both the root (header.png) and the active template directory so future swaps reuse it.
  • /api/templates/templateify asks GPT-5.1 to rewrite the current HTML with templating tokens for every data slot email3.py populates (intro, top stories, each market section, comments, etc.) while preserving the existing styles.