Spaces:
Paused
Paused
Download apps/renderer/qa/report.py from modventures/prevision: direct link, hf CLI and curl.
- Browser
- Download file 10.1 kB
-
https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/renderer/qa/report.py
- Command line
-
hf download hf://spaces/modventures/prevision/apps/renderer/qa/report.py
-
curl -L -o report.py https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/renderer/qa/report.py
10.1 kB
| """QA HTML report generation: build a standalone HTML report from run data.""" | |
| import html | |
| from enums import QaResult, QaStatus | |
| from qa.store import qa_int | |
| def qa_html(value) -> str: | |
| if value is None: | |
| return "" | |
| return html.escape(str(value), quote=True) | |
| def qa_status_label(status) -> str: | |
| value = str(status or "unknown").lower() | |
| if value in {s.value for s in QaStatus} | {r.value for r in QaResult}: | |
| return value | |
| return "unknown" | |
| def qa_yes_no(value) -> str: | |
| if isinstance(value, bool): | |
| return "yes" if value else "no" | |
| return "n/a" | |
| def qa_score_label(value) -> str: | |
| if isinstance(value, (int, float)): | |
| try: | |
| import math | |
| if math.isfinite(value): | |
| return f"{float(value):.2f}" | |
| except (TypeError, ValueError): | |
| pass | |
| return "n/a" | |
| def qa_list_label(value) -> str: | |
| if isinstance(value, list): | |
| items = [str(item) for item in value if isinstance(item, str) and item.strip()] | |
| if items: | |
| return "; ".join(items) | |
| return "none" | |
| def qa_metric_html(label: str, value: str) -> str: | |
| return f"<span><strong>{qa_html(value)}</strong>{qa_html(label)}</span>" | |
| def qa_image_html(label: str, url) -> str: | |
| if not isinstance(url, str) or not url.strip(): | |
| return f""" | |
| <div class="image-panel missing"> | |
| <span>{qa_html(label)}</span> | |
| <p>Missing screenshot</p> | |
| </div> | |
| """ | |
| return f""" | |
| <div class="image-panel"> | |
| <span>{qa_html(label)}</span> | |
| <img src="{qa_html(url)}" alt="{qa_html(label)} QA screenshot" loading="lazy" /> | |
| </div> | |
| """ | |
| def qa_gemini_report_html(gemini) -> str: | |
| if not isinstance(gemini, dict): | |
| return '<p class="muted">Gemini was not used or did not return a judgment for this result.</p>' | |
| issue_rows = [] | |
| if gemini.get("coverageGapDetected"): | |
| issue_rows.append(f"<li>Coverage gaps: {qa_html(qa_list_label(gemini.get('missedFloorAreas')))}</li>") | |
| if gemini.get("directionMismatchDetected"): | |
| issue_rows.append(f"<li>Direction issues: {qa_html(qa_list_label(gemini.get('directionIssues')))}</li>") | |
| if gemini.get("bleedDetected"): | |
| issue_rows.append("<li>Bleed detected on non-target surfaces.</li>") | |
| if isinstance(gemini.get("failureReasons"), list) and gemini.get("failureReasons"): | |
| issue_rows.append(f"<li>Failure reasons: {qa_html(qa_list_label(gemini.get('failureReasons')))}</li>") | |
| issues_html = f"<ul>{''.join(issue_rows)}</ul>" if issue_rows else "" | |
| metrics_html = "".join([ | |
| qa_metric_html("overall", qa_yes_no(gemini.get("overallPass"))), | |
| qa_metric_html("tile", qa_yes_no(gemini.get("tileApplied"))), | |
| qa_metric_html("coverage gap", qa_yes_no(gemini.get("coverageGapDetected"))), | |
| qa_metric_html("direction", qa_score_label(gemini.get("directionQuality"))), | |
| qa_metric_html("surface", qa_score_label(gemini.get("surfaceCorrectness"))), | |
| qa_metric_html("edge", qa_score_label(gemini.get("edgeCompleteness"))), | |
| qa_metric_html("occlusion", qa_score_label(gemini.get("occlusionBoundaryQuality"))), | |
| qa_metric_html("perspective", qa_score_label(gemini.get("perspectiveQuality"))), | |
| qa_metric_html("lighting", qa_score_label(gemini.get("lightingPreserved"))), | |
| qa_metric_html("realism", qa_score_label(gemini.get("realism"))), | |
| ]) | |
| return f""" | |
| <div class="gemini"> | |
| <div class="metrics">{metrics_html}</div> | |
| <p>{qa_html(gemini.get("notes") or "No notes returned.")}</p> | |
| {issues_html} | |
| </div> | |
| """ | |
| def qa_result_report_html(result: dict, index: int) -> str: | |
| status = qa_status_label(result.get("status")) | |
| image_name = result.get("imageName") or result.get("imageKey") or "Unknown image" | |
| tile_name = result.get("tileName") or "Unknown tile" | |
| error_html = f'<p class="error">{qa_html(result.get("error"))}</p>' if result.get("error") else "" | |
| return f""" | |
| <article class="result-card status-{status}"> | |
| <header> | |
| <div> | |
| <p class="eyebrow">{qa_html(tile_name)}</p> | |
| <h2>{index}. {qa_html(image_name)}</h2> | |
| </div> | |
| <span class="badge status-{status}">{qa_html(status)}</span> | |
| </header> | |
| <div class="image-stack"> | |
| {qa_image_html("Before", result.get("beforeImageUrl"))} | |
| {qa_image_html("After Tile Applied", result.get("afterImageUrl"))} | |
| </div> | |
| {error_html} | |
| <section> | |
| <h3>Gemini Judgment</h3> | |
| {qa_gemini_report_html(result.get("gemini"))} | |
| </section> | |
| </article> | |
| """ | |
| def build_qa_report_html(run: dict) -> str: | |
| status = qa_status_label(run.get("status")) | |
| results = run.get("results") if isinstance(run.get("results"), list) else [] | |
| result_cards = "\n".join( | |
| qa_result_report_html(result, index) | |
| for index, result in enumerate(results, start=1) | |
| if isinstance(result, dict) | |
| ) | |
| if not result_cards: | |
| result_cards = """ | |
| <section class="empty"> | |
| <h2>No screenshots yet</h2> | |
| <p>The report will include screenshots and Gemini judgment after Playwright writes the final report.</p> | |
| </section> | |
| """ | |
| error_html = f'<p class="error">{qa_html(run.get("error"))}</p>' if run.get("error") else "" | |
| title = f"QA Report {run.get('id', '')}".strip() | |
| return f"""<!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <title>{qa_html(title)}</title> | |
| <style> | |
| :root {{ | |
| color-scheme: light; | |
| --bg: #f6f7fb; | |
| --panel: #ffffff; | |
| --ink: #172033; | |
| --muted: #667085; | |
| --line: #d8deea; | |
| --passed: #177245; | |
| --failed: #b4233a; | |
| --running: #1d5fbf; | |
| }} | |
| * {{ box-sizing: border-box; }} | |
| body {{ | |
| margin: 0; | |
| background: var(--bg); | |
| color: var(--ink); | |
| font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; | |
| line-height: 1.5; | |
| }} | |
| main {{ width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 56px; }} | |
| .topbar {{ display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 20px; }} | |
| h1, h2, h3, p {{ margin-top: 0; }} | |
| h1 {{ font-size: clamp(28px, 4vw, 42px); margin-bottom: 8px; }} | |
| h2 {{ font-size: 20px; margin-bottom: 4px; }} | |
| h3 {{ font-size: 14px; margin-bottom: 10px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }} | |
| .eyebrow {{ color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px; }} | |
| .summary, .metrics {{ display: flex; flex-wrap: wrap; gap: 8px; }} | |
| .summary span, .metrics span {{ | |
| border: 1px solid var(--line); | |
| border-radius: 8px; | |
| background: #fff; | |
| color: var(--muted); | |
| display: inline-flex; | |
| gap: 6px; | |
| padding: 7px 10px; | |
| font-size: 13px; | |
| align-items: baseline; | |
| }} | |
| .summary strong, .metrics strong {{ color: var(--ink); }} | |
| .badge {{ | |
| border: 1px solid var(--line); | |
| border-radius: 999px; | |
| background: #fff; | |
| color: var(--muted); | |
| padding: 6px 10px; | |
| font-size: 12px; | |
| font-weight: 800; | |
| text-transform: uppercase; | |
| white-space: nowrap; | |
| }} | |
| .status-passed, .status-completed {{ color: var(--passed); border-color: #9bd4b5; }} | |
| .status-failed {{ color: var(--failed); border-color: #f0a4b3; }} | |
| .status-running, .status-queued {{ color: var(--running); border-color: #a9c7ff; }} | |
| .result-card, .empty {{ | |
| background: var(--panel); | |
| border: 1px solid var(--line); | |
| border-radius: 10px; | |
| padding: 18px; | |
| margin-top: 18px; | |
| box-shadow: 0 10px 30px rgba(15, 23, 42, .06); | |
| }} | |
| .result-card > header {{ display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }} | |
| .image-stack {{ display: grid; gap: 16px; }} | |
| .image-panel {{ border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #f8fafc; }} | |
| .image-panel span {{ display: block; padding: 8px 10px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }} | |
| .image-panel img {{ display: block; width: 100%; height: auto; }} | |
| .image-panel.missing {{ padding-bottom: 16px; }} | |
| .image-panel.missing p {{ margin: 0; padding: 0 10px; color: var(--muted); }} | |
| .gemini {{ margin-top: 8px; }} | |
| .gemini p {{ color: var(--ink); margin: 12px 0 0; }} | |
| .gemini ul {{ margin: 12px 0 0; padding-left: 20px; color: var(--failed); }} | |
| .muted {{ color: var(--muted); }} | |
| .error {{ | |
| border: 1px solid #f0a4b3; | |
| border-radius: 8px; | |
| background: #fff1f3; | |
| color: var(--failed); | |
| padding: 10px 12px; | |
| white-space: pre-wrap; | |
| }} | |
| @media (max-width: 720px) {{ | |
| main {{ width: min(100% - 20px, 1120px); padding-top: 20px; }} | |
| .topbar, .result-card > header {{ display: block; }} | |
| .badge {{ display: inline-block; margin-top: 8px; }} | |
| }} | |
| </style> | |
| </head> | |
| <body> | |
| <main> | |
| <header class="topbar"> | |
| <div> | |
| <p class="eyebrow">Real Browser QA Report</p> | |
| <h1>{qa_html(run.get("id") or "QA run")}</h1> | |
| <p class="muted">Generated from backend QA run data. Screenshots are served as report assets, not embedded base64.</p> | |
| </div> | |
| <span class="badge status-{status}">{qa_html(status)}</span> | |
| </header> | |
| <section class="summary"> | |
| {qa_metric_html("done", f"{qa_int(run.get('completed'))}/{qa_int(run.get('total'))}")} | |
| {qa_metric_html("passed", str(qa_int(run.get("passed"))))} | |
| {qa_metric_html("failed", str(qa_int(run.get("failed"))))} | |
| {qa_metric_html("updated", str(run.get("updatedAt") or "unknown"))} | |
| </section> | |
| {error_html} | |
| {result_cards} | |
| </main> | |
| </body> | |
| </html> | |
| """ | |