simplutils 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. {simplutils-0.1.0 → simplutils-0.1.1}/PKG-INFO +64 -25
  2. {simplutils-0.1.0 → simplutils-0.1.1}/README.md +59 -22
  3. {simplutils-0.1.0 → simplutils-0.1.1}/pyproject.toml +5 -3
  4. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/__init__.py +1 -1
  5. simplutils-0.1.1/src/simplutils/ui.py +368 -0
  6. simplutils-0.1.0/PUBLISHING.md +0 -265
  7. simplutils-0.1.0/src/simplutils/ui.py +0 -186
  8. {simplutils-0.1.0 → simplutils-0.1.1}/.gitignore +0 -0
  9. {simplutils-0.1.0 → simplutils-0.1.1}/LICENSE +0 -0
  10. {simplutils-0.1.0 → simplutils-0.1.1}/examples/cli_tour.py +0 -0
  11. {simplutils-0.1.0 → simplutils-0.1.1}/examples/library_tour.py +0 -0
  12. {simplutils-0.1.0 → simplutils-0.1.1}/examples/sample_data/config_v1.json +0 -0
  13. {simplutils-0.1.0 → simplutils-0.1.1}/examples/sample_data/config_v2.json +0 -0
  14. {simplutils-0.1.0 → simplutils-0.1.1}/examples/sample_data/logs/simplutils.log +0 -0
  15. {simplutils-0.1.0 → simplutils-0.1.1}/examples/sample_data/notes_v1.txt +0 -0
  16. {simplutils-0.1.0 → simplutils-0.1.1}/examples/sample_data/notes_v2.txt +0 -0
  17. {simplutils-0.1.0 → simplutils-0.1.1}/examples/sample_data/people.csv +0 -0
  18. {simplutils-0.1.0 → simplutils-0.1.1}/examples/sample_data/server.log +0 -0
  19. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/__main__.py +0 -0
  20. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/cli.py +0 -0
  21. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/interactive.py +0 -0
  22. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/logs.py +0 -0
  23. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/registry.py +0 -0
  24. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/textio.py +0 -0
  25. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/__init__.py +0 -0
  26. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/ai.py +0 -0
  27. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/convert.py +0 -0
  28. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/diff.py +0 -0
  29. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/encoding.py +0 -0
  30. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/files.py +0 -0
  31. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/generators.py +0 -0
  32. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/hashing.py +0 -0
  33. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/images.py +0 -0
  34. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/jsontools.py +0 -0
  35. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/jwt.py +0 -0
  36. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/mapsearch.py +0 -0
  37. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/pdfs.py +0 -0
  38. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/pii.py +0 -0
  39. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/qr.py +0 -0
  40. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/regex.py +0 -0
  41. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/text.py +0 -0
  42. {simplutils-0.1.0 → simplutils-0.1.1}/src/simplutils/tools/timetools.py +0 -0
  43. {simplutils-0.1.0 → simplutils-0.1.1}/tests/conftest.py +0 -0
  44. {simplutils-0.1.0 → simplutils-0.1.1}/tests/test_ai_tools.py +0 -0
  45. {simplutils-0.1.0 → simplutils-0.1.1}/tests/test_data_tools.py +0 -0
  46. {simplutils-0.1.0 → simplutils-0.1.1}/tests/test_features.py +0 -0
  47. {simplutils-0.1.0 → simplutils-0.1.1}/tests/test_more_tools.py +0 -0
  48. {simplutils-0.1.0 → simplutils-0.1.1}/tests/test_tools.py +0 -0
@@ -1,12 +1,14 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: simplutils
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Developer utilities for Base64, hashing, JSON/YAML/CSV, JWT, PDFs, images, QR codes, PII redaction and opt-in AI summaries, JSON extraction and classification via Ollama or OpenAI-compatible APIs. Library, CLI, interactive menu and local web UI.
5
- Project-URL: Homepage, https://github.com/Santhanakrishnan2004/simpl_utils
5
+ Project-URL: Homepage, https://simplutils.santhanakrishnan.dev
6
+ Project-URL: Documentation, https://simplutils.santhanakrishnan.dev
6
7
  Project-URL: Repository, https://github.com/Santhanakrishnan2004/simpl_utils
7
8
  Project-URL: Issues, https://github.com/Santhanakrishnan2004/simpl_utils/issues
9
+ Project-URL: Changelog, https://github.com/Santhanakrishnan2004/simpl_utils/releases
8
10
  Author: Santhana Krishnan
9
- License: MIT
11
+ License-Expression: MIT
10
12
  License-File: LICENSE
11
13
  Keywords: ai,base64,cli,image,json,jwt,llm,pdf,pii,qr,redaction,toolbox,utilities,yaml
12
14
  Classifier: Development Status :: 4 - Beta
