File size: 2,036 Bytes
c3a0bcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Gradio demo for hv-reader."""
import gradio as gr

from hv_reader import HVReader, SAMPLE_FICTION, SAMPLE_ACADEMIC, \
    SAMPLE_OVERCLAIM, SAMPLE_MONOTONE

model = HVReader()


def analyze_text(text: str) -> str:
    if not text or not text.strip():
        return "Please enter some text."
    return model.render(model.analyze(text))


def profile_only(text: str) -> str:
    if not text or not text.strip():
        return "Please enter some text."
    r = model.analyze(text)
    return (
        f"pace    {r.pace:.3f}   ({r.mean_wpm:.0f} WPM)\n"
        f"memory  {r.memory:.3f}   (1-week retention)\n"
        f"passes  {r.passes:.3f}   (reads needed)\n"
        f"slip    {r.slip:.3f}   (attention lapse)\n"
        f"wall    {r.wall:.3f}   (refusal)\n"
        f"\n"
        f"ttu     {r.ttu_s:.1f} s\n"
        f"hunger  {r.hunger_final:+.2f}\n"
        f"\n"
        f"{r.summary}"
    )


with gr.Blocks(title="hv-reader") as demo:
    gr.Markdown(
        "# hv-reader\n"
        "*The reading experience, in one call.*\n\n"
        "Five-axis profile: pace, memory, passes, slip, wall."
    )
    with gr.Row():
        with gr.Column(scale=2):
            text_in = gr.Textbox(
                label="Text",
                lines=14,
                placeholder="Paste a paragraph, essay, abstract...",
            )
            with gr.Row():
                btn = gr.Button("Analyze", variant="primary")
                p_btn = gr.Button("Profile only")
        with gr.Column(scale=3):
            out = gr.Textbox(
                label="Report",
                lines=34,
                show_copy_button=True,
            )

    btn.click(analyze_text, [text_in], out)
    p_btn.click(profile_only, [text_in], out)

    gr.Examples(
        examples=[
            [SAMPLE_FICTION],
            [SAMPLE_ACADEMIC],
            [SAMPLE_OVERCLAIM],
            [SAMPLE_MONOTONE],
        ],
        inputs=[text_in],
        outputs=out,
        fn=analyze_text,
    )


if __name__ == "__main__":
    demo.launch()