luar 0.4.2__tar.gz → 0.4.4__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 (28) hide show
  1. {luar-0.4.2/src/luar.egg-info → luar-0.4.4}/PKG-INFO +2 -2
  2. {luar-0.4.2 → luar-0.4.4}/pyproject.toml +2 -2
  3. {luar-0.4.2 → luar-0.4.4}/src/luar/__init__.py +1 -1
  4. {luar-0.4.2 → luar-0.4.4}/src/luar/app.py +65 -6
  5. {luar-0.4.2 → luar-0.4.4}/src/luar/backends/laya_backend.py +37 -1
  6. {luar-0.4.2 → luar-0.4.4/src/luar.egg-info}/PKG-INFO +2 -2
  7. {luar-0.4.2 → luar-0.4.4}/src/luar.egg-info/requires.txt +1 -1
  8. {luar-0.4.2 → luar-0.4.4}/tests/test_app.py +27 -0
  9. {luar-0.4.2 → luar-0.4.4}/tests/test_laya_backend.py +31 -0
  10. {luar-0.4.2 → luar-0.4.4}/LICENSE +0 -0
  11. {luar-0.4.2 → luar-0.4.4}/README.md +0 -0
  12. {luar-0.4.2 → luar-0.4.4}/setup.cfg +0 -0
  13. {luar-0.4.2 → luar-0.4.4}/src/luar/__main__.py +0 -0
  14. {luar-0.4.2 → luar-0.4.4}/src/luar/backends/__init__.py +0 -0
  15. {luar-0.4.2 → luar-0.4.4}/src/luar/backends/base.py +0 -0
  16. {luar-0.4.2 → luar-0.4.4}/src/luar/cli.py +0 -0
  17. {luar-0.4.2 → luar-0.4.4}/src/luar/engine.py +0 -0
  18. {luar-0.4.2 → luar-0.4.4}/src/luar/questions.py +0 -0
  19. {luar-0.4.2 → luar-0.4.4}/src/luar/report.py +0 -0
  20. {luar-0.4.2 → luar-0.4.4}/src/luar/tables.py +0 -0
  21. {luar-0.4.2 → luar-0.4.4}/src/luar.egg-info/SOURCES.txt +0 -0
  22. {luar-0.4.2 → luar-0.4.4}/src/luar.egg-info/dependency_links.txt +0 -0
  23. {luar-0.4.2 → luar-0.4.4}/src/luar.egg-info/entry_points.txt +0 -0
  24. {luar-0.4.2 → luar-0.4.4}/src/luar.egg-info/top_level.txt +0 -0
  25. {luar-0.4.2 → luar-0.4.4}/tests/test_engine.py +0 -0
  26. {luar-0.4.2 → luar-0.4.4}/tests/test_offline.py +0 -0
  27. {luar-0.4.2 → luar-0.4.4}/tests/test_questions.py +0 -0
  28. {luar-0.4.2 → luar-0.4.4}/tests/test_tables.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: luar
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: LUAR (Local Utility for Automated Reviews): catalog spreadsheet rows with a local decision model.
5
5
  Author-email: Alexandre Alves <alexxalvess@gmail.com>
6
6
  License-Expression: MIT
@@ -24,7 +24,7 @@ Requires-Dist: pandas>=2.0
24
24
  Requires-Dist: openpyxl>=3.1
25
25
  Requires-Dist: laya>=0.3.21
26
26
  Provides-Extra: ui
27
- Requires-Dist: gradio>=5.0; extra == "ui"
27
+ Requires-Dist: gradio>=6.0; extra == "ui"
28
28
  Provides-Extra: laya
29
29
  Provides-Extra: all
30
30
  Requires-Dist: luar[ui]; extra == "all"
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "luar"
7
- version = "0.4.2"
7
+ version = "0.4.4"
8
8
  description = "LUAR (Local Utility for Automated Reviews): catalog spreadsheet rows with a local decision model."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -34,7 +34,7 @@ Issues = "https://github.com/HayateV30/luar/issues"
34
34
  Changelog = "https://github.com/HayateV30/luar/releases"