@@ -51,13 +53,15 @@ one: they use local Ollama by default, or send the text to the remote endpoint y
51
53
  - Zero required dependencies (AI uses Python's standard library; image/PDF/YAML/QR/UI features are optional extras)
52
54
  - Friendly errors, typo suggestions, and a privacy-respecting log
53
55
 
54
- After the first PyPI release, install it with `python -m pip install simplutils`. See
55
- [PUBLISHING.md](PUBLISHING.md) to publish the source on GitHub and release the package to PyPI.
56
+ **Current PyPI release:** `0.1.0` · **Next package version:** `0.1.1` (UI improvements; not yet
57
+ published).
56
58
 
57
- This README includes a quick command example for every current utility. More detailed guides are
58
- planned for [simplutils.santhanakrishnan.dev](https://simplutils.santhanakrishnan.dev) (coming soon).
59
- AI/LLM tools include summarization, JSON extraction, and classification. Each has examples and
60
- provider/privacy notes below; the planned docs site will add more detailed guides.
59
+ Install the current release with `python -m pip install simplutils`. Browse the
60
+ [simplutils documentation site](https://simplutils.santhanakrishnan.dev) for the full tool catalog,
61
+ copy-ready CLI and Python examples, and interactive browser demos.
62
+
63
+ This README also includes quick examples for every current utility. AI/LLM tools include
64
+ summarization, JSON extraction, and classification; their provider and privacy notes are below.
61
65
 
62
66
  ---
63
67
 
@@ -75,7 +79,7 @@ provider/privacy notes below; the planned docs site will add more detailed guide
75
79
  10. [PII redaction: what it does and doesn't do](#10-pii-redaction-what-it-does-and-doesnt-do)
76
80
  11. [Troubleshooting and FAQ](#11-troubleshooting-and-faq)
77
81
  12. [Extending: add your own tool](#12-extending-add-your-own-tool)
78
- 13. [Development and releasing](#13-development-and-releasing)
82
+ 13. [Contributing and reporting issues](#13-contributing-and-reporting-issues)
79
83
 
80
84
  ---
81
85
 
@@ -889,14 +893,18 @@ simplutils ui --port 9000 # another port
889
893
  simplutils ui --no-browser # don't open a browser window
890
894
  ```
891
895
 
892
- A searchable sidebar lists every tool. Type or paste into the input box and the result updates
893
- live; options appear as drop-downs and switches. File tools have an upload box (with an image
894
- preview), multi-file tools take several uploads in order, and tools that make files show a
895
- **Download file** button. There is a dark-mode toggle.
896
+ A refreshed, searchable sidebar groups the tools and shows the active tool. Choose a tool, enter
897
+ text or upload files, set any options, and select **Run tool** to execute it. The UI does not run
898
+ automatically as you type; this avoids repeated calls to AI providers while editing a prompt.
899
+
900
+ The output panel includes **Copy** and, for generated files, **Download** controls. Image inputs
901
+ and generated images can be previewed, multiple files are listed in upload order, and **Reset**
902
+ clears the input and restores option defaults. The layout adapts to smaller screens, includes a
903
+ dark-mode toggle, and links to the full docs site.
896
904
 
897
- It runs a small server **on your own machine only**: nothing is hosted. Regular tools process data
898
- locally; AI tools follow the provider and endpoint you select, as described in the AI section.
899
- Use the search box at the top of the sidebar to find any tool.
905
+ It runs a small server bound to `127.0.0.1` on your own machine; nothing is hosted. Regular tools
906
+ process data locally; AI tools follow the provider and endpoint you select, as described in the AI
907
+ section. Use the search box at the top of the sidebar to find any tool.
900
908
 
901
909
  ---
902
910
 
@@ -1049,15 +1057,47 @@ Rules:
1049
1057
 
1050
1058
  ---
1051
1059
 
1052
- ## 13. Development and releasing
1060
+ ## 13. Contributing and reporting issues
1061
+
1062
+ The project is open source under the MIT license. Contributions, bug reports, and practical feature
1063
+ ideas are welcome.
1064
+
1065
+ ### Report a bug or request a feature
1066
+
1067
+ Open an [issue on GitHub](https://github.com/Santhanakrishnan2004/simpl_utils/issues/new). Before
1068
+ creating one, search existing issues to avoid duplicates.
1069
+
1070
+ - **Bug report:** include your OS, Python and simplutils versions, the command or API call, the
1071
+ smallest input that reproduces the problem, what you expected, and what happened. Include the
1072
+ complete error message, but remove API keys, passwords, personal information, and sensitive files.
1073
+ - **Feature request:** describe the task you want to accomplish, how you currently handle it, and
1074
+ an example of the input and useful output. For AI tools, note the provider and model only—never
1075
+ include credentials or private prompts.
1076
+ - **Security issue:** do not post credentials or exploitable details in a public issue. Use GitHub's
1077
+ private vulnerability reporting for this repository if it is enabled.
1078
+
1079
+ ### Contribute a change
1080
+
1081
+ 1. Fork the repository and create a branch for your change.
1082
+ 2. Set up a development environment and run the test suite:
1053
1083
 
1054
1084
  ```bash
1055
- pip install -e ".[all,dev]" # editable install with everything
1056
- python -m pytest # run the tests
1057
- python examples/library_tour.py # try the examples
1085
+ python -m venv .venv
1086
+ python -m pip install -e ".[all,dev]"
1087
+ python -m pytest
1088
+ python examples/library_tour.py
1058
1089
  ```
1059
1090
 
1060
- Project layout:
1091
+ 3. Keep changes focused. For a new utility, follow the `@tool` pattern in `src/simplutils/tools/`,
1092
+ register its module in `src/simplutils/tools/__init__.py`, add focused tests, and document its
1093
+ CLI and Python usage in the README.
1094
+ 4. Open a pull request against `main`. Explain the problem and solution, link any related issue, and
1095
+ include the test results.
1096
+
1097
+ For general usage help, see the [documentation site](https://simplutils.santhanakrishnan.dev).
1098
+ For package installation and optional extras, see [Install](#1-install).
1099
+
1100
+ ### Project layout
1061
1101
 
1062
1102
  ```text
1063
1103
  src/simplutils/
@@ -1072,9 +1112,8 @@ tests/ pytest tests
1072
1112
  examples/ runnable tours and sample data
1073
1113
  ```
1074
1114
 
1075
- To publish the source on GitHub and make `python -m pip install simplutils` available to everyone,
1076
- follow **[PUBLISHING.md](PUBLISHING.md)**. The PyPI install command works after the first successful
1077
- release; until then, install from the project folder with `python -m pip install -e .`.
1115
+ The package is available from [PyPI](https://pypi.org/project/simplutils/). For current usage
1116
+ guides, visit the [simplutils documentation site](https://simplutils.santhanakrishnan.dev).
1078
1117
 
1079
1118
  ## License
1080
1119
 
@@ -12,13 +12,15 @@ one: they use local Ollama by default, or send the text to the remote endpoint y
12
12
  - Zero required dependencies (AI uses Python's standard library; image/PDF/YAML/QR/UI features are optional extras)
13
13
  - Friendly errors, typo suggestions, and a privacy-respecting log
14
14
 
15
- After the first PyPI release, install it with `python -m pip install simplutils`. See
16
- [PUBLISHING.md](PUBLISHING.md) to publish the source on GitHub and release the package to PyPI.
15
+ **Current PyPI release:** `0.1.0` · **Next package version:** `0.1.1` (UI improvements; not yet
16
+ published).
17
17
 
18
- This README includes a quick command example for every current utility. More detailed guides are
19
- planned for [simplutils.santhanakrishnan.dev](https://simplutils.santhanakrishnan.dev) (coming soon).
20
- AI/LLM tools include summarization, JSON extraction, and classification. Each has examples and
21
- provider/privacy notes below; the planned docs site will add more detailed guides.
18
+ Install the current release with `python -m pip install simplutils`. Browse the
19
+ [simplutils documentation site](https://simplutils.santhanakrishnan.dev) for the full tool catalog,
20
+ copy-ready CLI and Python examples, and interactive browser demos.
21
+
22
+ This README also includes quick examples for every current utility. AI/LLM tools include
23
+ summarization, JSON extraction, and classification; their provider and privacy notes are below.
22
24
 
23
25
  ---
24
26
 
@@ -36,7 +38,7 @@ provider/privacy notes below; the planned docs site will add more detailed guide
36
38
  10. [PII redaction: what it does and doesn't do](#10-pii-redaction-what-it-does-and-doesnt-do)
37
39
  11. [Troubleshooting and FAQ](#11-troubleshooting-and-faq)
38
40
  12. [Extending: add your own tool](#12-extending-add-your-own-tool)
39
- 13. [Development and releasing](#13-development-and-releasing)
41
+ 13. [Contributing and reporting issues](#13-contributing-and-reporting-issues)
40
42
 
41
43
  ---
42
44
 
@@ -850,14 +852,18 @@ simplutils ui --port 9000 # another port
850
852
  simplutils ui --no-browser # don't open a browser window
851
853
  ```
852
854
 
853
- A searchable sidebar lists every tool. Type or paste into the input box and the result updates
854
- live; options appear as drop-downs and switches. File tools have an upload box (with an image
855
- preview), multi-file tools take several uploads in order, and tools that make files show a
856
- **Download file** button. There is a dark-mode toggle.
855
+ A refreshed, searchable sidebar groups the tools and shows the active tool. Choose a tool, enter
856
+ text or upload files, set any options, and select **Run tool** to execute it. The UI does not run
857
+ automatically as you type; this avoids repeated calls to AI providers while editing a prompt.
858
+
859
+ The output panel includes **Copy** and, for generated files, **Download** controls. Image inputs
860
+ and generated images can be previewed, multiple files are listed in upload order, and **Reset**
861
+ clears the input and restores option defaults. The layout adapts to smaller screens, includes a
862
+ dark-mode toggle, and links to the full docs site.
857
863
 
858
- It runs a small server **on your own machine only**: nothing is hosted. Regular tools process data
859
- locally; AI tools follow the provider and endpoint you select, as described in the AI section.
860
- Use the search box at the top of the sidebar to find any tool.
864
+ It runs a small server bound to `127.0.0.1` on your own machine; nothing is hosted. Regular tools
865
+ process data locally; AI tools follow the provider and endpoint you select, as described in the AI
866
+ section. Use the search box at the top of the sidebar to find any tool.
861
867
 
862
868
  ---
863
869
 
@@ -1010,15 +1016,47 @@ Rules:
1010
1016
 
1011
1017
  ---
1012
1018
 
1013
- ## 13. Development and releasing
1019
+ ## 13. Contributing and reporting issues
1020
+
1021
+ The project is open source under the MIT license. Contributions, bug reports, and practical feature
1022
+ ideas are welcome.
1023
+
1024
+ ### Report a bug or request a feature
1025
+
1026
+ Open an [issue on GitHub](https://github.com/Santhanakrishnan2004/simpl_utils/issues/new). Before
1027
+ creating one, search existing issues to avoid duplicates.
1028
+
1029
+ - **Bug report:** include your OS, Python and simplutils versions, the command or API call, the
1030
+ smallest input that reproduces the problem, what you expected, and what happened. Include the
1031
+ complete error message, but remove API keys, passwords, personal information, and sensitive files.
1032
+ - **Feature request:** describe the task you want to accomplish, how you currently handle it, and
1033
+ an example of the input and useful output. For AI tools, note the provider and model only—never
1034
+ include credentials or private prompts.
1035
+ - **Security issue:** do not post credentials or exploitable details in a public issue. Use GitHub's
1036
+ private vulnerability reporting for this repository if it is enabled.
1037
+
1038
+ ### Contribute a change
1039
+
1040
+ 1. Fork the repository and create a branch for your change.
1041
+ 2. Set up a development environment and run the test suite:
1014
1042
 
1015
1043
  ```bash
1016
- pip install -e ".[all,dev]" # editable install with everything
1017
- python -m pytest # run the tests
1018
- python examples/library_tour.py # try the examples
1044
+ python -m venv .venv
1045
+ python -m pip install -e ".[all,dev]"
1046
+ python -m pytest
1047
+ python examples/library_tour.py
1019
1048
  ```
1020
1049
 
1021
- Project layout:
1050
+ 3. Keep changes focused. For a new utility, follow the `@tool` pattern in `src/simplutils/tools/`,
1051
+ register its module in `src/simplutils/tools/__init__.py`, add focused tests, and document its
1052
+ CLI and Python usage in the README.
1053
+ 4. Open a pull request against `main`. Explain the problem and solution, link any related issue, and
1054
+ include the test results.
1055
+
1056
+ For general usage help, see the [documentation site](https://simplutils.santhanakrishnan.dev).
1057
+ For package installation and optional extras, see [Install](#1-install).
1058
+
1059
+ ### Project layout
1022
1060
 
1023
1061
  ```text
1024
1062
  src/simplutils/
@@ -1033,9 +1071,8 @@ tests/ pytest tests
1033
1071
  examples/ runnable tours and sample data
1034
1072
  ```
1035
1073
 
1036
- To publish the source on GitHub and make `python -m pip install simplutils` available to everyone,
1037
- follow **[PUBLISHING.md](PUBLISHING.md)**. The PyPI install command works after the first successful
1038
- release; until then, install from the project folder with `python -m pip install -e .`.
1074
+ The package is available from [PyPI](https://pypi.org/project/simplutils/). For current usage
1075
+ guides, visit the [simplutils documentation site](https://simplutils.santhanakrishnan.dev).
1039
1076
 
1040
1077
  ## License
1041
1078
 
@@ -8,7 +8,7 @@ dynamic = ["version"] # single source of truth: __version__ in src/simplutils/_
8
8
  description = "Developer utilities for Base64, hashing, JSON/YAML/CSV, JWT, PDFs, images, QR codes, PII redaction and opt-in AI summaries, JSON extraction and classification via Ollama or OpenAI-compatible APIs. Library, CLI, interactive menu and local web UI."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
11
- license = { text = "MIT" }
11
+ license = "MIT"
12
12
  authors = [{ name = "Santhana Krishnan" }]
13
13
  keywords = ["utilities", "ai", "llm", "base64", "pdf", "image", "json", "yaml", "jwt", "qr", "pii", "redaction", "cli", "toolbox"]
14
14
  classifiers = [
@@ -23,9 +23,11 @@ classifiers = [
23
23
  dependencies = []
24
24
 
25
25
  [project.urls]
26
- Homepage = "https://github.com/Santhanakrishnan2004/simpl_utils"
26
+ Homepage = "https://simplutils.santhanakrishnan.dev"
27
+ Documentation = "https://simplutils.santhanakrishnan.dev"
27
28
  Repository = "https://github.com/Santhanakrishnan2004/simpl_utils"
28
29
  Issues = "https://github.com/Santhanakrishnan2004/simpl_utils/issues"
30
+ Changelog = "https://github.com/Santhanakrishnan2004/simpl_utils/releases"
29
31
 
30
32
  [project.optional-dependencies]
31
33
  ui = ["nicegui>=3.0"]
@@ -44,7 +46,7 @@ path = "src/simplutils/__init__.py"
44
46
  packages = ["src/simplutils"]
45
47
 
46
48
  [tool.hatch.build.targets.sdist]
47
- include = ["src", "tests", "examples", "README.md", "PUBLISHING.md", "LICENSE", "pyproject.toml"]
49
+ include = ["src", "tests", "examples", "README.md", "LICENSE", "pyproject.toml"]
48
50
 
49
51
  [tool.pytest.ini_options]
50
52
  testpaths = ["tests"]
@@ -31,4 +31,4 @@ from .tools.jwt import jwt_decode # noqa: E402
31
31
  from .tools.text import case_convert, count, slugify # noqa: E402
32
32
  from .tools.timetools import date_to_ts, now, ts_to_date # noqa: E402
33
33
 
34
- __version__ = "0.1.0"
34
+ __version__ = "0.1.1"
@@ -0,0 +1,368 @@
1
+ """Local web UI (NiceGUI), generated from the tool registry. Runs entirely on localhost."""
2
+ from __future__ import annotations
3
+
4
+ import asyncio
5
+ import base64
6
+ import inspect
7
+ import json
8
+
9
+ from nicegui import ui
10
+
11
+ from . import __version__
12
+ from .logs import setup_logging
13
+ from .registry import FileResult, Tool, groups, load_all
14
+ from .tools.files import detect_image
15
+
16
+ DOCS_URL = "https://simplutils.santhanakrishnan.dev"
17
+
18
+
19
+ def _data_uri(data: bytes, mime: str) -> str:
20
+ return f"data:{mime};base64,{base64.b64encode(data).decode()}"
21
+
22
+
23
+ def _tool_panel(t: Tool) -> None:
24
+ values = {p.name: (None if p.required else p.default) for p in t.params}
25
+ refs = {}
26
+ state = {"bytes": None, "result": None, "files": [], "names": [], "running": False}
27
+
28
+ def clear_result() -> None:
29
+ state["result"] = None
30
+ refs["output"].value = ""
31
+ refs["download"].set_visibility(False)
32
+ refs["copy"].set_visibility(False)
33
+ refs["preview"].clear()
34
+ refs["status"].text = "Ready when you are."
35
+
36
+ def reset() -> None:
37
+ clear_result()
38
+ state["bytes"] = None
39
+ state["files"].clear()
40
+ state["names"].clear()
41
+ if t.input_kind == "text":
42
+ refs["input"].value = ""
43
+ refs["counter"].text = "0 characters"
44
+ elif t.input_kind in ("file", "files"):
45
+ refs["upload"].reset()
46
+ refs["filename"].text = "No files selected"
47
+ for param in t.params:
48
+ values[param.name] = None if param.required else param.default
49
+ if param.name in refs["options"]:
50
+ refs["options"][param.name].value = values[param.name]
51
+
52
+ def clear_files() -> None:
53
+ state["bytes"] = None
54
+ state["files"].clear()
55
+ state["names"].clear()
56
+ refs["upload"].reset()
57
+ refs["filename"].text = "No files selected"
58
+ clear_result()
59
+
60
+ async def execute(*_) -> None:
61
+ if state["running"]:
62
+ return
63
+ if t.input_kind == "file":
64
+ data = state["bytes"]
65
+ if data is None:
66
+ refs["status"].text = "Choose a file before running this tool."
67
+ return
68
+ elif t.input_kind == "files":
69
+ data = state["files"]
70
+ if not data:
71
+ refs["status"].text = "Choose one or more files before running this tool."
72
+ return
73
+ elif t.input_kind == "text":
74
+ data = refs["input"].value
75
+ if not data:
76
+ refs["status"].text = "Enter some text before running this tool."
77
+ return
78
+ else:
79
+ data = None
80
+
81
+ state["running"] = True
82
+ refs["run"].set_enabled(False)
83
+ refs["status"].text = "Working…"
84
+ refs["output"].value = ""
85
+ refs["download"].set_visibility(False)
86
+ refs["copy"].set_visibility(False)
87
+ refs["preview"].clear()
88
+ try:
89
+ result = await asyncio.to_thread(t.run, data, **values)
90
+ except Exception as e: # Render tool errors without breaking the local UI.
91
+ refs["status"].text = "The tool could not complete."
92
+ refs["output"].value = f"Error: {e}"
93
+ else:
94
+ refs["status"].text = "Done"
95
+ refs["copy"].set_visibility(True)
96
+ if isinstance(result, FileResult):
97
+ state["result"] = result
98
+ refs["output"].value = f"{result.filename} · {len(result.data):,} bytes"
99
+ refs["download"].set_visibility(True)
100
+ if result.mime.startswith("image/"):
101
+ with refs["preview"]:
102
+ ui.image(_data_uri(result.data, result.mime)).classes(
103
+ "max-h-96 max-w-full rounded-xl border border-slate-200 object-contain "
104
+ "dark:border-slate-700"
105
+ )
106
+ else:
107
+ refs["output"].value = result
108
+ finally:
109
+ state["running"] = False
110
+ refs["run"].set_enabled(True)
111
+
112
+ async def on_upload(e) -> None:
113
+ data = e.file.read()
114
+ if inspect.isawaitable(data):
115
+ data = await data
116
+ clear_result()
117
+ if t.input_kind == "files":
118
+ state["files"].append(data)
119
+ state["names"].append(e.file.name)
120
+ refs["filename"].text = (
121
+ f"{len(state['names'])} file(s): " + ", ".join(state["names"])
122
+ )
123
+ else:
124
+ state["bytes"] = data
125
+ refs["filename"].text = f"{e.file.name} · {len(data):,} bytes"
126
+ kind = detect_image(data)
127
+ if kind:
128
+ with refs["preview"]:
129
+ ui.image(_data_uri(data, kind[0])).classes(
130
+ "max-h-96 max-w-full rounded-xl border border-slate-200 object-contain "
131
+ "dark:border-slate-700"
132
+ )
133
+
134
+ def copy_output() -> None:
135
+ value = refs["output"].value
136
+ if value:
137
+ ui.run_javascript(f"navigator.clipboard.writeText({json.dumps(value)})")
138
+ ui.notify("Output copied", type="positive")
139
+
140
+ def download() -> None:
141
+ result = state["result"]
142
+ if result is not None:
143
+ ui.download(result.data, result.filename, result.mime)
144
+
145
+ with ui.card().classes("w-full rounded-2xl border border-slate-200 shadow-sm dark:border-slate-700"):
146
+ with ui.row().classes("w-full items-start justify-between gap-4"):
147
+ with ui.column().classes("min-w-0 gap-1"):
148
+ ui.label(t.title).classes("text-2xl font-bold tracking-tight")
149
+ ui.label(t.description).classes("text-sm text-slate-500 dark:text-slate-400")
150
+ ui.badge(t.group).props("outline color=primary").classes("shrink-0")
151
+
152
+ if t.input_kind == "text":
153
+ refs["input"] = ui.textarea(
154
+ "Input", placeholder="Type or paste your text here..."
155
+ ).props("outlined autogrow").classes("w-full")
156
+ refs["counter"] = ui.label("0 characters").classes(
157
+ "self-end text-xs text-slate-500 dark:text-slate-400"
158
+ )
159
+
160
+ def update_counter(e) -> None:
161
+ length = len(e.value or "")
162
+ refs["counter"].text = f"{length:,} character(s)"
163
+ clear_result()
164
+
165
+ refs["input"].on_value_change(update_counter)
166
+ elif t.input_kind in ("file", "files"):
167
+ multi = t.input_kind == "files"
168
+ refs["upload"] = ui.upload(
169
+ label="Drop files here or browse" if multi else "Drop a file here or browse",
170
+ multiple=multi,
171
+ auto_upload=True,
172
+ on_upload=on_upload,
173
+ ).classes("w-full")
174
+ refs["filename"] = ui.label("No files selected").classes(
175
+ "text-sm text-slate-500 dark:text-slate-400"
176
+ )
177
+ if multi:
178
+ ui.button(
179
+ "Clear selected files", on_click=clear_files, icon="delete_outline"
180
+ ).props("flat dense no-caps")
181
+
182
+ if t.params:
183
+ ui.separator().classes("my-1")
184
+ ui.label("Options").classes("text-sm font-semibold uppercase tracking-wide text-slate-500")
185
+ with ui.row().classes("w-full flex-wrap items-end gap-3"):
186
+ refs["options"] = {}
187
+ for param in t.params:
188
+ label = param.name.replace("_", " ")
189
+ if param.required:
190
+ label += " *"
191
+ if param.choices:
192
+ control = ui.select(
193
+ list(param.choices),
194
+ value=None if param.required else param.default,
195
+ label=label,
196
+ )
197
+ elif param.type is bool:
198
+ control = ui.switch(label, value=param.default)
199
+ elif param.type is int:
200
+ control = ui.number(
201
+ label,
202
+ value=None if param.required else param.default,
203
+ precision=0,
204
+ )
205
+ else:
206
+ control = ui.input(
207
+ label,
208
+ value="" if param.required else param.default,
209
+ )
210
+ refs["options"][param.name] = control
211
+
212
+ def update_option(e, name=param.name, value_type=param.type) -> None:
213
+ value = e.value
214
+ if value_type is int and value is not None:
215
+ value = int(value)
216
+ values[name] = value
217
+ clear_result()
218
+
219
+ control.on_value_change(update_option)
220
+
221
+ ui.separator().classes("my-1")
222
+ with ui.row().classes("w-full items-center gap-2"):
223
+ refs["run"] = ui.button(
224
+ "Run tool", on_click=execute, icon="play_arrow"
225
+ ).props("unelevated no-caps").classes("px-4")
226
+ ui.button("Reset", on_click=reset, icon="restart_alt").props(
227
+ "flat no-caps"
228
+ )
229
+ refs["status"] = ui.label("Ready when you are.").classes(
230
+ "ml-auto text-sm text-slate-500 dark:text-slate-400"
231
+ )
232
+
233
+ with ui.card().classes("mt-4 w-full rounded-2xl border border-slate-200 shadow-sm dark:border-slate-700"):
234
+ with ui.row().classes("w-full items-center justify-between"):
235
+ with ui.column().classes("gap-0"):
236
+ ui.label("Output").classes("text-lg font-semibold")
237
+ ui.label("Your result will appear here.").classes(
238
+ "text-xs text-slate-500 dark:text-slate-400"
239
+ )
240
+ with ui.row().classes("gap-2"):
241
+ refs["copy"] = ui.button(
242
+ "Copy", on_click=copy_output, icon="content_copy"
243
+ ).props("outline no-caps")
244
+ refs["download"] = ui.button(
245
+ "Download", on_click=download, icon="download"
246
+ ).props("outline color=positive no-caps")
247
+ refs["output"] = ui.textarea().props(
248
+ "outlined readonly autogrow input-class=font-mono"
249
+ ).classes("w-full")
250
+ refs["preview"] = ui.column().classes("w-full items-center")
251
+ refs["copy"].set_visibility(False)
252
+ refs["download"].set_visibility(False)
253
+
254
+
255
+ def run(port: int = 8080, show: bool = True) -> None:
256
+ setup_logging()
257
+ all_tools = load_all()
258
+ default_tool = "b64-encode" if "b64-encode" in all_tools else next(iter(all_tools))
259
+ state = {"tool": default_tool, "query": ""}
260
+ tool_groups = groups()
261
+
262
+ @ui.page("/")
263
+ def index() -> None:
264
+ dark = ui.dark_mode(False)
265
+
266
+ ui.add_head_html(
267
+ """
268
+ <style>
269
+ body { background: #f8fafc; }
270
+ .dark body { background: #0f172a; }
271
+ .q-drawer { border-right: 1px solid rgba(148, 163, 184, .2); }
272
+ .q-field__control { border-radius: 12px; }
273
+ .q-btn { border-radius: 10px; }
274
+ </style>
275
+ """
276
+ )
277
+
278
+ @ui.refreshable
279
+ def nav() -> None:
280
+ query = state["query"].strip().lower()
281
+ for group_name, tools in tool_groups.items():
282
+ matches = [
283
+ tool for tool in tools
284
+ if not query
285
+ or query in group_name.lower()
286
+ or query in tool.title.lower()
287
+ or query in tool.name.lower()
288
+ or query in tool.description.lower()
289
+ ]
290
+ if not matches:
291
+ continue
292
+ with ui.expansion(
293
+ f"{group_name} · {len(matches)}",
294
+ icon="folder_open",
295
+ value=any(tool.name == state["tool"] for tool in matches),
296
+ ).classes("w-full"):
297
+ for tool in matches:
298
+ active = tool.name == state["tool"]
299
+ ui.button(
300
+ tool.title,
301
+ on_click=lambda tool=tool: select(tool.name),
302
+ ).props(
303
+ "flat no-caps align=left "
304
+ + ("color=primary" if active else "color=grey-8")
305
+ ).classes("w-full justify-start")
306
+
307
+ @ui.refreshable
308
+ def panel() -> None:
309
+ with ui.column().classes("mx-auto w-full max-w-5xl gap-4 p-4 md:p-8"):
310
+ with ui.row().classes("items-center gap-2 text-sm text-slate-500 dark:text-slate-400"):
311
+ ui.label("Toolbox")
312
+ ui.icon("chevron_right").classes("text-base")
313
+ ui.label(all_tools[state["tool"]].group)
314
+ _tool_panel(all_tools[state["tool"]])
315
+
316
+ def select(name: str) -> None:
317
+ state["tool"] = name
318
+ nav.refresh()
319
+ panel.refresh()
320
+
321
+ def search(e) -> None:
322
+ state["query"] = e.value or ""
323
+ nav.refresh()
324
+
325
+ page_refs = {}
326
+ with ui.header().classes("items-center justify-between border-b border-slate-200 bg-white px-4 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-white"):
327
+ with ui.row().classes("items-center gap-3"):
328
+ ui.button(
329
+ icon="menu",
330
+ on_click=lambda: page_refs["drawer"].toggle(),
331
+ ).props("flat round").classes("md:hidden")
332
+ ui.icon("handyman").classes("text-2xl text-primary")
333
+ with ui.column().classes("gap-0"):
334
+ ui.label("simplutils").classes("text-lg font-bold leading-tight")
335
+ ui.label(f"Developer toolbox · v{__version__}").classes(
336
+ "text-xs opacity-70"
337
+ )
338
+ with ui.row().classes("items-center gap-2"):
339
+ ui.link("Documentation", DOCS_URL, new_tab=True).classes(
340
+ "text-sm font-medium text-primary no-underline"
341
+ )
342
+ ui.button(icon="dark_mode", on_click=dark.toggle).props(
343
+ "flat round"
344
+ ).tooltip("Toggle dark mode")
345
+
346
+ with ui.left_drawer(fixed=True).props("width=280") as drawer:
347
+ page_refs["drawer"] = drawer
348
+ drawer.classes(
349
+ "bg-white p-3 dark:bg-slate-900"
350
+ )
351
+ ui.input(
352
+ placeholder="Search tools...",
353
+ on_change=search,
354
+ ).props("outlined dense clearable").classes("mb-3 w-full")
355
+ with ui.scroll_area().classes("h-[calc(100vh-7rem)] w-full"):
356
+ nav()
357
+
358
+ with ui.column().classes("w-full"):
359
+ panel()
360
+
361
+ ui.run(
362
+ title="simplutils",
363
+ port=port,
364
+ show=show,
365
+ reload=False,
366
+ favicon="🧰",
367
+ host="127.0.0.1",
368
+ )
@@ -1,265 +0,0 @@
1
- # Packaging and publishing simplutils
2
-
3
- How to turn this project into an installable package and, when you're ready, put it on PyPI
4
- (or share it privately). **Nothing in this guide has been uploaded anywhere**; the package has only
5
- been built and tested locally.
6
-
7
- ---
8
-
9
- ## 0. Pick how you want to share it
10
-
11
- | Goal | Method | Needs an account? |
12
- |---|---|---|
13
- | Publish the source / install directly from GitHub | **GitHub** (section 1) | GitHub |
14
- | Try it yourself / a few colleagues | **Share the wheel file** (section 5) | No |
15
- | Your company / team only | **Private package feed** (section 9) | Your company's feed |
16
- | Everyone: `pip install simplutils` | **PyPI** (sections 6-8) | Yes, free |
17
-
18
- You can do them in that order. Starting with the wheel file costs nothing and commits you to nothing.
19
-
20
- ---
21
-
22
- ## 1. Publish the source to GitHub
23
-
24
- 1. Sign in to GitHub and create a **new public repository** named `simpl_utils`. Do not initialize it
25
- with a README, license, or `.gitignore`; those files already exist in this project.
26
- 2. Open PowerShell in this project folder (the folder containing `pyproject.toml`) and run:
27
-
28
- ```powershell
29
- git init
30
- git add .
31
- git commit -m "Initial release of simplutils"
32
- git branch -M main
33
- git remote add origin https://github.com/Santhanakrishnan2004/simpl_utils.git
34
- git push -u origin main
35
- ```
36
-
37
- If Git asks, configure your commit name and email with `git config --global user.name "Your Name"` and
38
- `git config --global user.email "you@example.com"`. GitHub will prompt you to authenticate when
39
- you push; do not put a password or access token in the remote URL. Use `main` exactly (not `mai`)
40
- as the branch name.
41
- 3. Check that the README and source files appear on the repository page. The GitHub project links
42
- are already configured in `pyproject.toml`. Anyone can install the current GitHub version with:
43
-
44
- ```powershell
45
- python -m pip install "git+https://github.com/Santhanakrishnan2004/simpl_utils.git"
46
- ```
47
-
48
- This installs from GitHub, not from PyPI. For the shorter, registry-based `pip install simplutils`
49
- command, continue with the PyPI release steps below.
50
-
51
- ---
52
-
53
- ## 2. Before the first release
54
-
55
- 1. **Name.** Check whether the `simplutils` distribution name is available immediately before
56
- releasing; names are only reserved when you upload:
57
- ```bash
58
- python -m pip index versions simplutils
59
- ```
60
- If a version is listed, the project name is already in use. If no matching distribution is found,
61
- still confirm the project name is available on PyPI before you build and upload.
62
- 2. **Licence.** `LICENSE` is MIT with the holder "simplutils contributors". Change the licence or the
63
- holder name if you want something else (for company work, check what your employer requires).
64
- 3. **Author and links** (optional but recommended). In `pyproject.toml`, add an `authors` entry.
65
- The `[project.urls]` links were configured in section 1. Use only details you're happy to make public.
66
- Anything in `pyproject.toml` and `README.md` becomes **public on PyPI** and cannot be edited
67
- for that version afterwards.
68
- 4. **Version.** It lives in one place: `__version__` in `src/simplutils/__init__.py`.
69
-
70
- ---
71
-
72
- ## 3. Set up a clean build environment
73
-
74
- Use a virtual environment so the build tools don't disturb your other Python projects
75
- (they can conflict with other installed packages).
76
-
77
- ```bash
78
- # Windows PowerShell
79
- python -m venv .venv-build
80
- .venv-build\Scripts\Activate.ps1
81
- python -m pip install --upgrade build twine
82
-
83
- # macOS / Linux / Git Bash
84
- python -m venv .venv-build
85
- source .venv-build/bin/activate # Git Bash on Windows: source .venv-build/Scripts/activate
86
- python -m pip install --upgrade build twine
87
- ```
88
-
89
- ---
90
-
91
- ## 4. Build
92
-
93
- From the project folder (the one containing `pyproject.toml`):
94
-
95
- ```bash
96
- python -m build
97
- ```
98
-
99
- This creates two files in `dist/`:
100
-
101
- | File | What it is |
102
- |---|---|
103
- | `simplutils-0.1.0-py3-none-any.whl` | The **wheel**: what `pip install` normally uses |
104
- | `simplutils-0.1.0.tar.gz` | The **source archive** (sdist): for people who build from source |
105
-
106
- Check them:
107
-
108
- ```bash
109
- twine check dist/* # both should say PASSED (validates the README renders on PyPI)
110
- ```
111
-
112
- Delete the `dist/` folder before every new build so old files aren't uploaded by accident.
113
-
114
- ---
115
-
116
- ## 5. Test the build in a clean environment (do this every time)
117
-
118
- This proves the *built package* works, not just your source folder.
119
-
120
- ```bash
121
- python -m venv .venv-test
122
- .venv-test\Scripts\Activate.ps1 # (bash: source .venv-test/bin/activate)
123
-
124
- pip install dist/simplutils-0.1.0-py3-none-any.whl # core only
125
- simplutils --version
126
- simplutils b64-encode "it works"
127
-
128
- pip install "dist/simplutils-0.1.0-py3-none-any.whl[all]" # with all extras
129
- python examples/library_tour.py
130
- python examples/cli_tour.py
131
- ```
132
-
133
- **Sharing the wheel directly:** send `simplutils-0.1.0-py3-none-any.whl` to someone (email,
134
- shared drive, chat). They run:
135
-
136
- ```bash
137
- pip install simplutils-0.1.0-py3-none-any.whl # add [all] before the closing quote for extras:
138
- pip install "simplutils-0.1.0-py3-none-any.whl[all]"
139
- ```
140
-
141
- The extras download their dependencies (Pillow, pypdf, ...) from PyPI automatically.
142
-
143
- ---
144
-
145
- ## 6. Create your PyPI accounts (one time)
146
-
147
- 1. Register at <https://pypi.org/account/register/> and **enable two-factor authentication** (required).
148
- 2. Register separately at <https://test.pypi.org/account/register/>. **TestPyPI** is a practice
149
- server: uploads there are throwaway and don't affect the real index.
150
- 3. Create an **API token** on each site (Account settings → API tokens).
151
- - For the first upload, use scope "Entire account" (the project doesn't exist yet).
152
- - After the first release, create a new token **scoped to the `simplutils` project only**, and delete the broad one.
153
- 4. **Treat tokens like passwords.** Never put them in the project folder, in git, or in a chat.
154
- A token starts with `pypi-`.
155
-
156
- ---
157
-
158
- ## 7. Upload to TestPyPI first (practice run)
159
-
160
- ```bash
161
- twine upload --repository testpypi dist/*
162
- ```
163
-
164
- When prompted: username `__token__`, password = your **TestPyPI** token.
165
-
166
- Prefer not to type it? Set it for the current terminal only:
167
-
168
- ```powershell
169
- # PowerShell
170
- $env:TWINE_USERNAME = "__token__"
171
- $env:TWINE_PASSWORD = "pypi-xxxxxxxx"
172
- ```
173
- ```bash
174
- # bash
175
- export TWINE_USERNAME=__token__
176
- export TWINE_PASSWORD=pypi-xxxxxxxx
177
- ```
178
-
179
- Then install it from TestPyPI in a clean environment to see what a user would get:
180
-
181
- ```bash
182
- pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ simplutils
183
- simplutils --version
184
- ```
185
-
186
- (`--extra-index-url` lets pip fetch the dependencies, which live on the real PyPI.)
187
- Look at the project page that TestPyPI shows: the README, description and metadata are what
188
- visitors will see.
189
-
190
- ---
191
-
192
- ## 8. Upload to the real PyPI
193
-
194
- ```bash
195
- twine upload dist/*
196
- ```
197
-
198
- Username `__token__`, password = your **PyPI** token. Then, in a clean environment, as any user would:
199
-
200
- ```bash
201
- pip install simplutils
202
- pip install "simplutils[all]"
203
- simplutils --version
204
- ```
205
-
206
- Your package page will be at `https://pypi.org/project/simplutils/`.
207
-
208
- > **Uploads are permanent.** A version number can never be reused or replaced, even if you delete
209
- > the release. If you find a mistake, fix it, bump the version, and upload again. Always do the
210
- > TestPyPI practice run first.
211
-
212
- ### Releasing a new version later
213
-
214
- 1. Change `__version__` in `src/simplutils/__init__.py` (e.g. `0.1.0` → `0.1.1`).
215
- Use `MAJOR.MINOR.PATCH`: patch for fixes, minor for new tools, major for breaking changes.
216
- 2. Run the tests: `python -m pytest`.
217
- 3. Delete `dist/`, then `python -m build`, `twine check dist/*`.
218
- 4. Test in a clean environment (section 5), upload to TestPyPI (optional), then `twine upload dist/*`.
219
-
220
- ### Later: automatic publishing (recommended once it's in GitHub)
221
-
222
- PyPI supports **Trusted Publishing**, which lets a GitHub Actions workflow upload releases without
223
- any stored token. Set it up under your project's "Publishing" settings on PyPI, and use the
224
- `pypa/gh-action-pypi-publish` action. It's safer than tokens, but needs a repository first.
225
-
226
- ---
227
-
228
- ## 9. Sharing inside a company (private)
229
-
230
- If you don't want it public, there are good options:
231
-
232
- - **Share the wheel** (section 5). Simplest.
233
- - **A private package feed** (Azure Artifacts, JFrog Artifactory, Nexus, GitLab/GitHub package
234
- registry, or a self-hosted `devpi`). Your IT team will tell you which one exists. Upload with
235
- `twine upload --repository-url <feed-url> dist/*`, and install with
236
- `pip install --index-url <feed-url> simplutils`.
237
- - **Install straight from a git repository:** `pip install "git+https://<your-git-host>/<repo>.git"`.
238
- - **A standalone `.exe`** for people without Python is possible with tools like PyInstaller. That
239
- hasn't been set up or tested in this project.
240
-
241
- If you publish internally, the PyPI name clash no longer matters, but keeping the `simplutils` name
242
- means a later move to PyPI needs no code changes.
243
-
244
- ---
245
-
246
- ## 10. Pre-release checklist
247
-
248
- - [ ] `python -m pytest` passes
249
- - [ ] Version bumped in `src/simplutils/__init__.py`
250
- - [ ] `README.md` reads well (it is the PyPI front page)
251
- - [ ] No secrets, personal data or internal URLs in `pyproject.toml`, the README, or `examples/`
252
- - [ ] Old `dist/` deleted, fresh `python -m build`, `twine check dist/*` passes
253
- - [ ] Wheel tested in a **clean** environment (core and `[all]`)
254
- - [ ] TestPyPI practice upload looked right
255
- - [ ] Name still free (first release only)
256
-
257
- ## Troubleshooting
258
-
259
- | Problem | Cause / fix |
260
- |---|---|
261
- | `403 Invalid or non-existent authentication` | Wrong token, or a TestPyPI token used on PyPI (they're separate). Username must be exactly `__token__` |
262
- | `400 File already exists` | That version was already uploaded. Bump the version and rebuild |
263
- | `403 ... isn't allowed to upload to project` | The name belongs to someone else, or your token is scoped to a different project |
264
- | `twine check` fails on the README | Fix the Markdown, rebuild, re-check |
265
- | Dependency conflicts when installing the build tools | Use a virtual environment (section 3). This project's build tools need a newer `packaging` than some other global packages allow |
@@ -1,186 +0,0 @@
1
- """Local web UI (NiceGUI), generated from the tool registry. Runs entirely on localhost."""
2
- from __future__ import annotations
3
-
4
- import base64
5
- import inspect
6
- import json
7
-
8
- from nicegui import ui
9
-
10
- from .logs import setup_logging
11
- from .registry import FileResult, Tool, groups, load_all
12
- from .tools.files import detect_image
13
-
14
-
15
- def _data_uri(data: bytes, mime: str) -> str:
16
- return f"data:{mime};base64,{base64.b64encode(data).decode()}"
17
-
18
-
19
- def _tool_panel(t: Tool) -> None:
20
- values = {p.name: (None if p.required else p.default) for p in t.params}
21
- refs = {}
22
- state = {"bytes": None, "result": None, "files": [], "names": []}
23
-
24
- def show_preview(data: bytes, mime: str) -> None:
25
- refs["preview"].clear()
26
- if mime.startswith("image/"):
27
- with refs["preview"]:
28
- ui.image(_data_uri(data, mime)).classes("max-w-md border rounded")
29
-
30
- def run(*_) -> None:
31
- state["result"] = None
32
- refs["download"].set_visibility(False)
33
- try:
34
- if t.input_kind == "file":
35
- data = state["bytes"]
36
- if data is None:
37
- refs["output"].value = "Upload a file to begin."
38
- return
39
- elif t.input_kind == "files":
40
- data = state["files"]
41
- if not data:
42
- refs["output"].value = "Upload one or more files to begin (they are used in upload order)."
43
- return
44
- elif t.input_kind == "text":
45
- data = refs["input"].value
46
- if not data:
47
- refs["output"].value = ""
48
- return
49
- else:
50
- data = None
51
- result = t.run(data, **values)
52
- except Exception as e: # ToolError or anything unexpected
53
- refs["output"].value = f"Error: {e}"
54
- return
55
- if isinstance(result, FileResult):
56
- state["result"] = result
57
- refs["output"].value = f"Ready: {result.filename} ({len(result.data):,} bytes) - use Download"
58
- refs["download"].set_visibility(True)
59
- show_preview(result.data, result.mime)
60
- else:
61
- refs["output"].value = result
62
-
63
- async def on_upload(e) -> None:
64
- data = e.file.read()
65
- if inspect.isawaitable(data):
66
- data = await data
67
- if t.input_kind == "files":
68
- state["files"].append(data)
69
- state["names"].append(e.file.name)
70
- refs["filename"].text = "Files (in order): " + ", ".join(state["names"])
71
- run()
72
- return
73
- state["bytes"] = data
74
- refs["filename"].text = f"{e.file.name} ({len(data):,} bytes)"
75
- kind = detect_image(data)
76
- refs["preview"].clear()
77
- if kind:
78
- show_preview(data, kind[0])
79
- run()
80
-
81
- def clear_files() -> None:
82
- state["files"].clear()
83
- state["names"].clear()
84
- refs["upload"].reset()
85
- refs["filename"].text = ""
86
- run()
87
-
88
- ui.label(t.title).classes("text-2xl font-bold")
89
- ui.label(t.description).classes("text-gray-500")
90
-
91
- if t.input_kind == "text":
92
- refs["input"] = ui.textarea("Input", on_change=run).props("outlined autogrow").classes("w-full")
93
- elif t.input_kind in ("file", "files"):
94
- multi = t.input_kind == "files"
95
- refs["upload"] = ui.upload(
96
- label="Drop files here or click +" if multi else "Drop a file here or click +",
97
- multiple=multi, auto_upload=True, on_upload=on_upload,
98
- ).classes("w-full")
99
- refs["filename"] = ui.label("").classes("text-sm text-gray-500")
100
- if multi:
101
- ui.button("Clear files", on_click=clear_files, icon="delete").props("flat dense")
102
- refs["preview"] = ui.column()
103
-
104
- if t.params:
105
- with ui.row().classes("items-center gap-4"):
106
- for p in t.params:
107
- def setter(name):
108
- def _set(e):
109
- values[name] = e.value
110
- run()
111
- return _set
112
- label = p.name.replace("_", " ")
113
- if p.choices:
114
- ui.select(list(p.choices), value=p.default, label=label, on_change=setter(p.name))
115
- elif p.type is bool:
116
- ui.switch(label, value=False, on_change=setter(p.name))
117
- elif p.type is int:
118
- ui.number(label, value=None if p.required else p.default, precision=0,
119
- on_change=lambda e, n=p.name: (values.__setitem__(n, int(e.value) if e.value is not None else None), run()))
120
- else:
121
- ui.input(label, value="" if p.required else p.default, on_change=setter(p.name))
122
-
123
- refs["output"] = ui.textarea("Output").props("outlined readonly autogrow").classes("w-full")
124
-
125
- def copy() -> None:
126
- ui.run_javascript(f"navigator.clipboard.writeText({json.dumps(refs['output'].value)})")
127
- ui.notify("Copied", type="positive")
128
-
129
- def download() -> None:
130
- r = state["result"]
131
- if r is not None:
132
- ui.download(r.data, r.filename, r.mime)
133
-
134
- with ui.row():
135
- ui.button("Run", on_click=run, icon="play_arrow")
136
- ui.button("Copy output", on_click=copy, icon="content_copy").props("outline")
137
- refs["download"] = ui.button("Download file", on_click=download, icon="download").props("color=positive")
138
- refs["download"].set_visibility(False)
139
- run()
140
-
141
-
142
- def run(port: int = 8080, show: bool = True) -> None:
143
- setup_logging()
144
- all_tools = load_all()
145
- state = {"tool": next(iter(all_tools)), "query": ""}
146
-
147
- @ui.page("/")
148
- def index() -> None:
149
- dark = ui.dark_mode()
150
-
151
- @ui.refreshable
152
- def nav() -> None:
153
- q = state["query"].lower()
154
- for group, tools in groups().items():
155
- matches = [t for t in tools if q in t.title.lower() or q in t.name or q in t.description.lower()]
156
- if not matches:
157
- continue
158
- ui.label(group).classes("text-xs uppercase text-gray-500 mt-3")
159
- for t in matches:
160
- ui.button(t.title, on_click=lambda t=t: select(t.name)).props(
161
- "flat no-caps align=left" + ("" if t.name != state["tool"] else " color=primary")
162
- ).classes("w-full")
163
-
164
- @ui.refreshable
165
- def panel() -> None:
166
- _tool_panel(all_tools[state["tool"]])
167
-
168
- def select(name: str) -> None:
169
- state["tool"] = name
170
- nav.refresh()
171
- panel.refresh()
172
-
173
- def search(e) -> None:
174
- state["query"] = e.value or ""
175
- nav.refresh()
176
-
177
- with ui.header().classes("items-center justify-between"):
178
- ui.label("simplutils").classes("text-xl font-bold")
179
- ui.button(icon="dark_mode", on_click=dark.toggle).props("flat round color=white")
180
- with ui.left_drawer(fixed=True).props("width=260"):
181
- ui.input(placeholder="Search tools...", on_change=search).props("outlined dense clearable").classes("w-full")
182
- nav()
183
- with ui.column().classes("w-full max-w-4xl mx-auto p-4"):
184
- panel()
185
-
186
- ui.run(title="simplutils", port=port, show=show, reload=False, favicon="🧰")
File without changes
File without changes
File without changes