Download app.py from zeechimp/hv-reader: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/zeechimp/hv-reader/resolve/main/app.py
- Command line
-
hf download hf://zeechimp/hv-reader/app.py
-
curl -L -o app.py https://huggingface.co/zeechimp/hv-reader/resolve/main/app.py
2.04 kB
| """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() |