Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,6 +36,48 @@ def get_param_from_url(param):
|
|
| 36 |
user_id = st.query_params.get(param, "")
|
| 37 |
return user_id
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
########################################################################################
|
| 40 |
|
| 41 |
# 'local' or 'hf'. hf is for Hugging Face file system but has limits on the number of access per hour
|
|
@@ -131,7 +173,12 @@ fields: List[Field] = [
|
|
| 131 |
title="Level of priority", other_params={'labels': priority_labels}, mandatory=True),
|
| 132 |
]),
|
| 133 |
|
| 134 |
-
Field(type="container", title="##### Rupture Markers",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
Field(type="expander", title="**Overview of rupture markers** *(expand)*", children=[
|
| 136 |
Field(type="markdown", title="", other_params={"path": "rupture_marker_overview.md"}),
|
| 137 |
]),
|
|
@@ -443,6 +490,13 @@ def validate_current_page(fields: List[Field], index: int) -> bool:
|
|
| 443 |
if not ok:
|
| 444 |
st.error("Please fill in all mandatory fields.")
|
| 445 |
return ok
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
#################################### Streamlit App ####################################
|
| 447 |
|
| 448 |
# Function to navigate rows
|
|
@@ -528,6 +582,8 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 528 |
show_field(child, index, data_collected)
|
| 529 |
|
| 530 |
case 'container':
|
|
|
|
|
|
|
| 531 |
with st.container(border=True):
|
| 532 |
st.markdown(f.title)
|
| 533 |
for child in (f.children or []):
|
|
|
|
| 36 |
user_id = st.query_params.get(param, "")
|
| 37 |
return user_id
|
| 38 |
|
| 39 |
+
def ensure_tooltip_css():
|
| 40 |
+
if st.session_state.get("_tt_css_done"):
|
| 41 |
+
return
|
| 42 |
+
st.markdown("""
|
| 43 |
+
<style>
|
| 44 |
+
.tt-wrap{display:inline-block; position:relative;}
|
| 45 |
+
.help-tt{display:inline-flex; justify-content:center; align-items:center;
|
| 46 |
+
width:1.1rem; height:1.1rem; border-radius:999px; font-weight:700;
|
| 47 |
+
border:1px solid rgba(0,0,0,.3); color:rgba(0,0,0,.75);
|
| 48 |
+
background:rgba(0,0,0,.04); cursor:help; margin-left:.5rem;
|
| 49 |
+
}
|
| 50 |
+
.help-tt::before{content:"?"; font-size:.8rem; line-height:1;}
|
| 51 |
+
.tt-panel{
|
| 52 |
+
position:absolute; z-index:9999; left:0; top:140%;
|
| 53 |
+
background:#111; color:#fff; padding:.6rem .8rem; border-radius:.5rem;
|
| 54 |
+
width:max-content; max-width:32rem; box-shadow:0 8px 24px rgba(0,0,0,.2);
|
| 55 |
+
opacity:0; transform:translateY(-4px); pointer-events:none;
|
| 56 |
+
transition:opacity .12s ease, transform .12s ease;
|
| 57 |
+
}
|
| 58 |
+
.tt-wrap:hover .tt-panel, .help-tt:focus + .tt-panel{
|
| 59 |
+
opacity:1; transform:translateY(0); pointer-events:auto;
|
| 60 |
+
}
|
| 61 |
+
.tt-panel dl{margin:0;}
|
| 62 |
+
.tt-panel dt{font-weight:700; margin:.25rem 0 0;}
|
| 63 |
+
.tt-panel dd{margin:0 0 .25rem 0;}
|
| 64 |
+
</style>
|
| 65 |
+
""", unsafe_allow_html=True)
|
| 66 |
+
st.session_state["_tt_css_done"] = True
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def deflist_tooltip_html(defs: list[tuple[str, str]]) -> str:
|
| 70 |
+
# build the <dl> content
|
| 71 |
+
import html as _html
|
| 72 |
+
dl = "".join(
|
| 73 |
+
f"<dt>{_html.escape(k)}</dt><dd>{_html.escape(v)}</dd>"
|
| 74 |
+
for k, v in defs
|
| 75 |
+
)
|
| 76 |
+
return f"""<span class="tt-wrap">
|
| 77 |
+
<span class="help-tt" tabindex="0" aria-label="definitions"></span>
|
| 78 |
+
<div class="tt-panel"><dl>{dl}</dl></div>
|
| 79 |
+
</span>"""
|
| 80 |
+
|
| 81 |
########################################################################################
|
| 82 |
|
| 83 |
# 'local' or 'hf'. hf is for Hugging Face file system but has limits on the number of access per hour
|
|
|
|
| 173 |
title="Level of priority", other_params={'labels': priority_labels}, mandatory=True),
|
| 174 |
]),
|
| 175 |
|
| 176 |
+
Field(type="container", title="##### Rupture Markers", other_params={
|
| 177 |
+
"defs": [
|
| 178 |
+
("Withdrawal", "Patient moves away from therapist/therapy."),
|
| 179 |
+
("Confrontation", "Patient moves against therapist/therapy."),
|
| 180 |
+
("Mixed", "Both withdrawal and confrontation markers present."),
|
| 181 |
+
]}, children=[
|
| 182 |
Field(type="expander", title="**Overview of rupture markers** *(expand)*", children=[
|
| 183 |
Field(type="markdown", title="", other_params={"path": "rupture_marker_overview.md"}),
|
| 184 |
]),
|
|
|
|
| 490 |
if not ok:
|
| 491 |
st.error("Please fill in all mandatory fields.")
|
| 492 |
return ok
|
| 493 |
+
|
| 494 |
+
def render_container_header(title_md: str, defs: list[tuple[str,str]] | None = None):
|
| 495 |
+
ensure_tooltip_css()
|
| 496 |
+
tip = deflist_tooltip_html(defs) if defs else ""
|
| 497 |
+
# Title supports Markdown; append HTML “?” fragment
|
| 498 |
+
st.markdown(f"{title_md} {tip}", unsafe_allow_html=True)
|
| 499 |
+
|
| 500 |
#################################### Streamlit App ####################################
|
| 501 |
|
| 502 |
# Function to navigate rows
|
|
|
|
| 582 |
show_field(child, index, data_collected)
|
| 583 |
|
| 584 |
case 'container':
|
| 585 |
+
defs = f.other_params.get("defs") if f.other_params else None
|
| 586 |
+
render_container_header(f.title, defs)
|
| 587 |
with st.container(border=True):
|
| 588 |
st.markdown(f.title)
|
| 589 |
for child in (f.children or []):
|