Calculator: empty-input handling, cleaner results, new operations

#1
by arshvinw5 - opened

What's changed

  • Empty inputs: blank fields now show a friendly message instead of a Gradio error.
  • Cleaner results: whole numbers show without .0 (5, not 5.0), and floating-point noise is rounded away (0.1 + 0.2 β†’ 0.3).
  • New operations: power (^), modulo (mod), square root (√) and percentage (% of, e.g. 15 % of 240 = 36).
    • The second number field hides when √ is selected.
    • Clear messages for modulo by zero, negative square roots, results too large to show, and results that aren't real numbers.
  • demo.launch() now runs only under if __name__ == "__main__":, so tests can import the module.

Tests

  • Added test_calculator.py with 22 pytest cases covering every operation and error path. 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