pythonhere 0.3.1__tar.gz → 0.4.0__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 (83) hide show
  1. {pythonhere-0.3.1/pythonhere.egg-info → pythonhere-0.4.0}/PKG-INFO +4 -1
  2. {pythonhere-0.3.1 → pythonhere-0.4.0}/pyproject.toml +7 -0
  3. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/SKILL.md +3 -1
  4. pythonhere-0.4.0/pythonhere/.agents/skills/pythonhere/references/litert.md +121 -0
  5. pythonhere-0.4.0/pythonhere/ml_here/__init__.py +17 -0
  6. pythonhere-0.4.0/pythonhere/ml_here/huggingface.py +998 -0
  7. pythonhere-0.4.0/pythonhere/ml_here/storage.py +145 -0
  8. pythonhere-0.4.0/pythonhere/version_here.py +1 -0
  9. {pythonhere-0.3.1 → pythonhere-0.4.0/pythonhere.egg-info}/PKG-INFO +4 -1
  10. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere.egg-info/SOURCES.txt +5 -0
  11. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere.egg-info/requires.txt +4 -0
  12. pythonhere-0.4.0/tests/test_ml_here.py +416 -0
  13. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_pythonhere_skill.py +3 -1
  14. pythonhere-0.3.1/pythonhere/version_here.py +0 -1
  15. {pythonhere-0.3.1 → pythonhere-0.4.0}/LICENSE +0 -0
  16. {pythonhere-0.3.1 → pythonhere-0.4.0}/README.rst +0 -0
  17. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/agents/openai.yaml +0 -0
  18. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/able.md +0 -0
  19. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/android-media.md +0 -0
  20. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/android-packages.md +0 -0
  21. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/android-permissions.md +0 -0
  22. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/android-runtime.md +0 -0
  23. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/jnius.md +0 -0
  24. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/kivy-kv.md +0 -0
  25. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/kivy-runtime.md +0 -0
  26. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/midi.md +0 -0
  27. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/.agents/skills/pythonhere/references/plyer.md +0 -0
  28. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/__init__.py +0 -0
  29. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/android_here.py +0 -0
  30. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/data/logo/logo-128.png +0 -0
  31. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/data/logo/logo-32.png +0 -0
  32. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/data/logo/logo-splash.png +0 -0
  33. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/enum_here.py +0 -0
  34. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/exception_manager_here.kv +0 -0
  35. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/exception_manager_here.py +0 -0
  36. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/launcher_here.py +0 -0
  37. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/__init__.py +0 -0
  38. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/README.md +0 -0
  39. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/able.md +0 -0
  40. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/android-media.md +0 -0
  41. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/android-packages.md +0 -0
  42. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/android-permissions.md +0 -0
  43. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/android-runtime.md +0 -0
  44. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/jnius.md +0 -0
  45. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/kivy-kv.md +0 -0
  46. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/kivy-runtime.md +0 -0
  47. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/midi.md +0 -0
  48. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts/plyer.md +0 -0
  49. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/prompts.py +0 -0
  50. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/magic_here/shortcuts.py +0 -0
  51. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/main.py +0 -0
  52. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/network_here.py +0 -0
  53. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/patches_here.py +0 -0
  54. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/pythonhere.kv +0 -0
  55. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/server_here.py +0 -0
  56. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/tools_here.py +0 -0
  57. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/__init__.py +0 -0
  58. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/actionbar_here.kv +0 -0
  59. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/common_here.kv +0 -0
  60. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/connection_address_here.kv +0 -0
  61. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/connection_address_here.py +0 -0
  62. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/layout_here.py +0 -0
  63. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/server_screen_here.kv +0 -0
  64. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/server_screen_here.py +0 -0
  65. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/settings_here.kv +0 -0
  66. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/ui_here/settings_here.py +0 -0
  67. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere/window_here.py +0 -0
  68. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere.egg-info/dependency_links.txt +0 -0
  69. {pythonhere-0.3.1 → pythonhere-0.4.0}/pythonhere.egg-info/top_level.txt +0 -0
  70. {pythonhere-0.3.1 → pythonhere-0.4.0}/setup.cfg +0 -0
  71. {pythonhere-0.3.1 → pythonhere-0.4.0}/setup.py +0 -0
  72. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_ai_prompts.py +0 -0
  73. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_android_here.py +0 -0
  74. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_exception_manager_here.py +0 -0
  75. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_launcher_here.py +0 -0
  76. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_magic.py +0 -0
  77. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_main.py +0 -0
  78. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_network.py +0 -0
  79. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_patches.py +0 -0
  80. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_server_here.py +0 -0
  81. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_settings.py +0 -0
  82. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_tools_here.py +0 -0
  83. {pythonhere-0.3.1 → pythonhere-0.4.0}/tests/test_window_here.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythonhere
3
- Version: 0.3.1
3
+ Version: 0.4.0
4
4
  Summary: Here is the Kivy based app to run code from the Jupyter magic %there
5
5
  Author-email: b3b <ash.b3b@gmail.com>
6
6
  License-Expression: MIT
@@ -20,6 +20,9 @@ Requires-Dist: herethere[magic]>=0.3.2
20
20
  Requires-Dist: ipython
21
21
  Requires-Dist: ipywidgets
22
22
  Requires-Dist: Pillow
23
+ Provides-Extra: litert
24
+ Requires-Dist: litert-lm-api==0.16.0; extra == "litert"
25
+ Requires-Dist: requests; extra == "litert"
23
26
  Dynamic: license-file
24
27
 
25
28
  PythonHere
@@ -28,6 +28,12 @@ dependencies = [
28
28
  "Pillow",
29
29
  ]
30
30
 
31
+ [project.optional-dependencies]
32
+ litert = [
33
+ "litert-lm-api==0.16.0",
34
+ "requests",
35
+ ]
36
+
31
37
  [dependency-groups]
32
38
  dev = [
33
39
  { include-group = "docker" },
@@ -66,6 +72,7 @@ pythonpath = ["pythonhere"]
66
72
  [tool.setuptools]
67
73
  packages = [
68
74
  "pythonhere",
75
+ "pythonhere.ml_here",
69
76
  "pythonhere.magic_here",
70
77
  "pythonhere.ui_here",
71
78
  ]
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: pythonhere
3
- description: "Build, inspect, and debug PythonHere applications by executing Python through the `there` CLI in an already-running Kivy/Python-for-Android process. Use when a task targets a PythonHere device or `there.env` connection and involves live Kivy UI, KV language, Android APIs, Pyjnius, permissions, installed Android packages, media/files, Plyer device features, BLE with able, or MIDI with midistream."
3
+ description: "Build, inspect, and debug PythonHere applications by executing Python through the `there` CLI in an already-running Kivy/Python-for-Android process. Use when a task targets a PythonHere device or `there.env` connection and involves live Kivy UI, KV language, Android APIs, Pyjnius, permissions, installed Android packages, media/files, Plyer device features, BLE with able, MIDI with midistream, or on-device AI with LiteRT-LM and `.litertlm` models."
4
4
  ---
5
5
 
6
6
  # Operate PythonHere with `there`
@@ -40,6 +40,8 @@ when the task depends on it broadly or requires its exact current contents.
40
40
  recording, camera, file selection, GPS, battery, or sensors.
41
41
  - Consult [able.md](references/able.md) for Bluetooth Low Energy work.
42
42
  - Consult [midi.md](references/midi.md) for MIDI or synthesizer work.
43
+ - Consult [litert.md](references/litert.md) for PythonHere's ML model helpers
44
+ and LiteRT-LM usage.
43
45
 
44
46
  Combine references when a feature genuinely needs details from several
45
47
  concerns; for example, an Android gallery may need permission, MediaStore, and
@@ -0,0 +1,121 @@
1
+ # ML model helpers for LiteRT
2
+
3
+ PythonHere provides `ml_here` for acquiring and locating ML model files. It
4
+ does not wrap LiteRT-LM inference.
5
+
6
+ All public model helpers return paths as strings (a list of strings for
7
+ `discover_models()`), ready to pass to `litert_lm.Engine()`.
8
+
9
+ ```python
10
+ from ml_here import (
11
+ discover_models,
12
+ download_hf_model,
13
+ model_path,
14
+ models_directory,
15
+ require_model,
16
+ )
17
+ ```
18
+
19
+ - `models_directory(create=False)` returns PythonHere's model directory. On
20
+ Android this is the app-specific external files directory under `models`; on
21
+ Linux it is `~/.local/share/pythonhere/models`.
22
+ - `model_path(repo_id, filename)` returns the namespaced path for a model. It
23
+ does not create directories and rejects unsafe path components.
24
+ - `require_model(repo_id, filename)` returns that path when the model is
25
+ installed and raises `FileNotFoundError` otherwise.
26
+ - `discover_models(extra_directories=(), extensions=".litertlm")` recursively
27
+ returns sorted, unique LiteRT-LM model paths from managed storage and any
28
+ additional directories. Pass another extension or iterable to select other
29
+ formats, or `extensions=None` to include every completed stored artifact.
30
+ - `download_hf_model(repo_id, filename, *, revision="main", token=None,
31
+ destination=None, progress=None, cancelled=None, overwrite=False,
32
+ expected_sha256=None)` downloads a Hugging Face model file of any format. By
33
+ default, it stores the file at `model_path(repo_id, filename)`.
34
+
35
+ Choose by intent: use `require_model()` to load a known installed model, the
36
+ path returned by `download_hf_model()` after a download, and
37
+ `discover_models()` only to inventory models whose identities are not already
38
+ known. Use `model_path()` when only the expected location is needed.
39
+
40
+ Downloads are resumable across restarts and make the final file visible only
41
+ after the download completes. Cancellation preserves the partial download for
42
+ resuming. Pass a token for private or gated models. The `progress` callback
43
+ receives the following interface; use it directly rather than redefining it:
44
+
45
+ ```python
46
+ class DownloadProgress:
47
+ repo_id: str
48
+ filename: str
49
+ destination: str
50
+ downloaded: int
51
+ total: int | None
52
+ elapsed: float
53
+ speed_bps: float
54
+ fraction: float | None
55
+ percent: float | None
56
+ speed_mbps: float
57
+ remaining: int | None
58
+ eta: float | None
59
+ ```
60
+
61
+ Use `litert_lm` directly to load and run the returned model path.
62
+
63
+ ## Run an installed model
64
+
65
+ Run model loading and inference on a worker (`--worker`) to keep Kivy
66
+ responsive. In the app runtime, import model helpers from `ml_here`.
67
+
68
+ ```python
69
+ import litert_lm
70
+ from ml_here import require_model
71
+
72
+ model_file = require_model(
73
+ "litert-community/SmolLM2-135M-Instruct",
74
+ "SmolLM2_135M_Instruct.litertlm",
75
+ )
76
+ engine = litert_lm.Engine(model_file)
77
+ try:
78
+ with engine.create_conversation(max_output_tokens=128) as conversation:
79
+ response = conversation.send_message(
80
+ "What is the Kivy framework? Answer in one short paragraph."
81
+ )
82
+ text = "".join(
83
+ part["text"]
84
+ for part in response["content"]
85
+ if part.get("type") == "text"
86
+ )
87
+ print(text)
88
+ finally:
89
+ engine.close()
90
+ ```
91
+
92
+ The conversation closes before the engine, including when inference raises.
93
+ For an interactive chat, keep the engine loaded and reuse the conversation
94
+ for follow-up messages; close both when the chat is finished.
95
+
96
+ `litert_lm.Engine(model_file)` uses CPU by default. For a model and device
97
+ that support GPU inference, replace the engine construction above with:
98
+
99
+ ```python
100
+ engine = litert_lm.Engine(model_file, backend=litert_lm.Backend.GPU())
101
+ ```
102
+
103
+ ## Download first when needed
104
+
105
+ If the model is not installed, download it on a worker before inference:
106
+
107
+ ```python
108
+ from ml_here import download_hf_model
109
+
110
+ model_file = download_hf_model(
111
+ "litert-community/SmolLM2-135M-Instruct",
112
+ "SmolLM2_135M_Instruct.litertlm",
113
+ )
114
+ print(model_file)
115
+ ```
116
+
117
+ When downloading and loading in the same script, pass the returned
118
+ `model_file` directly to `litert_lm.Engine()`.
119
+
120
+ See the [upstream Python API](https://github.com/google-ai-edge/LiteRT-LM/tree/main/python)
121
+ for streaming, sampling, and multimodal inference.
@@ -0,0 +1,17 @@
1
+ """Acquire, store, index, and discover ML model files for PythonHere."""
2
+
3
+ from .huggingface import download_hf_model
4
+ from .storage import (
5
+ discover_models,
6
+ model_path,
7
+ models_directory,
8
+ require_model,
9
+ )
10
+
11
+ __all__ = (
12
+ "discover_models",
13
+ "download_hf_model",
14
+ "model_path",
15
+ "models_directory",
16
+ "require_model",
17
+ )