Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions assets/paper_zzzz_refinement.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* Reading hierarchy and quiet supporting content. */
[data-testid="stMain"] .st-key-example_footer [data-testid="stCaptionContainer"] {
font-size: .75rem; line-height: 1.4; text-align: right; margin-top: var(--ep-space-4);
}
[data-testid="stMain"] [class*="st-key-topic_example_card_"] { background: var(--ep-surface-panel); }
[class*="st-key-topic_example_card_"] [data-testid="stRadio"] label {
border: 1px solid var(--ep-border); border-radius: var(--ep-radius-control);
padding: .65rem .85rem; margin-block: .25rem; background: var(--ep-surface-panel);
}
[class*="st-key-topic_example_card_"] [data-testid="stRadio"] label:has(input:checked) { border-color: var(--ep-action); background: var(--ep-surface-subtle); }
[data-testid="stMain"] .st-key-learning_radar_ranking_panel h3 { font-size: var(--ep-type-section); margin-bottom: var(--ep-space-4); }
.radar-ranked-row strong { font-size: 1rem; line-height: 1.4; }
.radar-ranked-row span { font-size: .875rem; line-height: 1.4; }
.radar-ranked-row small { font-size: .8rem; line-height: 1.5; }
[class*="_self_check_row"] { padding-block: var(--ep-space-3); gap: var(--ep-space-3); }
[class*="_practice_action"] { padding-block: var(--ep-space-4); border-top: 1px solid var(--ep-border); margin-top: var(--ep-space-4); }
[class*="_explain_nav"] { border-top: 1px solid var(--ep-border); padding-top: var(--ep-space-4); margin-top: var(--ep-space-4); gap: var(--ep-space-6); }
[data-testid="stMain"] .st-key-dashboard_courses_header { margin-top: var(--ep-space-6); }
[data-testid="stMain"] .st-key-dashboard_actions { margin-block: var(--ep-space-4) var(--ep-space-6); }
/* The margin is a transparent layer, not another sheet with a moving landscape.
Its grid space stays stable when hidden so the background and question do not resize. */
[data-testid="stMain"] .st-key-flight_worksheet_margin {
background: transparent !important; background-image: none !important; border: 0;
box-shadow: none; opacity: 1; visibility: visible;
transition: opacity var(--ep-panel-motion) ease, visibility var(--ep-panel-motion);
}
[data-testid="stMain"]:has(.practice-panel-state[data-open="false"]) .st-key-flight_worksheet_margin {
opacity: 0; visibility: hidden; pointer-events: none;
}
[data-testid="stMain"] { background-attachment: fixed; }
/* Treasure-map route: keep the drawing at its natural scale on narrow screens. */
.paper-progress-route { display: block; width: 100%; min-width: 7rem; max-width: 38rem; height: 4.5rem; overflow: visible; }
.route-line { fill: none; stroke: var(--ep-text-secondary); stroke-width: 1.4; stroke-dasharray: 3 6; }
.route-stop { fill: var(--ep-surface-panel); stroke: var(--ep-action); stroke-width: 1.4; }
.route-plane-static { display: none; }
/* One shared central loading layer for explicit operations and Streamlit reruns. */
[data-testid="stApp"]:has([data-testid="stStatusWidgetRunningIcon"]) [data-testid="stHeader"]::after { content: none !important; animation: none !important; }
@keyframes paper-route-loading { from { offset-distance: 0%; } to { offset-distance: 100%; } }
@keyframes paper-loading-reveal { from { opacity: 0; } to { opacity: 1; } }
[data-testid="stApp"]:is(:has([data-testid="stStatusWidgetRunningIcon"]), :has([data-testid="stSpinner"]))::before {
content: ""; position: fixed; inset: 0; z-index: 9990; pointer-events: none;
background: rgb(254 247 239 / 65%) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 240 120'%3E%3Cpath d='M8 60 C44 4 76 116 120 60 S196 4 232 60' fill='none' stroke='%23586475' stroke-width='1.5' stroke-dasharray='3 6'/%3E%3C/svg%3E") center / 240px 120px no-repeat;
backdrop-filter: blur(4px); opacity: 0; animation: paper-loading-reveal 150ms 200ms forwards;
}
[data-testid="stApp"]:is(:has([data-testid="stStatusWidgetRunningIcon"]), :has([data-testid="stSpinner"]))::after {
content: ""; position: fixed; top: calc(50% - 60px); left: calc(50% - 120px);
z-index: 9991; width: 38px; height: 28px; pointer-events: none;
background: var(--paper-plane) center / contain no-repeat;
offset-path: path('M8 60 C44 4 76 116 120 60 S196 4 232 60');
offset-rotate: auto 25deg; opacity: 0;
animation: paper-route-loading 2.6s ease-in-out infinite alternate, paper-loading-reveal 150ms 200ms forwards;
}
[data-testid="stSpinner"] [data-testid="stSpinnerIcon"] { display: none; }
[data-testid="stSpinner"] { position: fixed; z-index: 9992; top: calc(50% + 85px); left: 50%; transform: translateX(-50%); max-width: min(85vw, 30rem); text-align: center; }
@media (prefers-reduced-motion: reduce) {
.route-plane-moving { display: none; }
.route-plane-static { display: initial; }
[data-testid="stMain"] .st-key-flight_worksheet_margin { transition: none; }
[data-testid="stApp"]:is(:has([data-testid="stStatusWidgetRunningIcon"]), :has([data-testid="stSpinner"]))::after {
animation: none; offset-distance: 50%; opacity: 1;
}
[data-testid="stApp"]:is(:has([data-testid="stStatusWidgetRunningIcon"]), :has([data-testid="stSpinner"]))::before { animation: none; opacity: 1; }
}
.paper-radar-chart .radar-label { font-family: system-ui, sans-serif; font-weight: 500; }
.st-key-learning_radar_page_chart [data-testid="stCaptionContainer"] { text-align: right; font-size: .75rem; }
/* Optional explanations: one quiet question mark, revealed by hover or focus. */
.quiet-help-row { display: flex; justify-content: flex-end; min-height: 1.5rem; }
.quiet-help { position: relative; display: inline-flex; }
.quiet-help button { width: 1.5rem; height: 1.5rem; border: 1px solid var(--ep-border); border-radius: 50%; background: transparent; color: var(--ep-text-secondary); padding: 0; font: 600 .8rem/1 system-ui; cursor: help; }
.quiet-help button:focus-visible { outline: 2px solid var(--ep-focus); outline-offset: 3px; }
.quiet-help-text { visibility: hidden; opacity: 0; position: absolute; z-index: 50; right: 0; bottom: calc(100% + .5rem); width: min(21rem, 78vw); padding: .75rem 1rem; border: 1px solid var(--ep-border); border-radius: var(--ep-radius-control); color: var(--ep-text-primary); background: var(--ep-surface-panel); box-shadow: 0 4px 20px rgb(19 34 79 / 10%); font: 400 .875rem/1.6 system-ui; text-align: left; pointer-events: none; }
.quiet-help:is(:hover,:focus-within) .quiet-help-text { opacity: 1; visibility: visible; pointer-events: auto; }
.quiet-help::before { content: ''; position: absolute; bottom: 100%; width: 100%; height: .6rem; }
@media (pointer: coarse) { .quiet-help button { width: 2.75rem; height: 2.75rem; } }
.st-key-learning_radar_mark_panel h3 { font-size: var(--ep-type-section); }
/* Turn before the return trip so the loading plane never travels backwards. */
@keyframes paper-route-loading {
0% { offset-distance: 0%; offset-rotate: auto 25deg; }
49.9% { offset-distance: 100%; offset-rotate: auto 25deg; }
50% { offset-distance: 100%; offset-rotate: auto 205deg; }
99.9% { offset-distance: 0%; offset-rotate: auto 205deg; }
100% { offset-distance: 0%; offset-rotate: auto 25deg; }
}
[data-testid="stApp"]:is(:has([data-testid="stStatusWidgetRunningIcon"]), :has([data-testid="stSpinner"]))::after {
animation: paper-route-loading 5.2s ease-in-out infinite, paper-loading-reveal 150ms 200ms forwards;
}
@media (prefers-reduced-motion: reduce) {
[data-testid="stApp"]:is(:has([data-testid="stStatusWidgetRunningIcon"]), :has([data-testid="stSpinner"]))::after { animation: none; }
}
4 changes: 4 additions & 0 deletions assets/ui_tokens.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* Shared primitives -> semantic roles -> component aliases. Also loaded in Pilot's shadow root. */
:root, :host {
--ep-type-body: 1rem;
--ep-type-section: 1.35rem;
--ep-type-label: .875rem;
--ep-panel-motion: 240ms;
--ep-cream-50: #FEF7EF;
--ep-cream-100: #FAF3E9;
--ep-cream-white: #FFFCF7;
Expand Down
3 changes: 1 addition & 2 deletions components/knowledge_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,7 @@ def render_radar_panel(
With ``course`` the spider chart is drawn above the list, highlighting
``focus_topic_id`` when one is given.
"""
st.markdown(tr(title))
st.caption(tr("Topics where students marked \"I'm stuck here\", most flagged first."))
st.subheader(tr(title.strip("*")))
if course is not None:
# Imported here: components.radar_chart imports this module.
from components.radar_chart import render_radar_figure
Expand Down
9 changes: 5 additions & 4 deletions components/radar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
_LINE = "#EEE7DF"
_BADGE = "#F0EADA"
_CARD = "#FFFCF7"
_FONT_FAMILY = "Georgia, 'Times New Roman', serif"
_FONT_FAMILY = "system-ui, sans-serif"

_FONT_SIZE = 12
_LINE_HEIGHT = 14
Expand Down Expand Up @@ -345,10 +345,10 @@ def radar_chart_svg(axes: Sequence[RadarAxis], *, size: int = 320) -> str:
return "".join(parts)


def _render_svg(axes: Sequence[RadarAxis]) -> None:
def _render_svg(axes: Sequence[RadarAxis], size: int = 320) -> None:
# The wrapping <div> keeps the markup one raw HTML block for Markdown.
st.markdown(
f'<div class="paper-radar">\n{radar_chart_svg(axes)}\n</div>',
f'<div class="paper-radar">\n{radar_chart_svg(axes, size=size)}\n</div>',
unsafe_allow_html=True,
)

Expand Down Expand Up @@ -378,6 +378,7 @@ def render_course_radar_chart(
*,
focus_topic_id: str | None = None,
limit: int = 6,
size: int = 320,
key: str,
) -> None:
"""Draw the course's Learning Radar chart with its captions."""
Expand All @@ -387,7 +388,7 @@ def render_course_radar_chart(
with st.container(key=key):
if not axes:
return
_render_svg(axes)
_render_svg(axes, size)
st.caption(tr("Students stuck per topic"))
if not any(axis.value > 0 for axis in axes):
st.caption(tr("No topics have been flagged yet."))
Expand Down
119 changes: 79 additions & 40 deletions components/topic_explanation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""On-demand topic teaching, with existing course examples available offline."""
from services.ui_help import help_tip
import hashlib

import streamlit as st
Expand All @@ -18,48 +19,86 @@ def render_topic_explanation(course: StudyPackage, topic_id: str) -> None:
(course.model_dump_json() + topic_id + str(chinese)).encode()
).hexdigest()
with st.container(key="topic_teaching_content"):
st.caption(tr("Go beyond the summary: understand the idea, then work through an example."))
if st.button(tr("Explain step by step"), key=f"graph_explain_{fingerprint}"):
language = "Simplified Chinese" if chinese else "English"
prompt = (
f"Explain this selected topic in {language} for a student who found the summary too abstract. "
"Use short numbered sections: 1. Intuition in everyday language; "
"2. Key conditions or steps and why each matters; "
"3. One simple worked example with each reasoning step; "
"4. A common mistake and how to avoid it; 5. One self-check question. "
"Label any illustrative example as an example, not a quotation from the course. "
"Use only the supported concepts; explicitly acknowledge missing context. "
"Do not merely repeat the summary."
)
with st.spinner(tr("Preparing the explanation…")):
result = ask_tutor(course.model_dump(mode="json"), prompt, topic_id)
if result.get("ok") and result.get("answer", "").strip():
st.session_state["graph_topic_explanation"] = {
"fingerprint": fingerprint, "answer": result["answer"]
}
else:
st.warning(tr("The explanation is unavailable. You can still read the course example below, or try again."))
saved = st.session_state.get("graph_topic_explanation", {})
if saved.get("fingerprint") == fingerprint:
st.caption(tr("AI explanation · check it against your course material."))
st.write(saved["answer"])
from services.demo_teaching import calculus_lesson
from services.demo_updates import FILES
lesson = calculus_lesson(topic_id, chinese) if course.course_id == 'calculus-i-demo' else None
if lesson:
steps, worked, mistake = lesson
st.subheader(tr("Step-by-step explanation"))
for number, step in enumerate(steps, 1):
st.write(f"{number}. {step}")
with st.container(border=True, key="topic_worked_example"):
st.markdown('**' + tr('Worked example') + '**')
st.write(worked)
st.caption(tr('Common mistake') + ': ' + mistake)
elif course.course_id in FILES:
st.subheader(tr("Step-by-step explanation"))
st.write(topic.summary)
first = next((q for q in course.questions if q.topic_id == topic_id), None)
if first:
st.markdown('**' + tr('Worked example') + '**')
st.write(first.question)
st.write(first.explanation)
else:
st.caption(tr("Go beyond the summary: understand the idea, then work through an example."))
if st.button(tr("Explain step by step"), key=f"graph_explain_{fingerprint}"):
language = "Simplified Chinese" if chinese else "English"
prompt = (
f"Explain this selected topic in {language} for a student who found the summary too abstract. "
"Use short numbered sections: 1. Intuition in everyday language; "
"2. Key conditions or steps and why each matters; "
"3. One simple worked example with each reasoning step; "
"4. A common mistake and how to avoid it; 5. One self-check question. "
"Label any illustrative example as an example, not a quotation from the course. "
"Use only the supported concepts; explicitly acknowledge missing context. "
"Do not merely repeat the summary."
)
with st.spinner(tr("Preparing the explanation…")):
result = ask_tutor(course.model_dump(mode="json"), prompt, topic_id)
if result.get("ok") and result.get("answer", "").strip():
st.session_state["graph_topic_explanation"] = {
"fingerprint": fingerprint, "answer": result["answer"]
}
else:
st.warning(tr("The explanation is unavailable. You can still read the course example below, or try again."))
saved = st.session_state.get("graph_topic_explanation", {})
if saved.get("fingerprint") == fingerprint:
st.caption(tr("AI explanation · check it against your course material."))
st.write(saved["answer"])

examples = [question for question in course.questions if question.topic_id == topic_id]
st.markdown(tr("**Example from this course**"))
st.caption(tr("Original course wording is preserved. Reading examples does not count as a graded attempt."))
st.subheader(tr("Example from this course"))
if not examples:
st.caption(tr("There is no example for this topic in the current course yet."))
return
example = st.selectbox(
tr("Choose an example"), examples,
format_func=lambda item: item.question,
key=f"graph_example_{fingerprint}",
)
st.write(example.question)
for index, option in enumerate(example.options):
st.write(f"{chr(65 + index)}. {option}")
if st.checkbox(tr("Show answer and explanation"), key=f"graph_solution_{fingerprint}_{example.id}"):
st.markdown(tr("**Answer**"))
st.write(f"{chr(65 + example.correct_index)}. {example.options[example.correct_index]}")
st.markdown(tr("**Why this answer**"))
st.write(example.explanation)
by_id = {item.id: item for item in examples}
selected_key = f'graph_selected_example_{fingerprint}'
selected = st.session_state.get(selected_key)
if selected not in by_id:
def choose_example():
st.session_state[selected_key] = st.session_state.get(f'graph_example_{fingerprint}')
st.selectbox(
tr("Choose an example"), list(by_id), index=None,
format_func=lambda item: by_id[item].question,
key=f"graph_example_{fingerprint}", on_change=choose_example,
placeholder=tr('Choose an example'),
)
return
example = by_id[selected]
from services.practice_pages_ui import render_question_heading
with st.container(border=True, key=f"topic_example_card_{fingerprint}"):
render_question_heading(examples.index(example) + 1, example.question)
st.radio(tr('Choose an answer'), list(range(len(example.options))), index=None,
format_func=lambda i: f"{chr(65+i)}. {example.options[i]}",
key=f'graph_example_answer_{fingerprint}_{example.id}')
if st.checkbox(tr("Show answer and explanation"), key=f"graph_solution_{fingerprint}_{example.id}"):
st.markdown(tr("**Answer**"))
st.write(f"{chr(65 + example.correct_index)}. {example.options[example.correct_index]}")
st.markdown(tr("**Why this answer**"))
st.write(example.explanation)
with st.container(key='example_footer'):
help_tip(tr("Original course wording is preserved. Reading examples does not count as a graded attempt."))
def change_example():
st.session_state.pop(selected_key, None)
st.session_state.pop(f'graph_example_{fingerprint}', None)
st.button(tr('Change example'), key=f'graph_change_example_{fingerprint}', on_click=change_example)
Loading
Loading