Calculator: history, live results and expression mode

#2
by arshvinw5 - opened

What's changed

  • Expression mode: a new Expression tab that evaluates a whole expression, e.g. (2 + 3) * 4 / 2 β†’ 10.
    • Supports + - * /, ^ / **, mod / %, sqrt(16) / √16, negative numbers, Γ— and Γ·.
    • Evaluated safely with an ast allow-list (no eval). Unsafe or invalid input shows "Invalid expression".
    • Huge powers (9^9^9) return "Result is too large" instead of hanging.
  • Live results: the Calculate button is removed, and results update as you type.
  • History panel: Save to history (or Enter) adds entries like 2 + 3 = 5. Newest first, capped at 50, with a Clear history button. Errors and repeats of the latest entry are skipped.

Tests

  • 61 tests in test_calculator.py (39 new). All pass with uv run pytest -q.

How to try it

pip/uv run python gradio_calculator.py, then open http://127.0.0.1:7860

Publish this branch
This branch is in draft mode, publish it to be able to merge.

Sign up or log in to comment