Spaces:
Running on Zero
Running on Zero
File size: 9,665 Bytes
5c78c83 13fe947 5c78c83 9eec184 5c78c83 13fe947 5c78c83 9eec184 5c78c83 aa61566 5c78c83 aa61566 5c78c83 aa61566 5c78c83 18b8de2 5c78c83 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | from __future__ import annotations
from typing import Any
from hackathon_advisor._text import clean as _clean, list_of_dicts as _list_of_dicts, utc_now
SPACE_URL = "https://huggingface.co/spaces/build-small-hackathon/hackathon-advisor"
LIVE_URL = "https://build-small-hackathon-hackathon-advisor.hf.space"
GITHUB_URL = "https://github.com/JacobLinCool/hackathon-advisor"
def build_submission_packet_markdown(
session: dict[str, Any],
metadata: dict[str, Any],
ledger: dict[str, Any],
) -> str:
ideas = _list_of_dicts(session.get("ideas"))
trace = _list_of_dicts(session.get("trace"))
goals = [str(goal) for goal in session.get("goals") or []]
last_plan = [str(step) for step in session.get("last_plan") or []]
current = _current_idea(session, ideas)
score = current.get("score") if isinstance(current.get("score"), dict) else {}
verdict = _clean(score.get("verdict")) if score else "DRAFT"
overall = _clean(score.get("overall")) if score else "0.0"
title = _clean(current.get("title") or "Unwritten Page")
lines = [
"# Hackathon Advisor Submission Packet",
"",
f"Generated: {utc_now()}",
"",
"## Links",
"",
f"- Live Space: {LIVE_URL}",
f"- Hugging Face repository: {SPACE_URL}",
f"- GitHub repository: {GITHUB_URL}",
"",
"## Snapshot",
"",
f"- Project snapshot: {_clean(metadata.get('snapshot_generated_at'))}",
f"- Project count: {_clean(metadata.get('project_count', 'unknown'))}",
f"- Index: {_clean(metadata.get('index_algorithm'))} at {_clean(metadata.get('index_generated_at'))}",
f"- Digest: `{_clean(metadata.get('snapshot_digest'))}`",
"",
"## Current Demo Page",
"",
f"- Title: {title}",
f"- Verdict: {verdict} {overall}/10",
f"- Goals: {', '.join(goals) if goals else 'No specific goals'}",
f"- Pitch: {_clean(current.get('pitch')) or 'No pitch recorded.'}",
"",
]
lines.extend(_demo_script(title, verdict, overall, current, trace, last_plan))
lines.extend(_artifact_checklist(trace, ideas, session))
lines.extend(_prize_evidence(ledger))
lines.extend(_model_budget(ledger))
lines.extend(_session_summary(ideas, trace, last_plan))
lines.extend(_social_post(title, verdict, ledger))
lines.extend(_open_gaps(ledger))
return "\n".join(lines).rstrip() + "\n"
def _demo_script(
title: str,
verdict: str,
overall: str,
idea: dict[str, Any],
trace: list[dict[str, Any]],
last_plan: list[str],
) -> list[str]:
echoes = _echoes(idea)
first_echo = echoes[0] if echoes else {}
project = first_echo.get("project") if isinstance(first_echo.get("project"), dict) else {}
echo_title = _clean(project.get("title") or project.get("id") or "a cited Space")
page = _clean(first_echo.get("page_number")) or "?"
plan_step = _clean(last_plan[0]) if last_plan else "Press Plan to show the build path."
turn_count = len(trace)
return [
"## Demo Script",
"",
"| Time | Beat | Proof |",
"| --- | --- | --- |",
"| 0:00 | Open The Unwritten Almanac and point to the local snapshot count. | Snapshot metadata is visible in the provenance line. |",
f"| 0:10 | Type the project instinct for `{title}`. | Streaming response starts, then the seal reads {verdict} at {overall}/10. |",
f"| 0:30 | Show the nearest echo. | Page {page}: {echo_title}. |",
f"| 0:45 | Press Gap or Plan to move from diagnosis to build path. | {plan_step} |",
f"| 1:05 | Export builder-facing artifacts. | Notes, Chapter, and PNG are available in the app after {turn_count} recorded turns. |",
"| 1:20 | Check submission evidence outside the main UI. | `/api/prize-ledger` separates ready and planned badge states; `/api/demo-bundle.zip` contains JSONL, LoRA, and packet exports. |",
"",
]
def _artifact_checklist(trace: list[dict[str, Any]], ideas: list[dict[str, Any]], session: dict[str, Any]) -> list[str]:
has_trace = bool(trace)
has_ideas = bool(ideas)
has_artifact = isinstance(session.get("last_artifact"), dict) and bool(session["last_artifact"].get("title"))
rows = [
("Tool trace JSONL", has_trace, "trace_artifact"),
("Field Notes markdown", has_trace, "field_notes"),
("Almanac chapter markdown", has_ideas, "chapter"),
("MiniCPM5 LoRA SFT JSONL", has_trace, "lora_dataset"),
("Submission packet markdown", True, "submission_packet"),
("Fate page PNG", has_artifact, "/api/artifact.png"),
]
lines = ["## Artifact Checklist", "", "| Artifact | Status | Source |", "| --- | --- | --- |"]
for name, ready, source in rows:
lines.append(f"| {name} | {'ready' if ready else 'needs session'} | {source} |")
lines.append("")
return lines
def _prize_evidence(ledger: dict[str, Any]) -> list[str]:
lines = ["## Prize Evidence", "", "| Prize path | Status | Evidence |", "| --- | --- | --- |"]
for badge in _list_of_dicts(ledger.get("badges")):
lines.append(
"| "
+ " | ".join(
[
_clean(badge.get("name")),
_clean(badge.get("status")),
_clean(badge.get("evidence")),
]
)
+ " |"
)
lines.append("")
return lines
def _model_budget(ledger: dict[str, Any]) -> list[str]:
total = _clean(ledger.get("total_params_b"))
limit = _clean(ledger.get("tiny_titan_limit_b"))
eligible = "yes" if ledger.get("tiny_titan_eligible") else "no"
lines = [
"## Model Budget",
"",
f"- Total documented stack: {total}B params",
f"- Tiny Titan limit: {limit}B params",
f"- Tiny Titan eligible: {eligible}",
"",
"| Role | Model | Params | Status | Runtime |",
"| --- | --- | --- | --- | --- |",
]
for item in _list_of_dicts(ledger.get("model_stack")):
lines.append(
"| "
+ " | ".join(
[
_clean(item.get("role")),
_clean(item.get("model")),
f"{_clean(item.get('params_b'))}B",
_clean(item.get("status")),
_clean(item.get("runtime")),
]
)
+ " |"
)
lines.append("")
return lines
def _session_summary(ideas: list[dict[str, Any]], trace: list[dict[str, Any]], last_plan: list[str]) -> list[str]:
lines = ["## Session Evidence", ""]
if ideas:
lines.extend(["### Idea Board", ""])
for index, idea in enumerate(ideas[-4:], start=max(1, len(ideas) - 3)):
score = idea.get("score") if isinstance(idea.get("score"), dict) else {}
verdict = _clean(score.get("verdict")) if score else "DRAFT"
overall = _clean(score.get("overall")) if score else "0.0"
lines.append(f"- {index}. {_clean(idea.get('title'))}: {verdict} {overall}/10")
else:
lines.append("- No ideas recorded yet.")
lines.extend(["", "### Latest Build Plan", ""])
if last_plan:
for index, step in enumerate(last_plan, start=1):
lines.append(f"{index}. {_clean(step)}")
else:
lines.append("No build plan recorded yet.")
lines.extend(["", "### Tool Trace", ""])
if trace:
for index, event in enumerate(trace[-5:], start=max(1, len(trace) - 4)):
tools = " -> ".join(
_clean(tool.get("name")) for tool in _list_of_dicts(event.get("tools")) if tool.get("name")
)
lines.append(f"- Turn {index}: {_clean(event.get('input'))} [{tools or 'reply'}]")
else:
lines.append("- No tool trace recorded yet.")
lines.append("")
return lines
def _social_post(title: str, verdict: str, ledger: dict[str, Any]) -> list[str]:
ready = sum(1 for badge in _list_of_dicts(ledger.get("badges")) if badge.get("status") == "ready")
total = len(_list_of_dicts(ledger.get("badges")))
return [
"## Social Post Draft",
"",
(
"I built Hackathon Advisor, a small-model originality coach for Build Small. "
f"The Unwritten Almanac checks `{title}` against a local snapshot of real Spaces, cites overlap, "
f"and exports the evidence trail. Latest seal: {verdict}. Prize ledger: {ready}/{total} ready."
),
"",
f"Live: {LIVE_URL}",
"",
]
def _open_gaps(ledger: dict[str, Any]) -> list[str]:
pending = [
badge
for badge in _list_of_dicts(ledger.get("badges"))
if badge.get("status") not in {"ready", "eligible"}
]
lines = ["## Open Gaps", ""]
if pending:
for badge in pending:
lines.append(f"- {_clean(badge.get('name'))}: {_clean(badge.get('status'))} - {_clean(badge.get('evidence'))}")
else:
lines.append("- No non-ready badge states reported by the current ledger.")
lines.append("")
return lines
def _current_idea(session: dict[str, Any], ideas: list[dict[str, Any]]) -> dict[str, Any]:
current_id = _clean(session.get("current_idea_id"))
if current_id:
for idea in ideas:
if _clean(idea.get("id")) == current_id:
return idea
if ideas:
return ideas[-1]
return {}
def _echoes(idea: dict[str, Any]) -> list[dict[str, Any]]:
score = idea.get("score") if isinstance(idea.get("score"), dict) else {}
return _list_of_dicts(score.get("echoes"))
|