Access Crowd HTML output results - amazon-sagemaker

I'm creating a website using the Crowd HTML Elements that let users/workers annotate images with the bounding box format. The form looks like this:
<crowd-form>
<crowd-bounding-box
name="annotatedResult"
labels="['Referee', 'Player']"
src="https://s3.amazonaws.com/cv-demo-images/basketball-outdoor.jpg"
header="Draw boxes around each basketball player and referee in this image"
>
<full-instructions header="Bounding Box Instructions" >
<p>Use the bounding box tool to draw boxes around the requested target of interest:</p>
<ol>
<li>Draw a rectangle using your mouse over each instance of the target.</li>
<li>Make sure the box does not cut into the target, leave a 2 - 3 pixel margin</li>
<li>
When targets are overlapping, draw a box around each object,
include all contiguous parts of the target in the box.
Do not include parts that are completely overlapped by another object.
</li>
<li>
Do not include parts of the target that cannot be seen,
even though you think you can interpolate the whole shape of the target.
</li>
<li>Avoid shadows, they're not considered as a part of the target.</li>
<li>If the target goes off the screen, label up to the edge of the image.</li>
</ol>
</full-instructions>
<short-instructions>
Draw boxes around each basketball player and referee in this image.
</short-instructions>
</crowd-bounding-box>
</crowd-form>
The results of a worker's submission looks like the following:
{
"annotatedResult": {
"boundingBoxes": [
{
"height": 3300,
"label": "Dog",
"left": 536,
"top": 154,
"width": 4361
}
],
"inputImageProperties": {
"height": 3456,
"width": 5184
}
}
}
]
I'd like to take this output and write it to a database, pass it to AWS Lambda, store it as metadata, etc. but I don't know how to access the results. Is the JSON output a property of some HTML DOM property I can grab?
I can attach a javascript function to the submit action of the crowd-form portion...
<script>
document.querySelector('crowd-form').onsubmit = function() {
???
};
</script>
...but I'm not sure what object I need to grab to get the results. Thanks for your help!

You can access the bounding boxes during the onsubmit event like this:
<script>
document.querySelector('crowd-form').onsubmit = function(e) {
const boundingBoxes = document.querySelector('crowd-bounding-box').value.boundingBoxes || document.querySelector('crowd-bounding-box')._submittableValue.boundingBoxes;
}
</script>
Here's a working jsfiddle.
Your use case sounds interesting. If you don't mind sharing, please email me at samhenry#amazon.com and I may be able to help further.
Thank you,
Amazon Mechanical Turk

Related

With react-Chart-js2, is there a way to add more fields to the datasets, for example, text that accompanies data that was submitted?

I have a chart that displays people's predictions on events from a scale of 0-100. To accompany their submissions, I ask for a comment explaining why they said what they said. This is a crowdsourcing project so it would benefit other users if they could see what other users are thinking. Their predictions are stored in objects, like:
forecast: {
certainty: 0.6,
comments: "I said 60% because I think that this is pretty likely",
date: "Tue Feb 22 2022"
}
And these forecasts are displayed like this:
But I would love it if when hovering over the data in the chart, you could also see the comment:
In the picture above, that data is stored in the following format:
let allData = {
label: "AllData",
data: [],
showLine: false,
borderWidth: 0,
pointRadius: 4
}
and then the actual elements inside that data array is stored like:
let myForecast = {
x: dateOfForecast (date variable),
y: myActualForecast (double variable)
}
My thinking was that there would be a way to add a "Description" variable to that myForecast object to accompany the x and the y values, like this:
let myForecast = {
x: dateOfForecast (date variable),
y: myActualForecast (double variable),
description: "I said 60% because I think that this is pretty likely"
}
but as far as I can tell there is nothing in the APIs allowing this. I would love to be wrong!
Thank you in advance, I hope my question makes sense and is clear.
Thanks to some wider reading, I found this answer from another post: https://stackoverflow.com/a/70387861/12464559
Where the accepted answer suggests using the callback provided by ChartJS (the options object for your chart > plugins > tooltip > callback).
I console.log()'d the context object that it passes into the callback, thus allowing me to find where in that context object the x, y and description values for each datapoint were stored (they were in the context variable > raw). I then appended the description like this:
tooltip: {
console.log(context);
let label = context.database.label || '';
if (label) {
label += context.raw.description;
}
return label;
}
Hope this helps anyone in the future! Full credit to toki in the post shared above!

Alexa Skill renders display card in Alexa companion app

