Skip to content

Commit

Permalink
Merge pull request #315 from mitmedialab/dev_TMButton
Browse files Browse the repository at this point in the history
Implementing a button to open Teachable Machine
  • Loading branch information
pmalacho-mit authored Nov 27, 2023
2 parents a0571ac + 373819c commit fde1397
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ export default function legacySupportMixin<T extends MinimalExtensionConstructor
return { menuUpdates, replaceAt: { index, block: legacyBlock } };
});

updates.forEach(({ replaceAt: { index, block } }) => mutableBlocks[index] = block);
updates.forEach(({ replaceAt: { index, block } }) => {
const current = mutableBlocks[index];
mutableBlocks[index] = block;
if (block.blockType === "button") mutableBlocks[index].func = current.func;
});

updates
.map(({ menuUpdates }) => menuUpdates)
Expand Down
14 changes: 11 additions & 3 deletions extensions/src/teachableMachine/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Environment, extension } from "$common";
import { Environment, buttonBlock, extension } from "$common";
import tmImage from '@teachablemachine/image';
import tmPose from '@teachablemachine/pose';
import { create } from '@tensorflow-models/speech-commands';
import { legacyFullSupport, } from "./legacy";

const { legacyExtension, legacyBlock } = legacyFullSupport.for<teachableMachine>();
const { legacyBlock, legacyExtension } = legacyFullSupport.for<teachableMachine>();
const VideoState = {
/** Video turned off. */
OFF: 'off',
Expand All @@ -26,7 +26,6 @@ export default class teachableMachine extends extension({
insetIconURL: "teachable-machine-blocks-small.svg",
tags: ["Dancing with AI", "Made by PRG"]
}) {

lastUpdate: number;
maxConfidence: number;
modelConfidences: {};
Expand Down Expand Up @@ -310,6 +309,14 @@ export default class teachableMachine extends extension({
this.runtime.ioDevices.video.setPreviewGhost(trans);
}

/**
* Opens a new tab with the Google Teachable Machine website
*/
@buttonBlock("Teachable Machine Site ↗")
openTeachableMachine() {
window.open('https://teachablemachine.withgoogle.com/train', '_blank');
}

@legacyBlock.useModelBlock()
useModelBlock(url: string) {
this.useModel(url);
Expand Down Expand Up @@ -352,4 +359,5 @@ export default class teachableMachine extends extension({
setVideoTransparency(transparency: number) {
this.setTransparency(transparency);
}

}
1 change: 0 additions & 1 deletion packages/scratch-gui/src/containers/blocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class Blocks extends React.Component {
toolboxWorkspace.registerButtonCallback('MAKE_A_LIST', varListButtonCallback('list'));
toolboxWorkspace.registerButtonCallback('MAKE_A_PROCEDURE', procButtonCallback);
toolboxWorkspace.registerButtonCallback('CONNECT_MICROBIT_ROBOT', connectMicrobitRobotCallback);

this.props.vm.runtime.on(registerButtonCallbackEvent, (event) => {
toolboxWorkspace.registerButtonCallback(event, () => this.props.vm.runtime.emit(event));
});
Expand Down

0 comments on commit fde1397

Please sign in to comment.