'
f"Estimated share who would mark each word as unknown · {group}.
"
f"Warmer colors indicate a higher chance. For example, 20% means about one in five learners.{coverage}
"
f'{"".join(pieces)}
'
)
def add_learner_check(runner):
import gradio as gr
with gr.Accordion(TITLE, open=False):
gr.Markdown(
"Check one English sentence against learners’ own reports of words they did not understand."
)
text = gr.Textbox(label="English sentence", placeholder=EXAMPLE, lines=2)
level = gr.Dropdown(
label="Learner’s measured English level (CEFR)",
choices=[("No level supplied", POOLED), *[(k, k) for k in LEVELS]],
value=POOLED,
)
button = gr.Button("Check learner vocabulary", variant="secondary")
result = gr.HTML()
state = gr.State()
def submit(sentence, measured):
try:
if measured not in (POOLED, *LEVELS):
raise ValueError(
"Choose a listed CEFR level or use the full learner group."
)
packet = runner.learner_sentence(sentence)
return packet, display(packet, measured)
except ValueError as error:
raise gr.Error(escape(str(error))) from error
def change(measured, sentence, record):
return (
display(record, measured) if record and record["text"] == sentence else ""
)
button.click(
submit,
[text, level],
[state, result],
api_name="learner_vocabulary",
concurrency_limit=1,
)
level.input(
change, [level, text, state], result, api_name=False, show_progress="hidden"
)
text.input(
lambda: (None, ""),
outputs=[state, result],
api_name=False,
show_progress="hidden",
)