Skip to content

Commit

Permalink
Merge pull request #695 from NextCenturyCorporation/MCS-1814
Browse files Browse the repository at this point in the history
MCS-1814 [Webenabled] Add task descriptions
  • Loading branch information
rartiss55 authored Sep 14, 2023
2 parents 9b0f7b4 + c649011 commit 44cfb3f
Show file tree
Hide file tree
Showing 26 changed files with 553 additions and 33 deletions.
20 changes: 19 additions & 1 deletion webenabled/mcs_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from os.path import exists

from flask import current_app
from mcs_task_desc import TaskDescription
from PIL import Image
from subprocess_runner import (is_file_open, is_process_running,
start_subprocess)
Expand Down Expand Up @@ -97,12 +98,13 @@ def load_scene(self, scene_filename: str):
self.scene_filename = scene_filename
action_list_str = self.get_action_list()
goal_info = self.get_goal_info(scene_filename)
task_desc = self.get_task_desc(scene_filename)
self.step_number = 0
self.scene_id = scene_filename[
(scene_filename.rfind('/') + 1):(scene_filename.rfind('.'))
]
_, img, step_output = self._post_step_and_get_output(scene_filename)
return img, step_output, action_list_str, goal_info
return img, step_output, action_list_str, goal_info, task_desc

def perform_action(self, params: object):
key = params["keypress"]
Expand Down Expand Up @@ -321,6 +323,22 @@ def get_goal_info(self, scene_filename):
self.logger.exception("Exception in reading goal from json file")
return {}

def get_task_desc(self, scene_filename):
"""Get task description based on filename from mcs_task_desc.py"""
self.logger.info(
f"Attempt to get task description based"
f"on scene_filename: {scene_filename}")
scene_type = scene_filename.split('/')[-1].split('0')[0][:-1].upper()

for description in TaskDescription:
if (description.name == scene_type):
self.logger.info(
f"Scene type identified: {description.name}")
return description.value

self.logger.info("Scene type not found, returning 'N/A'")
return "N/A"

def get_controller_pid(self):
return self.pid

Expand Down
480 changes: 480 additions & 0 deletions webenabled/mcs_task_desc.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion webenabled/mcsweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def handle_scene_selection():

# Get the scene filename and tell interface to load it.
scene_filename = clean_request_data(request)
img, step_output, action_list, goal_info = mcs_interface.load_scene(
img, step_output, action_list, goal_info, task_desc = mcs_interface.load_scene( # noqa: E501
"scenes/" + scene_filename)
app.logger.info(f"Start scene: {scene_filename}, output: {img}")
resp = jsonify(
Expand All @@ -204,6 +204,7 @@ def handle_scene_selection():
image=img,
scene=scene_filename,
goal=goal_info,
task_desc=task_desc,
step=0,
step_output=step_output
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
"z": 12
}
],
"name": "interactive_tool_use_0001_09",
"name": "interactive_asymmetric_tool_use_0001_09",
"objects": [
{
"id": "bd91a6bc-0b25-4c22-a276-cce2bdec6faf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
"z": 12
}
],
"name": "interactive_tool_use_0001_10",
"name": "interactive_asymmetric_tool_use_0001_10",
"objects": [
{
"id": "bd91a6bc-0b25-4c22-a276-cce2bdec6faf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
"z": 12
}
],
"name": "interactive_tool_use_0001_11",
"name": "interactive_asymmetric_tool_use_0001_11",
"objects": [
{
"id": "bd91a6bc-0b25-4c22-a276-cce2bdec6faf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
"z": 12
}
],
"name": "interactive_tool_use_0001_12",
"name": "interactive_asymmetric_tool_use_0001_12",
"objects": [
{
"id": "bd91a6bc-0b25-4c22-a276-cce2bdec6faf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
"z": 12
}
],
"name": "interactive_tool_use_0001_13",
"name": "interactive_asymmetric_tool_use_0001_13",
"objects": [
{
"id": "bd91a6bc-0b25-4c22-a276-cce2bdec6faf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
"z": 12
}
],
"name": "interactive_tool_use_0001_14",
"name": "interactive_asymmetric_tool_use_0001_14",
"objects": [
{
"id": "bd91a6bc-0b25-4c22-a276-cce2bdec6faf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
"z": 12
}
],
"name": "interactive_tool_use_0001_15",
"name": "interactive_asymmetric_tool_use_0001_15",
"objects": [
{
"id": "bd91a6bc-0b25-4c22-a276-cce2bdec6faf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
"z": 12
}
],
"name": "interactive_tool_use_0001_16",
"name": "interactive_asymmetric_tool_use_0001_16",
"objects": [
{
"id": "bd91a6bc-0b25-4c22-a276-cce2bdec6faf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"z": 7
}
],
"name": "interactive_tool_use_0001_01",
"name": "interactive_symmetric_tool_use_0001_01",
"objects": [
{
"id": "4bc60ef7-4b55-4905-89b9-95545e3bfa06",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"z": 6
}
],
"name": "interactive_tool_use_0001_02",
"name": "interactive_symmetric_tool_use_0001_02",
"objects": [
{
"id": "4bc60ef7-4b55-4905-89b9-95545e3bfa06",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"z": 7
}
],
"name": "interactive_tool_use_0001_03",
"name": "interactive_symmetric_tool_use_0001_03",
"objects": [
{
"id": "4bc60ef7-4b55-4905-89b9-95545e3bfa06",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"z": 6
}
],
"name": "interactive_tool_use_0001_04",
"name": "interactive_symmetric_tool_use_0001_04",
"objects": [
{
"id": "4bc60ef7-4b55-4905-89b9-95545e3bfa06",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"z": 7
}
],
"name": "interactive_tool_use_0001_05",
"name": "interactive_symmetric_tool_use_0001_05",
"objects": [
{
"id": "4bc60ef7-4b55-4905-89b9-95545e3bfa06",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"z": 6
}
],
"name": "interactive_tool_use_0001_06",
"name": "interactive_symmetric_tool_use_0001_06",
"objects": [
{
"id": "4bc60ef7-4b55-4905-89b9-95545e3bfa06",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"z": 7
}
],
"name": "interactive_tool_use_0001_07",
"name": "interactive_symmetric_tool_use_0001_07",
"objects": [
{
"id": "4bc60ef7-4b55-4905-89b9-95545e3bfa06",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"z": 6
}
],
"name": "interactive_tool_use_0001_08",
"name": "interactive_symmetric_tool_use_0001_08",
"objects": [
{
"id": "4bc60ef7-4b55-4905-89b9-95545e3bfa06",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
"z": 9
}
],
"name": "interactive_tool_use_0001_17",
"name": "interactive_tool_choice_0001_17",
"objects": [
{
"id": "947fa286-4b90-4ca1-9486-5e5a10ea68c8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
"z": 9
}
],
"name": "interactive_tool_use_0001_18",
"name": "interactive_tool_choice_0001_18",
"objects": [
{
"id": "f3c6b0cb-06bd-44a2-bfa8-113cd3a1adb8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
"z": 9
}
],
"name": "interactive_tool_use_0001_19",
"name": "interactive_tool_choice_0001_19",
"objects": [
{
"id": "54365d9d-f6d8-41b9-8030-cbeafcd1faa9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
"z": 9
}
],
"name": "interactive_tool_use_0001_20",
"name": "interactive_tool_choice_0001_20",
"objects": [
{
"id": "fc69081c-2526-42e3-b4af-b4c6e2343610",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
"z": 10
}
],
"name": "interactive_tool_use_0001_21",
"name": "interactive_tool_choice_0001_21",
"objects": [
{
"id": "186db014-1d47-4783-b431-7ee950f4bdae",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
"z": 9
}
],
"name": "interactive_tool_use_0001_22",
"name": "interactive_tool_choice_0001_22",
"objects": [
{
"id": "fc69081c-2526-42e3-b4af-b4c6e2343610",
Expand Down
39 changes: 30 additions & 9 deletions webenabled/templates/mcs_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

div#scene-nav-info {
flex: 1;
display: flex;
flex-direction: column;
margin-bottom: 10px
}

Expand Down Expand Up @@ -84,6 +86,8 @@

#shortcuts {
margin-right: 15px;
display: flex;
flex-direction: column;
}