How To add an image to this card or how remove it totally?
How to add an image to Alexa Card ?
Form the official documentation(https://developer.amazon.com/docs/custom-skills/include-a-card-in-your-skills-response.html#creating-a-basic-home-card-to-display-text)
A home card can include a single image. In this case, you provide the
title, text, and two URLs (a small version and large version) for the
image to display.
Note that the total number of characters (title, content, and both
URLs combined) for the card cannot exceed 8000. Each URL cannot exceed
2000 characters.
To create a card with an image, include the card property in your JSON
response:
Set the type to Standard. Set the title and text properties to the
text to display. Note that this type of card uses a text property, not
a content property like Simple. Use either "\r\n" or "\n" within the
text to insert line breaks. Include an image object with smallImageUrl
and largeImageUrl properties. Set smallImageUrl and largeImageUrl to
the URLs of a small and large version of the image to display. See
below for details about the image format, size, and hosting
requirements.
{
"version": "1.0",
"response": {
"outputSpeech": {"type":"PlainText","text":"Your Car-Fu car is on the way!"},
"card": {
"type": "Standard",
"title": "Ordering a Car",
"text": "Your ride is on the way to 123 Main Street!\nEstimated cost for this ride: $25",
"image": {
"smallImageUrl": "https://carfu.com/resources/card-images/race-car-small.png",
"largeImageUrl": "https://carfu.com/resources/card-images/race-car-large.png"
}
}
}
}
When using the Java library:
Create a StandardCard object. Call the object's setTitle() and
setText() methods to set the title and content. Create an Image object
and assign the URLs with the object's setSmallImageUrl() and
setLargeImageUrl() methods. Pass the Image object to the StandardCard
object with the setImage() method. Pass the StandardCard object to
either SpeechletResponse.newTellResponse() or
SpeechletResponse.newAskResponse() to get a SpeechletResponse that
includes the card.

Updating scope with an attribute that is being changed manually

I've been thinking for hours about this problem and haven't been able to figure out how to do it in an elegant way.
I'm implementing a simple video player where I let the user trim the video (meaning, choose a start and end time). I get a dynamic array of videos from the server, looks something like this:
$scope.videos =
[{
id: "1",
start: 122,
end: 187,
length: 352,
url: "https://www.youtube.com/watch?v=-ePGMfDkTHo"
},
{
id: "2",
start: 122,
end: 187,
length: 352,
url: "https://www.youtube.com/watch?v=dVlM2LW90nU"
}... etc];
And with ng-repeat I display the videos on the client.
This is what I have in my view for each iframe that hold a video:
<iframe class="video" length="{{asset.length}}" start="{{asset.start}}" end="{{asset.end}}" original-url="{{ asset.url }}" data-value-start="asset.start"></iframe>
(where asset represent a video in the array)
I have a play bar where I let the user change the start and end time of the videos. Once the user changes the start and end time from the view I change the custom attributes accordingly in the iframe tag:
$scope.$apply(function()
{
$caller.attr('src',$scope.trustSrc(createEmbedUrl(url, $scope.newAssetData.start, $scope.newAssetData.end)));
$caller.attr('start', $scope.newAssetData.start);
});
My problem is, that once the user is done changing the times, I need to send back to the server the new start and end time. I was expecting that changing 'start' and 'end' attribute would change the same attributes in the video scope variable but it doesn't happen. I was thinking od "dirty" ways to solve this problem without Angular (such as adding another custom attribute in the view of 'vidId' and have it be my guide to track the new start and end times but it just seems wrong to do it.
What am I missing?
Thank you,
Mila

Angularjs Dom Manipilation in a Table

i have a table where i can turn pages, you can choose a color for a user and that color is shown in the circle, but when i turn one page, the color is gone!
I read about dom manipluation in directives, but that still didnt solve my problem:
the tutorials mostly show one with a click funktion, and i dont to click the circle
they also werent "permanent"
maybe i did something wrong? please can someone help or give me a hint?
i made also a plnkr :
Here's the link!
You need to save chosen color to currect user object. Maybe like this:
$scope.showColorPicker = function(user) {
data = $scope.colors;
dlg = $dialogs.create('/dialogs/pickColor.html','pickColorCtrl',$scope.colors,{},{key:false ,back:'static'});
dlg.result.then(function(data) {
var colnr = data;
var user_circle = angular.element(document.getElementById('color_' + user.id));
user_circle.context.style.backgroundColor = $scope.colors[colnr-1].color;
user.color = $scope.colors[colnr-1];
});
};
HTML for color circle:
<span class="smallcircle" ng-bind="color_{{user.id}}" id="color_{{user.id}}" name="color_{{user.id}}" style="background-color: {{user.color.color || 'lightgray'}};"></span>
Make sure you pass user object to showColorPicker function:
Change Color
Demo: http://plnkr.co/edit/em0ZUHjbXUNa7MYgpC5f?p=info

How do I highlight Africa and other regions using the Google Visualization Geochart?

I'm trying to find a map solution that is possible to highlight and click on various regions, one region would be Africa. I'm also looking for a solution that will work well with Angularjs.
I thought the Google Visualization Chart might be suitable. This allows the selection of regions using the region codes listed on the site.
I've tried adding a few regions, the only one I could get working was Australia (AU), the following don't work for me:
['Europe', 150],
['Western Asia', 145],
['Asia', 142],
['Africa', 002]
Here's the jsfiddle I'm using to test this.
Am I doing something wrong or is there an issue with the chart itself?
Thank you.
google.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Region Code', 'Continent', 'Popularity'],
['142', 'Asia', 200],
['150', 'Europe', 300],
['019', 'Americas', 400],
['009', 'Oceania', 600],
['002', 'Africa', 700]
]);
var options = {
resolution: 'continents'
};
var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
chart.draw(data, options);
}
This jsfiddle shows how to do it:

Resources