Spaces:
Running
Running
Food Desert commited on
Commit ·
87dee11
1
Parent(s): 0ea3247
Render architecture diagram via HTML at docs marker for HF compatibility
Browse files
app.py
CHANGED
|
@@ -28,6 +28,7 @@ from psq_rag.ui.group_ranked_display import rank_groups_from_tfidf, _load_enable
|
|
| 28 |
APP_DIR = Path(__file__).parent
|
| 29 |
DOCS_DIR = APP_DIR / "docs"
|
| 30 |
ARCH_DIAGRAM_FILE = DOCS_DIR / "assets" / "architecture_overview.png"
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
_CORPORATE_HARDBLOCK_PATTERNS = [
|
|
@@ -137,15 +138,6 @@ def _load_about_docs_markdown() -> str:
|
|
| 137 |
parts = text.split("---", 2)
|
| 138 |
if len(parts) >= 3:
|
| 139 |
text = parts[2].strip()
|
| 140 |
-
if "{{ARCHITECTURE_DIAGRAM}}" in text:
|
| 141 |
-
arch_uri = _load_arch_diagram_data_uri()
|
| 142 |
-
if arch_uri:
|
| 143 |
-
text = text.replace(
|
| 144 |
-
"{{ARCHITECTURE_DIAGRAM}}",
|
| 145 |
-
f'<img src="{arch_uri}" alt="Architecture diagram" />',
|
| 146 |
-
)
|
| 147 |
-
else:
|
| 148 |
-
text = text.replace("{{ARCHITECTURE_DIAGRAM}}", "`(architecture diagram unavailable)`")
|
| 149 |
if text:
|
| 150 |
return text
|
| 151 |
return (
|
|
@@ -183,6 +175,25 @@ def _load_arch_diagram_data_uri() -> str:
|
|
| 183 |
return f"data:image/png;base64,{b64}"
|
| 184 |
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
def _selection_source_rank(origin: str) -> int:
|
| 187 |
o = _normalize_selection_origin(origin)
|
| 188 |
if o == "structural":
|
|
@@ -1435,6 +1446,10 @@ css = """
|
|
| 1435 |
background: #ffffff;
|
| 1436 |
}
|
| 1437 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1438 |
.top-instruction {
|
| 1439 |
text-align: center;
|
| 1440 |
margin: 2px 0 6px 0;
|
|
@@ -2184,11 +2199,30 @@ with gr.Blocks(css=css, js=client_js) as app:
|
|
| 2184 |
placeholder="Progress logs will appear here."
|
| 2185 |
)
|
| 2186 |
with gr.Accordion("How Prompt Squirrel Works", open=False):
|
| 2187 |
-
|
| 2188 |
-
|
| 2189 |
-
|
| 2190 |
-
|
| 2191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2192 |
tooltip_map_payload = gr.Textbox(
|
| 2193 |
value="{}",
|
| 2194 |
visible=True,
|
|
|
|
| 28 |
APP_DIR = Path(__file__).parent
|
| 29 |
DOCS_DIR = APP_DIR / "docs"
|
| 30 |
ARCH_DIAGRAM_FILE = DOCS_DIR / "assets" / "architecture_overview.png"
|
| 31 |
+
ARCH_DIAGRAM_MARKER = "{{ARCHITECTURE_DIAGRAM}}"
|
| 32 |
|
| 33 |
|
| 34 |
_CORPORATE_HARDBLOCK_PATTERNS = [
|
|
|
|
| 138 |
parts = text.split("---", 2)
|
| 139 |
if len(parts) >= 3:
|
| 140 |
text = parts[2].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
if text:
|
| 142 |
return text
|
| 143 |
return (
|
|
|
|
| 175 |
return f"data:image/png;base64,{b64}"
|
| 176 |
|
| 177 |
|
| 178 |
+
def _split_about_docs_for_diagram(md: str) -> Tuple[str, str]:
|
| 179 |
+
text = (md or "").strip()
|
| 180 |
+
if ARCH_DIAGRAM_MARKER not in text:
|
| 181 |
+
return text, ""
|
| 182 |
+
before, after = text.split(ARCH_DIAGRAM_MARKER, 1)
|
| 183 |
+
return before.strip(), after.strip()
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def _build_arch_diagram_html() -> str:
|
| 187 |
+
uri = _load_arch_diagram_data_uri()
|
| 188 |
+
if not uri:
|
| 189 |
+
return "<p><code>(architecture diagram unavailable)</code></p>"
|
| 190 |
+
return f"""
|
| 191 |
+
<div class="arch-diagram-wrap">
|
| 192 |
+
<img src="{uri}" alt="Architecture diagram" />
|
| 193 |
+
</div>
|
| 194 |
+
"""
|
| 195 |
+
|
| 196 |
+
|
| 197 |
def _selection_source_rank(origin: str) -> int:
|
| 198 |
o = _normalize_selection_origin(origin)
|
| 199 |
if o == "structural":
|
|
|
|
| 1446 |
background: #ffffff;
|
| 1447 |
}
|
| 1448 |
|
| 1449 |
+
.arch-diagram-wrap {
|
| 1450 |
+
margin: 6px 0 10px 0;
|
| 1451 |
+
}
|
| 1452 |
+
|
| 1453 |
.top-instruction {
|
| 1454 |
text-align: center;
|
| 1455 |
margin: 2px 0 6px 0;
|
|
|
|
| 2199 |
placeholder="Progress logs will appear here."
|
| 2200 |
)
|
| 2201 |
with gr.Accordion("How Prompt Squirrel Works", open=False):
|
| 2202 |
+
_about_md = _load_about_docs_markdown()
|
| 2203 |
+
if ARCH_DIAGRAM_MARKER in _about_md:
|
| 2204 |
+
_about_before, _about_after = _split_about_docs_for_diagram(_about_md)
|
| 2205 |
+
if _about_before:
|
| 2206 |
+
gr.Markdown(
|
| 2207 |
+
_about_before,
|
| 2208 |
+
elem_id="about-docs",
|
| 2209 |
+
elem_classes=["about-docs"],
|
| 2210 |
+
)
|
| 2211 |
+
gr.HTML(
|
| 2212 |
+
_build_arch_diagram_html(),
|
| 2213 |
+
elem_classes=["about-docs"],
|
| 2214 |
+
)
|
| 2215 |
+
if _about_after:
|
| 2216 |
+
gr.Markdown(
|
| 2217 |
+
_about_after,
|
| 2218 |
+
elem_classes=["about-docs"],
|
| 2219 |
+
)
|
| 2220 |
+
else:
|
| 2221 |
+
gr.Markdown(
|
| 2222 |
+
_about_md,
|
| 2223 |
+
elem_id="about-docs",
|
| 2224 |
+
elem_classes=["about-docs"],
|
| 2225 |
+
)
|
| 2226 |
tooltip_map_payload = gr.Textbox(
|
| 2227 |
value="{}",
|
| 2228 |
visible=True,
|