from __future__ import annotations import base64 from pathlib import Path import html import gradio as gr ROOT = Path(__file__).resolve().parent REPO = "https://huggingface.co/spaces/zcahjl3/figmirror-code-aug10" CSS = """ """ def image_data(path: Path) -> str: data = base64.b64encode(path.read_bytes()).decode("ascii") return f"data:image/png;base64,{data}" def rel_url(slug: str, filename: str) -> str: return f"{REPO}/resolve/main/{slug}/{filename}" def build_html() -> str: cases = sorted(p for p in ROOT.iterdir() if p.is_dir() and (p / "comparison.png").exists()) cards = [] for case in cases: slug = case.name parts = slug.split("_", 2) chart_type = html.escape(parts[1] if len(parts) > 1 else slug) label = html.escape(parts[2] if len(parts) > 2 else slug) img = image_data(case / "comparison.png") cards.append(f"""

{chart_type} · {label}

Original code render versus data-preserving FigMirror code augmentation

Both sides are generated from code. Left: unchanged original.py. Right: augmented.py, preserving the same data and chart topology while improving figure aesthetics.

""") return CSS + f"""

FigMirror Data-Preserving Code Augmentation - 10 Cases

Each case compares two code-generated images. The right-hand figure is not a new task: it keeps the original data, labels, chart type/topology, and analytical relation, then applies FigMirror presentation improvements.

{''.join(cards)}
""" with gr.Blocks(title="FigMirror Code Augmentation") as demo: gr.HTML(build_html()) if __name__ == "__main__": demo.launch()