toh26 / tab_sampler.py
clr's picture
specgr
f99c784
Raw History Blame Contribute Delete
1.92 kB
import gradio as gr
import data
def sampler_tab(book, folder):
pool = data.build_pool(book)
# idk what hf's problem is
# to reproduce the bug, refresh then select ö, au, both lengths, on tab2
# ¿¿¿???
#gr.Markdown("""
# # 📍 Síðan virkar best á https://clr-toh26.hf.space/
# """, elem_id="hfembedded-only")
with gr.Row(equal_height=True):
sounds = gr.CheckboxGroup(data.sound_choices(book), label="Veldu 2-4 hljóð og 1 lengd, eða 1-3 hljóð og 2 lengdir.", scale=6)
with gr.Column(scale=2, min_width=160):
with gr.Row():
lengdir = gr.CheckboxGroup(data.LENGD_SEL, value=["langt"], label="Lengd(ir)")
with gr.Row():
hint = gr.Checkbox(True, label="Gefa vísbendingar")
with gr.Row():
spectro = gr.Checkbox(False, label="Sýna hljóðrófsrit")
go = gr.Button("Byrja", variant="primary", scale=1, min_width=120)
status = gr.Markdown("")
state = data.exercise_panel()
order = {s: i for i, (_, s) in enumerate(data.sound_choices(book))}
def practise(sounds_, lengdir_, hint_, spectro_):
err = data.validate_selection(sounds_, lengdir_)
if err:
return gr.skip(), f"# ⚠️ {err}"
sounds_ = sorted(sounds_, key=order.get)
items, warnings = data.sample_exercises(pool, folder, sounds_, lengdir_)
msg = f"✅ {len(items)} dæmi."
if warnings:
msg += " ⚠️ " + "; ".join(warnings) + "."
st = data.new_exercise_set(items, hint_, ask_lengd=len(lengdir_) == 2, ask_sound=len(sounds_) > 1,
spectro=spectro_)
return st, msg
data.wire_generate(go, state, [sounds, lengdir, hint, spectro], practise, extra_outputs=[status],
guard=lambda s, l, h, sp: data.validate_selection(s, l))