.center {
Expand Down Expand Up @@ -152,7 +156,6 @@
}

select {
width: 90%;
font-family: inherit;
font-size: inherit;
line-height: inherit;
Expand Down Expand Up @@ -200,8 +203,13 @@
flex-direction: column;
}

#scene-demo {
display: flex;
flex-direction: column;
}

.left-panel {
min-width: 400px;
display: flex;
max-width: 550px;
}

Expand Down Expand Up @@ -271,6 +279,12 @@ <h1>Machine Common Sense</h1>
<span><strong>Scene Name: </strong></span>
<span id="scene-filename">None - Please select a scene.</span>
</div>

<div id="task-desc-div">
<span><strong>Task Description: </strong></span>
<span id="task-desc">N/A</span>
</div>

<div id="goal-div">
<span><strong>Goal: </strong></span>
<span id="goal-cat"></span><span id="goal-desc">N/A</span>
Expand Down Expand Up @@ -421,6 +435,7 @@ <h1>Machine Common Sense</h1>
{method: 'POST', body: JSON.stringify(sceneSelect.value)})
.then(parseJsonResponse)
.then(updateSceneFilename)
.then(updateTaskDesc)
.then(updateStepNumber)
.then(updateActionList)
.then(updateGoalInfo)
Expand Down Expand Up @@ -466,16 +481,15 @@ <h1>Machine Common Sense</h1>
}

if("description" in data.goal) {
if(hasNoDesc) {
document.getElementById("goal-desc").style.display = "none"
} else {
document.getElementById("goal-desc").style.display = "inline"
document.getElementById("goal-desc").style.display = "inline"

let goalDesc = document.getElementById('goal-desc');
goalDesc.innerHTML = data.goal.description;
}
let goalDesc = document.getElementById('goal-desc');
goalDesc.innerHTML = data.goal.description;
} else {
console.warn("description not in goalInfo");
if(hasNoDesc) {
document.getElementById("goal-desc").style.display = "none"
}
}

if("last_step" in data.goal) {
Expand Down Expand Up @@ -552,6 +566,13 @@ <h1>Machine Common Sense</h1>
return data;
}

function updateTaskDesc(data) {
console.log("taskDescription is " + data.task_desc);
let taskDesc = document.getElementById('task-desc');
taskDesc.innerHTML = data.task_desc;
return data;
}

function updateSceneFilename(data) {
console.log("sceneFilename is " + data.scene);
var sceneFilename = document.getElementById('scene-filename');
Expand Down

0 comments on commit 44cfb3f

Please sign in to comment.