Skip to content

Commit

Permalink
Working on webenabled docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasSchellenbergNextCentury committed Dec 14, 2023
1 parent c41191b commit 450f09a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def get_version():
'numpyencoder==0.3.0',
'opencv-python==4.4.0.46; python_version<="3.9"',
'opencv-python==4.5.4.60; python_version>="3.10"',
'portalocker',
'pydantic==1.10.7',
'requests==2.31.0',
'scikit-image==0.19.3',
Expand Down
34 changes: 22 additions & 12 deletions webenabled/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Running MCS on the web
# Machine Common Sense Web Browser Demo

## Install
This MCS web app lets you run scenes in your web browser, using your keyboard to move around and perform actions like an AI would.

## Usage

TODO

## Development

### Install

First, "git clone" this repository. Then run the following commands from this folder to setup your python environment:

Expand All @@ -17,38 +25,40 @@ If you are a developer for this software, we recommend you install the machine_c
python -m pip install -e ../
```

## Scene Files
### Scene Files

Put scene json files into scenes/. The directory will be scanned and the list of
scene files will appear on the web page

## Run Web Server
### Run Web Server

First, run `cache_addressables` to cache all addressable assets and prevent possible timeout issues. You should do this each time you reboot your machine.

Then, run `python mcsweb.py` to start the flask server with host `0.0.0.0` (so the page will be accessable from any machine on the network) and port `8080`.

Alternatively, run `python mcsweb.py` to see all of the available options. The `--debug` flag is very helpful for development.

## Use

On same or other machine, go to:
Then, on your machine (or another machine on your network), in your web browser, go to:

```
http://<machine.ip.address>:8080/mcs
```

## Overview
If accessing on your local machine, you can use `localhost` instead of an IP address.

### Overview

1. Routing is done in `mcsweb`. Loading `localhost:8080/mcs` calls `show_mcs_page`. This uses `request.cookies` to identify new user sessions. A single `MCSInterface` is instantiated for each user session. The page is rendered using `templates/mcs_page.html`.
2. The `MCSInterface` class creates the `cmd_<time>/` and `output_<time>/` directories in `static/mcsinterface/` for the input and output data for the current user session. It starts a subprocess in a separate thread which runs `run_scene_with_dir.py`. It watches the `output_<time>/` directory for step output and images the subprocess saves in that directory, which are the images returned by action steps.
3. The `run_scene_with_dir` script creates the MCS Controller and starts a watchdog Observer to watch for changes to the `cmd_<time>/` directory. Whenever a new "command" text file is created or modified, it triggers the Observer, which reads the command (either a scene filename ending in ".json" or an MCS action like Pass or MoveAhead), gives it to the MCS Controller via either its `start_scene` or `step` function, and saves step output and the output image in the `output_<time>` directory.
4. When the user selects a scene in the UI, the `handle_scene_selection` function in `mcsweb` calls `load_scene` in `MCSInterface` which saves a "command" text file containing the scene filename.
5. When the user presses a key in the UI, the `handle_keypress` function in `mcsweb` calls `perform_action` in `MCSInterface` which saves a "command" text file containing the action string.

## Pyinstaller
### Pyinstaller

Please note: Your python virtual environment must be installed in this folder (`venv/` is inside `webenabled/`) and activated.

### Linux and Mac
#### Linux and Mac

Setup:

Expand All @@ -74,12 +84,12 @@ Cleanup (do before you need to rebuild):
rm -rf build/ dist/
```

### Windows
#### Windows

Same as the Linux/Mac instructions, except as noted below.

Build:

```
pyinstaller --add-data "templates;templates" --add-data "static;static" --add-data "scenes;scenes" --console mcsweb.py --log-level=DEBUG -y *>&1 | Tee-Object -Append -FilePath pyinstaller.out
pyinstaller --add-data "templates;templates" --add-data "static;static" --add-data "scenes;scenes" --console mcsweb.py --log-level=DEBUG *>&1 | Tee-Object -Append -FilePath pyinstaller.out
```
3 changes: 1 addition & 2 deletions webenabled/mcs_task_desc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from enum import Enum, unique
from enum import Enum


@unique
class TaskDescription(Enum):
"""
The names for each enum correspond to the naming conventions currently
Expand Down

0 comments on commit 450f09a

Please sign in to comment.