35
35
 
36
36
  [project.optional-dependencies]
37
- ui = ["gradio>=5.0"]
37
+ ui = ["gradio>=6.0"] # row_limits/column_limits on gr.Dataframe
38
38
  laya = [] # Laya is now a required dependency; kept so `luar[laya]` still installs cleanly
39
39
  all = ["luar[ui]"]
40
40
  dev = ["pytest>=8"]
@@ -2,7 +2,7 @@
2
2
  from .engine import DEFAULT_THRESHOLD, Result, classify, run_file
3
3
  from .questions import Question, QuestionError, load_questions, parse_questions
4
4
 
5
- __version__ = "0.4.2"
5
+ __version__ = "0.4.4"
6
6
 
7
7
  __all__ = [
8
8
  "DEFAULT_THRESHOLD",
@@ -92,6 +92,26 @@ CSS = """
92
92
  #luar-header > :first-child, #luar-actions { grid-column: 1; justify-self: center; justify-content: center; }
93
93
  }
94
94
  .luar-step h3 { margin-top: 8px; }
95
+ /* background: four crosses of light points in a row along the X axis, turning together around it
96
+ (inspired by an old TV intro); behind everything, never clickable, still when motion is reduced */
97
+ #luar-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; perspective: 900px;
98
+ perspective-origin: 15% 85%; --dot: 15, 23, 42; --a: 0.30; --b: 4;
99
+ -webkit-mask: radial-gradient(circle at 14% 86%, #000 0, #000 210px, transparent 540px);
100
+ mask: radial-gradient(circle at 14% 86%, #000 0, #000 210px, transparent 540px); }
101
+ .dark #luar-bg { --dot: 255, 255, 255; }
102
+ .gradio-container > * { position: relative; z-index: 1; }
103
+ #luar-bg .cam { position: absolute; left: 16%; bottom: 16%; transform-style: preserve-3d;
104
+ transform: rotateX(-22deg) rotateY(58deg); }
105
+ #luar-bg .spin { position: absolute; transform-style: preserve-3d; animation: luar-spin 120s linear infinite; }
106
+ #luar-bg .cross { position: absolute; transform-style: preserve-3d; }
107
+ #luar-bg .arm { position: absolute; left: 0; top: calc(var(--w) / -2); height: var(--w);
108
+ width: calc(var(--R) - var(--h)); transform-origin: 0 50%; filter: blur(var(--bl));
109
+ background: radial-gradient(circle, rgba(var(--dot), var(--o)) 0 var(--r), transparent calc(var(--r) + 1.5px))
110
+ left center / var(--g) var(--w) repeat-x; }
111
+ @keyframes luar-spin { from { transform: rotateX(0); } to { transform: rotateX(360deg); } }
112
+ /* still while the app works (Gradio marks running outputs .pending, also on errors): CPU for Laya */
113
+ body:has(.pending) #luar-bg .spin { animation-play-state: paused !important; }
114
+ @media (prefers-reduced-motion: reduce) { #luar-bg .spin { animation: none; } }
95
115
  #luar-run { min-height: 48px; font-size: 1rem; }
96
116
  button, [role="button"], label:has(input) { cursor: pointer; }
97
117
  :focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
@@ -106,11 +126,18 @@ Add a column named `expected_<id>` to your file to measure accuracy on rows you
106
126
  """
107
127
 
108
128
  NO_QUESTIONS = (
109
- "There are no questions yet. In step 2, fill in at least the id and the question of one row "
110
- "(or load a questions .json file). Trying the Sample CSV? Download Sample JSON at the top of the "
111
- "page and drop it in \"Load questions (.json)\", or pick \"Amostra de teste (Sample CSV)\" in "
112
- "\"…or try an example\" to load both at once."
129
+ "There are no questions yet. In step 2, fill in at least the id and the question of one row, "
130
+ "or load a questions .json file in \"Load questions (.json)\"."
113
131
  )
132
+ # only offered where the sample buttons and the examples menu exist (a repository checkout, not PyPI)
133
+ SAMPLE_HINT = (
134
+ " Trying the Sample CSV? Download Sample JSON at the top of the page and load it there, or pick "
135
+ "\"Amostra de teste (Sample CSV)\" in \"…or try an example\" to load both at once."
136
+ )
137
+
138
+
139
+ def no_questions_message() -> str:
140
+ return NO_QUESTIONS + (SAMPLE_HINT if SAMPLE_QUESTIONS.exists() else "")
114
141
 
115
142
 
116
143
  def _questions_to_rows(questions) -> list[list[str]]:
@@ -132,7 +159,7 @@ def _rows_to_questions(table) -> list:
132
159
  continue
133
160
  data.append({"id": qid, "type": qtype.lower(), "question": text, "options": opts})
134
161
  if not data:
135
- raise QuestionError(NO_QUESTIONS)
162
+ raise QuestionError(no_questions_message())
136
163
  return parse_questions(data)
137
164
 
138
165
 
@@ -230,6 +257,35 @@ def on_run(file, columns, table, threshold, checkpoint, progress=gr.Progress()):
230
257
  return result.table, render_summary(result), [str(result.table_path), str(result.summary_path)]
231
258
 
232
259
 
260
+ # Background geometry (see CSS above): each section is 15% smaller than the one in front of it
261
+ BG_SECTIONS = 4
262
+ BG_SHRINK = 0.15
263
+ BG_GAP = 70 # px between sections along the X axis
264
+ BG_HOLE = 0.06 # gap at the center of each cross, as a share of the arm length
265
+ BG_BLUR = (1, 0.45, 0.15, 0) # front section blurred, back ones sharp (depth of field)
266
+ BG_OPACITY = (1, 0.85, 0.72, 0.6)
267
+
268
+
269
+ def background_html() -> str:
270
+ """Four aligned crosses of four arms each, from the largest (front) to the smallest (back)."""
271
+ crosses = []
272
+ for i in range(BG_SECTIONS):
273
+ f = (1 - BG_SHRINK) ** i
274
+ radius = round(230 * f)
275
+ style = (
276
+ f"transform: translateX({i * BG_GAP}px) rotateY(90deg); --R: {radius}px; "
277
+ f"--h: {round(radius * BG_HOLE)}px; --r: {6 * f:.1f}px; --w: {round(16 * f)}px; "
278
+ f"--g: {round(30 * f)}px; --o: calc(var(--a) * {BG_OPACITY[i]}); "
279
+ f"--bl: calc(var(--b) * {BG_BLUR[i]}px)"
280
+ )
281
+ arms = "".join(
282
+ f'<div class="arm" style="transform: rotate({-90 + 90 * j}deg) translateX(var(--h))"></div>'
283
+ for j in range(4)
284
+ )
285
+ crosses.append(f'<div class="cross" style="{style}">{arms}</div>')
286
+ return f'<div id="luar-bg" aria-hidden="true"><div class="cam"><div class="spin">{"".join(crosses)}</div></div></div>'
287
+
288
+
233
289
  def readme_markdown(path: Path) -> str:
234
290
  """The README with its screenshots pointed at the local files, so the manual works offline."""
235
291
  local = f"/gradio_api/file={quote(IMAGES.as_posix())}/"
@@ -238,6 +294,7 @@ def readme_markdown(path: Path) -> str:
238
294
 
239
295
  def build() -> gr.Blocks:
240
296
  with gr.Blocks(title="LUAR", analytics_enabled=False) as demo:
297
+ gr.HTML(background_html(), padding=False, container=False)
241
298
  readmes = {lang: path for lang, path in READMES.items() if path.exists()}
242
299
  with gr.Row(elem_id="luar-header"):
243
300
  gr.Markdown("# LUAR")
@@ -279,7 +336,9 @@ def build() -> gr.Blocks:
279
336
  datatype=["str", "str", "str", "str"],
280
337
  value=[["", "choice", "", ""]],
281
338
  interactive=True,
282
- row_count=(1, "dynamic"),
339
+ # An int means (1, "dynamic"): rows can be added. Tuples are deprecated for row_count,
340
+ # and row_limits/column_limits are not implemented yet (Gradio 6.29).
341
+ row_count=1,
283
342
  column_count=(4, "fixed"),
284
343
  wrap=True,
285
344
  column_widths=["12%", "10%", "38%", "40%"],
@@ -27,6 +27,33 @@ def laya_installed() -> bool:
27
27
  return importlib.util.find_spec("laya") is not None
28
28
 
29
29
 
30
+ class LibraryBlockedError(BackendError):
31
+ pass
32
+
33
+
34
+ WINERROR_APP_CONTROL = 4551 # "An Application Control policy has blocked this file"
35
+
36
+
37
+ def is_library_error(e: OSError) -> bool:
38
+ """A DLL that failed to load (Windows), not a missing model file or a network error."""
39
+ text = str(e)
40
+ return getattr(e, "winerror", None) is not None and (".dll" in text.lower() or "WinError" in text)
41
+
42
+
43
+ def library_error(e: OSError) -> LibraryBlockedError:
44
+ """Explain a PyTorch DLL that failed to load (Laya imports PyTorch on first use)."""
45
+ if getattr(e, "winerror", None) == WINERROR_APP_CONTROL or f"WinError {WINERROR_APP_CONTROL}" in str(e):
46
+ return LibraryBlockedError(
47
+ "Windows blocked one of PyTorch's files (Application Control, WinError 4551), so the Laya "
48
+ "engine could not start. This can happen just once: close LUAR and open it again. If it keeps "
49
+ f"happening, ask whoever manages this computer to allow PyTorch's files. Details: {e}"
50
+ )
51
+ return LibraryBlockedError(
52
+ "PyTorch, which the Laya engine needs, could not be loaded. Close LUAR and open it again; if it "
53
+ f"keeps happening, reinstall it with: pip install --force-reinstall torch. Details: {e}"
54
+ )
55
+
56
+
30
57
  def import_laya():
31
58
  """Import the `laya` package (a LUAR dependency), or explain how to repair a broken install."""
32
59
  try:
@@ -35,6 +62,10 @@ def import_laya():
35
62
  raise LayaNotInstalledError(
36
63
  f"The Laya engine could not be loaded. Reinstall it with: {INSTALL_HINT}"
37
64
  ) from e
65
+ except OSError as e:
66
+ if is_library_error(e): # a PyTorch DLL refused to load
67
+ raise library_error(e) from e
68
+ raise
38
69
  return laya
39
70
 
40
71
 
@@ -136,7 +167,12 @@ class LayaBackend:
136
167
  if subfolder:
137
168
  kwargs["subfolder"] = subfolder
138
169
  # once downloaded, load from disk: laya.load(repo) asks the Hub for updates on every run
139
- self._agent = laya.load(local_checkpoint(self.repo, subfolder) or self.repo, **kwargs)
170
+ try:
171
+ self._agent = laya.load(local_checkpoint(self.repo, subfolder) or self.repo, **kwargs)
172
+ except OSError as e:
173
+ if is_library_error(e): # laya imports PyTorch lazily, here
174
+ raise library_error(e) from e
175
+ raise
140
176
  return self._agent
141
177
 
142
178
  def decide(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: luar
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: LUAR (Local Utility for Automated Reviews): catalog spreadsheet rows with a local decision model.
5
5
  Author-email: Alexandre Alves <alexxalvess@gmail.com>
6
6
  License-Expression: MIT
@@ -24,7 +24,7 @@ Requires-Dist: pandas>=2.0
24
24
  Requires-Dist: openpyxl>=3.1
25
25
  Requires-Dist: laya>=0.3.21
26
26
  Provides-Extra: ui
27
- Requires-Dist: gradio>=5.0; extra == "ui"
27
+ Requires-Dist: gradio>=6.0; extra == "ui"
28
28
  Provides-Extra: laya
29
29
  Provides-Extra: all
30
30
  Requires-Dist: luar[ui]; extra == "all"
@@ -11,4 +11,4 @@ pytest>=8
11
11
  [laya]
12
12
 
13
13
  [ui]
14
- gradio>=5.0
14
+ gradio>=6.0
@@ -22,6 +22,18 @@ def test_no_questions_explains_what_to_do():
22
22
  app._rows_to_questions(table)
23
23
 
24
24
 
25
+ def test_no_questions_message_only_mentions_samples_that_exist(monkeypatch, tmp_path):
26
+ with pytest.raises(QuestionError, match="Sample JSON") as repo:
27
+ app._rows_to_questions([["", "choice", "", ""]])
28
+ # an install from PyPI has no examples/ folder: the sample buttons and menu are hidden
29
+ monkeypatch.setattr(app, "SAMPLE_QUESTIONS", tmp_path / "missing.json")
30
+ with pytest.raises(QuestionError) as pypi:
31
+ app._rows_to_questions([["", "choice", "", ""]])
32
+ assert "Load questions (.json)" in str(pypi.value)
33
+ assert "Sample" not in str(pypi.value) and "try an example" not in str(pypi.value)
34
+ assert str(repo.value).startswith(str(pypi.value))
35
+
36
+
25
37
  def test_half_written_row_still_reports_the_missing_id():
26
38
  with pytest.raises(QuestionError, match="Invalid question id"):
27
39
  app._rows_to_questions([["", "choice", "What is it about?", "a; b"]])
@@ -41,3 +53,18 @@ def test_every_example_set_loads_and_matches_its_answer_key():
41
53
  assert f"expected_{q.id}" in df.columns, f"{name}: no expected_{q.id}"
42
54
  file, rows = app.on_example(name)
43
55
  assert [r[0] for r in rows] == [q.id for q in load_questions(EXAMPLES / questions)]
56
+
57
+
58
+ def test_background_has_four_aligned_crosses_shrinking_to_the_back():
59
+ import re
60
+
61
+ from luar.app import CSS, background_html
62
+
63
+ html = background_html()
64
+ assert html.count('class="cross"') == 4 and html.count('class="arm"') == 16
65
+ radii = [int(r) for r in re.findall(r"--R: (\d+)px", html)]
66
+ assert radii == sorted(radii, reverse=True) and len(set(radii)) == 4 # 1st largest, 4th smallest
67
+ assert 'aria-hidden="true"' in html
68
+ # never in the way: behind the page, not clickable, still when the OS asks for less motion
69
+ assert "pointer-events: none" in CSS and "prefers-reduced-motion" in CSS
70
+ assert "body:has(.pending)" in CSS # paused while the app works
@@ -88,3 +88,34 @@ def test_download_command(monkeypatch):
88
88
  assert cli_main(["download"]) == 0
89
89
  assert cli_main(["download", "english"]) == 0
90
90
  assert asked == [("multilingual", "english"), ("english",)]
91
+
92
+
93
+ def _blocked_dll():
94
+ e = OSError(1, "Uma política de Controle de Aplicativo bloqueou este arquivo. "
95
+ r'Error loading "C:\py\torch\lib\shm.dll" or one of its dependencies.')
96
+ e.winerror = 4551
97
+ return e
98
+
99
+
100
+ def test_blocked_pytorch_dll_explains_what_to_do(monkeypatch):
101
+ import laya
102
+
103
+ from luar.backends.laya_backend import LibraryBlockedError
104
+
105
+ def blocked(*a, **k):
106
+ raise _blocked_dll()
107
+
108
+ monkeypatch.setattr(laya, "load", blocked)
109
+ with pytest.raises(LibraryBlockedError, match="Application Control.*close LUAR and open it again"):
110
+ LayaBackend(checkpoint="multilingual").decide(["t"], load_questions(EXAMPLES / "reviews_questions.json"))
111
+
112
+
113
+ def test_other_os_errors_are_not_called_dll_problems(monkeypatch):
114
+ import laya
115
+
116
+ def missing(*a, **k):
117
+ raise FileNotFoundError("model.safetensors not found")
118
+
119
+ monkeypatch.setattr(laya, "load", missing)
120
+ with pytest.raises(FileNotFoundError):
121
+ LayaBackend(checkpoint="multilingual").decide(["t"], load_questions(EXAMPLES / "reviews_questions.json"))
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes