Skip to content

Add pydemo1 - #102

Merged
pierre-tenedero merged 1 commit into
mainfrom
pydemo1
Jul 23, 2026
Merged

Add pydemo1#102
pierre-tenedero merged 1 commit into
mainfrom
pydemo1

Conversation

@pierre-tenedero

@pierre-tenedero pierre-tenedero commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added an eye and speech detection demo with browser-based camera, microphone, model inference, and live status displays.
    • Added support for running and packaging the new demo module.
    • Improved workflow switching by stopping the previously active demo automatically.
  • Improvements

    • Extended speech detection recordings to 30 seconds.
    • Updated recording displays to show remaining time.
    • Added clearer GPU meter identification.
  • Tests

    • Added coverage for the new demo workflow and browser-runner compatibility.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds the pydemo1 eye-and-speech demo with Python processing, Pyodide/browser execution, workspace build and test wiring, coverage/type-check configuration, workflow lifecycle tracking, and updated speech recording UI and duration.

Changes

pydemo1 Demo Integration

Layer / File(s) Summary
Python demo processing and contracts
services/ws-modules/pydemo1/pydemo1/*, services/ws-modules/pydemo1/tests/*
Adds eye and speech capture result contracts, processing wrappers, WebSocket workflow orchestration, cleanup handling, and tests.
Browser runtime and demo interface
services/ws-modules/pydemo1/pkg/*
Adds the ES module package, Pyodide initialization and wheel loading, demo UI, WebSocket bridge, and model setup.
Combined media capture and cleanup
services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js
Adds camera and microphone capture, eye and speech inference, rendering, storage uploads, event transmission, and teardown.
Workspace build, test, and analysis wiring
.mise/*, config/*, pyproject.toml, services/ws-modules/pydemo1/pkg/.gitignore
Registers pydemo1 as a workspace module and adds build, test, prefetch, coverage, Pyrefly, and artifact-ignore configuration.
Workflow coordination and speech updates
services/ws-server/static/*, services/ws-web-runner/tests/modules.rs, services/ws-modules/pyspeech1/*
Adds active-workflow stopping, GPU meter identification, Deno coverage cases, a 30-second speech capture window, and countdown/style helpers.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant Pyodide
  participant CameraMicrophone
  participant WsClient
  Browser->>Pyodide: initialize pydemo1
  Browser->>CameraMicrophone: start eye and speech capture
  CameraMicrophone->>Pyodide: provide capture data
  Pyodide->>WsClient: send processed event JSON
  Browser->>WsClient: upload eye capture
  Browser->>CameraMicrophone: stop and release resources
Loading

Possibly related PRs

Suggested reviewers: jayvdb

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the main change by introducing the new pydemo1 module, though it is slightly less descriptive than the full demo scope.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pydemo1

Comment @coderabbitai help to get the list of available commands.

@deepsource-io

deepsource-io Bot commented Jul 22, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 3052768...cb6beb9 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Coverage  

Code Review Summary

Analyzer Status Updated (UTC) Details
C# Jul 22, 2026 11:41p.m. Review ↗
C & C++ Jul 22, 2026 11:41p.m. Review ↗
Docker Jul 22, 2026 11:41p.m. Review ↗
Java Jul 22, 2026 11:41p.m. Review ↗
JavaScript Jul 22, 2026 11:41p.m. Review ↗
Python Jul 22, 2026 11:41p.m. Review ↗
Rust Jul 22, 2026 11:41p.m. Review ↗
Secrets Jul 22, 2026 11:41p.m. Review ↗
Code coverage Jul 23, 2026 12:08a.m. Review ↗

Code Coverage Summary

Language Line Coverage (New Code) Line Coverage (Overall)
Aggregate
91%
59.2%
[▲ up 0.3% from main]
Python
91%
85.2%
[▲ up 0.9% from main]
Rust -
57.1%

➟ Additional coverage metrics may have been reported. See full coverage report ↗


Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

let pythonScriptPromise = null;
let pythonRuntimePromise = null;

export default async function init() {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'


Found non-compliant syntax. Confirm that there are no syntax errors before committing your code to a version control system.

results = build_results(faces, width, height)
now_s = time.monotonic() - self.started_at
if results:
self.crop = smooth_crop(self.crop, eye_region_crop(results[0], width, height))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'crop' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

event_json: str | None = None
capture_count = 0
if now_s * 1000.0 - self.last_analysis_ms >= ANALYSIS_INTERVAL_MS:
self.last_analysis_ms = now_s * 1000.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'last_analysis_ms' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

capture_count = 0
if now_s * 1000.0 - self.last_analysis_ms >= ANALYSIS_INTERVAL_MS:
self.last_analysis_ms = now_s * 1000.0
self.analysis = analyze_window(list(self.history))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'analysis' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

event_json = eye_event_json(eye_event_payload(results, self.analysis, width, height))
indicator_active = self.analysis["misalignment"]["detected"] or self.analysis["oscillation"]["detected"]
if indicator_active and not self.indicator_was_active:
self.captured_for_episode = False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'captured_for_episode' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

if indicator_active and not self.indicator_was_active:
self.captured_for_episode = False
if indicator_active and not self.captured_for_episode and upload_consent:
self.captured_for_episode = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'captured_for_episode' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

if indicator_active and not self.captured_for_episode and upload_consent:
self.captured_for_episode = True
capture_count += 1
self.indicator_was_active = indicator_active

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'indicator_was_active' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

self.indicator_was_active = indicator_active

if now_s * 1000.0 - self.last_periodic_capture_ms >= PERIODIC_CAPTURE_INTERVAL_MS:
self.last_periodic_capture_ms = now_s * 1000.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'last_periodic_capture_ms' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

def ws_state(self) -> str:
return self.state

def agent_id(self) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

async def capture(self) -> None:
self.calls.append("capture")

def should_stop(self) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

@codacy-production

codacy-production Bot commented Jul 22, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 critical · 33 high · 7 medium · 10 minor

Alerts:
⚠ 51 issues (≤ 0 issues of at least minor severity)

Results:
51 new issues

Category Results
BestPractice 2 medium
Documentation 5 minor
ErrorProne 33 high
Security 1 critical
CodeStyle 1 minor
Complexity 5 medium
4 minor

View in Codacy

🟢 Metrics 287 complexity · 18 duplication

Metric Results
Complexity 287
Duplication 18

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

let pythonScriptPromise = null;
let pythonRuntimePromise = null;

export default async function init() {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'


Found non-compliant syntax. Confirm that there are no syntax errors before committing your code to a version control system.

results = build_results(faces, width, height)
now_s = time.monotonic() - self.started_at
if results:
self.crop = smooth_crop(self.crop, eye_region_crop(results[0], width, height))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'crop' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

event_json: str | None = None
capture_count = 0
if now_s * 1000.0 - self.last_analysis_ms >= ANALYSIS_INTERVAL_MS:
self.last_analysis_ms = now_s * 1000.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'last_analysis_ms' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

capture_count = 0
if now_s * 1000.0 - self.last_analysis_ms >= ANALYSIS_INTERVAL_MS:
self.last_analysis_ms = now_s * 1000.0
self.analysis = analyze_window(list(self.history))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'analysis' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

event_json = eye_event_json(eye_event_payload(results, self.analysis, width, height))
indicator_active = self.analysis["misalignment"]["detected"] or self.analysis["oscillation"]["detected"]
if indicator_active and not self.indicator_was_active:
self.captured_for_episode = False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'captured_for_episode' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

if indicator_active and not self.indicator_was_active:
self.captured_for_episode = False
if indicator_active and not self.captured_for_episode and upload_consent:
self.captured_for_episode = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'captured_for_episode' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

if indicator_active and not self.captured_for_episode and upload_consent:
self.captured_for_episode = True
capture_count += 1
self.indicator_was_active = indicator_active

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'indicator_was_active' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

self.indicator_was_active = indicator_active

if now_s * 1000.0 - self.last_periodic_capture_ms >= PERIODIC_CAPTURE_INTERVAL_MS:
self.last_periodic_capture_ms = now_s * 1000.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'last_periodic_capture_ms' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

def ws_state(self) -> str:
return self.state

def agent_id(self) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

async def capture(self) -> None:
self.calls.append("capture")

def should_stop(self) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

let pythonScriptPromise = null;
let pythonRuntimePromise = null;

export default async function init() {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'


Found non-compliant syntax. Confirm that there are no syntax errors before committing your code to a version control system.

results = build_results(faces, width, height)
now_s = time.monotonic() - self.started_at
if results:
self.crop = smooth_crop(self.crop, eye_region_crop(results[0], width, height))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'crop' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

event_json: str | None = None
capture_count = 0
if now_s * 1000.0 - self.last_analysis_ms >= ANALYSIS_INTERVAL_MS:
self.last_analysis_ms = now_s * 1000.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'last_analysis_ms' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

capture_count = 0
if now_s * 1000.0 - self.last_analysis_ms >= ANALYSIS_INTERVAL_MS:
self.last_analysis_ms = now_s * 1000.0
self.analysis = analyze_window(list(self.history))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'analysis' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

event_json = eye_event_json(eye_event_payload(results, self.analysis, width, height))
indicator_active = self.analysis["misalignment"]["detected"] or self.analysis["oscillation"]["detected"]
if indicator_active and not self.indicator_was_active:
self.captured_for_episode = False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'captured_for_episode' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

if indicator_active and not self.indicator_was_active:
self.captured_for_episode = False
if indicator_active and not self.captured_for_episode and upload_consent:
self.captured_for_episode = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'captured_for_episode' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

if indicator_active and not self.captured_for_episode and upload_consent:
self.captured_for_episode = True
capture_count += 1
self.indicator_was_active = indicator_active

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'indicator_was_active' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

self.indicator_was_active = indicator_active

if now_s * 1000.0 - self.last_periodic_capture_ms >= PERIODIC_CAPTURE_INTERVAL_MS:
self.last_periodic_capture_ms = now_s * 1000.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute 'last_periodic_capture_ms' defined outside __init__


Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

def ws_state(self) -> str:
return self.state

def agent_id(self) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

async def capture(self) -> None:
self.calls.append("capture")

def should_stop(self) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

@pierre-tenedero
pierre-tenedero marked this pull request as ready for review July 22, 2026 23:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js`:
- Line 297: Replace the Unicode ellipsis character in the UI strings within the
relevant runtime setup messages, including the occurrences near
setLoadingMessage and the other referenced locations, with the ASCII sequence
"...". Preserve the surrounding wording and behavior while ensuring all
specified strings remain ASCII-only.
- Around line 109-116: Update loadPythonRuntime so the global py is assigned
only after pyodide.pyimport("pydemo1") and py.config().toJs(...) both succeed.
Use a local temporary for the imported module, then commit it to py after cfg is
initialized, while preserving the existing cleanup behavior and retry guard.
- Around line 755-792: Update runEyeDetection to use demo.captureSeconds when
calculating the elapsed capture duration instead of EYE_DETECTION_SECONDS,
keeping the existing timing, completion, and cleanup behavior unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c83a2a15-764a-40ae-979f-048ebd1a2a78

📥 Commits

Reviewing files that changed from the base of the PR and between 3052768 and cb6beb9.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (17)
  • .mise/config.coverage.toml
  • .mise/config.python.toml
  • config/coverage.toml
  • config/pyrefly.toml
  • pyproject.toml
  • services/ws-modules/pydemo1/pkg/.gitignore
  • services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js
  • services/ws-modules/pydemo1/pkg/package.json
  • services/ws-modules/pydemo1/pydemo1/__init__.py
  • services/ws-modules/pydemo1/pydemo1/demo.py
  • services/ws-modules/pydemo1/pyproject.toml
  • services/ws-modules/pydemo1/tests/test_demo.py
  • services/ws-modules/pyspeech1/pkg/et_ws_pyspeech1.js
  • services/ws-modules/pyspeech1/pyspeech1/speech_detection.py
  • services/ws-server/static/app.js
  • services/ws-server/static/meters.js
  • services/ws-web-runner/tests/modules.rs

Comment on lines +109 to +116
try {
setPreparationStatus("Importing the combined demo workflow...");
py = pyodide.pyimport("pydemo1");
cfg = py.config().toJs({ dict_converter: Object.fromEntries });
} finally {
if (globalThis.__etPyCov) await globalThis.__etPyCov.stop(pyodide, "pydemo1");
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Partial runtime init leaves py set but cfg undefined, breaking retries.

py is assigned at Line 111 before cfg at Line 112. If config() fails, loadPythonRuntime still leaves the global py truthy, so its early if (py) return; (Line 79) short-circuits on the next attempt (e.g. after the preload .catch re-enables the Load button). cfg stays undefined and later cfg.eye.bundle_path in loadModels throws. Assign py only after cfg succeeds.

🛠️ Proposed fix
   try {
     setPreparationStatus("Importing the combined demo workflow...");
-    py = pyodide.pyimport("pydemo1");
-    cfg = py.config().toJs({ dict_converter: Object.fromEntries });
+    const demoModule = pyodide.pyimport("pydemo1");
+    cfg = demoModule.config().toJs({ dict_converter: Object.fromEntries });
+    py = demoModule;
   } finally {
     if (globalThis.__etPyCov) await globalThis.__etPyCov.stop(pyodide, "pydemo1");
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
setPreparationStatus("Importing the combined demo workflow...");
py = pyodide.pyimport("pydemo1");
cfg = py.config().toJs({ dict_converter: Object.fromEntries });
} finally {
if (globalThis.__etPyCov) await globalThis.__etPyCov.stop(pyodide, "pydemo1");
}
}
try {
setPreparationStatus("Importing the combined demo workflow...");
const demoModule = pyodide.pyimport("pydemo1");
cfg = demoModule.config().toJs({ dict_converter: Object.fromEntries });
py = demoModule;
} finally {
if (globalThis.__etPyCov) await globalThis.__etPyCov.stop(pyodide, "pydemo1");
}
}
🧰 Tools
🪛 ast-grep (0.44.1)

[error] 109-109: React's useState should not be directly called
Context: setPreparationStatus("Importing the combined demo workflow...")
Note: [CWE-710] Improper Adherence to Coding Standards. Security best practice.

(usestate-direct-usage)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js` around lines 109 - 116,
Update loadPythonRuntime so the global py is assigned only after
pyodide.pyimport("pydemo1") and py.config().toJs(...) both succeed. Use a local
temporary for the imported module, then commit it to py after cfg is
initialized, while preserving the existing cleanup behavior and retry guard.

});

try {
setLoadingMessage(demo, py ? "Local Python runtime ready" : "Finishing local Python runtime setup…");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace non-ASCII ellipsis with ASCII.

These UI strings use the Unicode ellipsis (U+2026): also at Lines 424, 603, 665, 674, and 675. Use ... to stay ASCII-only. As per coding guidelines: "Write only ASCII characters, except in explicitly exempt generated, verification, help, license, and binary paths."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js` at line 297, Replace the
Unicode ellipsis character in the UI strings within the relevant runtime setup
messages, including the occurrences near setLoadingMessage and the other
referenced locations, with the ASCII sequence "...". Preserve the surrounding
wording and behavior while ensuring all specified strings remain ASCII-only.

Source: Coding guidelines

Comment on lines +755 to +792
async function runEyeDetection(state, demo) {
let lastInference = 0;
while (!demo.stopped && performance.now() - demo.startedAt < EYE_DETECTION_SECONDS * 1000) {
const now = performance.now();

if (now - lastInference >= 50) {
lastInference = now;
captureEyeFrame(demo);
const result = demo.landmarker.detectForVideo(demo.eyeFrame, now);
const faces = (result.faceLandmarks ?? []).map((face) => {
const flat = [];
for (const point of face) flat.push(point.x, point.y);
return flat;
});
const capture = JSON.stringify({
faces,
width: demo.video.videoWidth,
height: demo.video.videoHeight,
upload_consent: demo.uploadConsent,
});
const processed = py.process_eye_capture(capture).toJs({ dict_converter: Object.fromEntries });
const eyePayload = JSON.parse(processed.results_json);
demo.eyeResults = eyePayload.faces;
demo.eyeAnalysis = eyePayload.analysis;
demo.eyeCrop = eyePayload.crop;
if (processed.event_json) state.client?.send?.(processed.event_json);
for (let index = 0; index < processed.capture_count; index++) {
await saveEyeCapture(state, demo);
}
}
await nextFrame();
}
if (!demo.stopped) {
demo.eyeComplete = true;
renderEyeFrame(demo);
stopVideo(demo);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== File outline ==\n'
ast-grep outline services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js --view expanded | sed -n '1,220p'

printf '\n== Search for capture timing symbols ==\n'
rg -n --no-heading 'EYE_DETECTION_SECONDS|captureSeconds|eyeComplete|speech|runEyeDetection|runSpeech|capture window|COMPLETE' services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js

printf '\n== Relevant slice around runEyeDetection ==\n'
sed -n '720,820p' services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js

printf '\n== Relevant slice around speech capture logic ==\n'
sed -n '620,720p' services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js

Repository: edge-toolkit/core

Length of output: 17299


Use the shared capture duration for eye detection. runEyeDetection still stops after the hardcoded 30s constant, while speech capture and the countdown use demo.captureSeconds. Any value other than 30 makes the two panels finish at different times, so drive both from the same duration source.

🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis

[warning] 769-769: services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js#L769
Avoid trailing commas in object or array literals

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/ws-modules/pydemo1/pkg/et_ws_pydemo1.js` around lines 755 - 792,
Update runEyeDetection to use demo.captureSeconds when calculating the elapsed
capture duration instead of EYE_DETECTION_SECONDS, keeping the existing timing,
completion, and cleanup behavior unchanged.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.98198% with 20 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
services/ws-modules/pydemo1/pydemo1/demo.py 81.48% 10 Missing and 10 partials ⚠️

📢 Thoughts on this report? Let us know!

@jayvdb jayvdb changed the title Add pyeye1 and pyspeech1 demo Add pydemo1 Jul 23, 2026
@pierre-tenedero
pierre-tenedero merged commit 83cae82 into main Jul 23, 2026
29 of 34 checks passed
@pierre-tenedero
pierre-tenedero deleted the pydemo1 branch July 23, 2026 00:31
@coderabbitai coderabbitai Bot mentioned this pull request Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants