Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Gradio demo for hv-reader."""
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
from hv_reader import HVReader, SAMPLE_FICTION, SAMPLE_ACADEMIC, \
|
| 5 |
+
SAMPLE_OVERCLAIM, SAMPLE_MONOTONE
|
| 6 |
+
|
| 7 |
+
model = HVReader()
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def analyze_text(text: str) -> str:
|
| 11 |
+
if not text or not text.strip():
|
| 12 |
+
return "Please enter some text."
|
| 13 |
+
return model.render(model.analyze(text))
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def profile_only(text: str) -> str:
|
| 17 |
+
if not text or not text.strip():
|
| 18 |
+
return "Please enter some text."
|
| 19 |
+
r = model.analyze(text)
|
| 20 |
+
return (
|
| 21 |
+
f"pace {r.pace:.3f} ({r.mean_wpm:.0f} WPM)\n"
|
| 22 |
+
f"memory {r.memory:.3f} (1-week retention)\n"
|
| 23 |
+
f"passes {r.passes:.3f} (reads needed)\n"
|
| 24 |
+
f"slip {r.slip:.3f} (attention lapse)\n"
|
| 25 |
+
f"wall {r.wall:.3f} (refusal)\n"
|
| 26 |
+
f"\n"
|
| 27 |
+
f"ttu {r.ttu_s:.1f} s\n"
|
| 28 |
+
f"hunger {r.hunger_final:+.2f}\n"
|
| 29 |
+
f"\n"
|
| 30 |
+
f"{r.summary}"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
with gr.Blocks(title="hv-reader") as demo:
|
| 35 |
+
gr.Markdown(
|
| 36 |
+
"# hv-reader\n"
|
| 37 |
+
"*The reading experience, in one call.*\n\n"
|
| 38 |
+
"Five-axis profile: pace, memory, passes, slip, wall."
|
| 39 |
+
)
|
| 40 |
+
with gr.Row():
|
| 41 |
+
with gr.Column(scale=2):
|
| 42 |
+
text_in = gr.Textbox(
|
| 43 |
+
label="Text",
|
| 44 |
+
lines=14,
|
| 45 |
+
placeholder="Paste a paragraph, essay, abstract...",
|
| 46 |
+
)
|
| 47 |
+
with gr.Row():
|
| 48 |
+
btn = gr.Button("Analyze", variant="primary")
|
| 49 |
+
p_btn = gr.Button("Profile only")
|
| 50 |
+
with gr.Column(scale=3):
|
| 51 |
+
out = gr.Textbox(
|
| 52 |
+
label="Report",
|
| 53 |
+
lines=34,
|
| 54 |
+
show_copy_button=True,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
btn.click(analyze_text, [text_in], out)
|
| 58 |
+
p_btn.click(profile_only, [text_in], out)
|
| 59 |
+
|
| 60 |
+
gr.Examples(
|
| 61 |
+
examples=[
|
| 62 |
+
[SAMPLE_FICTION],
|
| 63 |
+
[SAMPLE_ACADEMIC],
|
| 64 |
+
[SAMPLE_OVERCLAIM],
|
| 65 |
+
[SAMPLE_MONOTONE],
|
| 66 |
+
],
|
| 67 |
+
inputs=[text_in],
|
| 68 |
+
outputs=out,
|
| 69 |
+
fn=analyze_text,
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
demo.launch()
|