Table of Contents

broadcast ()

Description

The block sends a broadcast throughout the whole Scratch program. Any scripts in any sprites that are hatted with the When I Receive () block that is set to a specified broadcast will activate. This broadcast block lets scripts send broadcasts without any waits in its script (unlike the Broadcast () and Wait block). Broadcasts are a good way to have sprites and scripts communicate.

Example

The example demonstrates the show and hides of the sprite using the buttons.

Script

Output

Read More
The Language Translator with ChatGPT is a powerful system that enables real-time translation and conversation support, facilitating multilingual communication.

Introduction

The Language Translator with ChatGPT and Speech Recognition is a system that helps people communicate across languages by providing real-time translation and conversation support. It combines language translation, chatbot capabilities, and speech recognition to facilitate multilingual communication.

Language Translator Using ChatGPT is a project that trains the ChatGPT language model with multilingual data to enable it to understand and translate text between different languages. It utilizes ChatGPT’s natural language processing abilities to generate human-like responses, making it ideal for building a language translation system. The training data includes sentence pairs in different languages and their corresponding translations.

Logic

Initially, two characters engage in a conversation. One character asks a question, and the other character converts it into a different language before answering it and providing a response.

  1. Open PictoBlox and create a new file.
  2. Select the environment as appropriate Block Coding Environment.
  3. To add the ChatGPT extension, click on the extension button located as shown in the image. This will enable the ChatGPT extension, allowing you to incorporate its capabilities into your project.
  4. To begin, select two sprites Hazel and John from the sprite options in the bottom left corner, as shown in the image.
  5. To upload a backdrop, use the “Choose Backdrop” option, which allows you to select and set a background image or scene for your activity. Backdrops are used as the type of background in our activity.
  6. To create a script, select a different sprite and then add various block scripts to customize its behavior.
  7. Let’s use the sprites Hazel and Joan for our script.
  8. For Hazel, navigate to the costumes section and enable the “Flip Horizontal” option to add a mirror effect. Set the positions of both sprites as if they are talking to each other.
  9. Click on John’s Sprite first. We will now begin writing a script as shown in the image.
  10. First, we will prompt the user to input a sentence. and using the say() method, the sprite will verbally repeat the same answer provided by the user.
  11. Next, by using the broadcast() block, we can send the translated answer to the second sprite to ensure that both sprites have the same response.
  12. select the second Hazel’s sprite and begin with the when I receive a () block. This block will initiate the action when the second sprite receives a message from the first sprite.
  13. Drag and drop the “translate() into()” function into the block. This block will translate any language of your choice. In this example, we are writing in Hindi language.
  14. We utilize the get AI Response block to obtain a response from ChatGPT. Then, using the say() method, Hazel, the sprite, will deliver the answer in translated sentences.
  15. To begin the script, simply click on the green flag button.

Output

Read More
The examples show how to use pose recognition in PictoBlox to maintain a yoga pose for a particular time interval.

Script

The idea is simple, we’ll add one image of  each class in the “costume” column by making one new sprite which will we display on the stage according to input from user. we’ll also change name of the image according to pose.

  1. Add testing images to the backdrop and delete the default backdrop.
  2. Now, come back to the coding tab and select the Tobi sprite.
  3. We’ll start by adding a when flag clicked block from the Events palette.
  4. We made the new variable “count” by choosing the “Make a Variable” option from the Variables palette.
  5. Add the “hide variable () block from the Variables palette. Select count.
  6. Add the “turn () video on stage with () transparency” block from the Machine Learning palette. Select the off option at the first empty place, and for the second, write a 0 value.
  7. Add an “ask () and wait” block from the Sensing palette. Write an appropriate statement in an empty place.
  8. Add the “if () then” block from the control palette for checking the user’s input.
  9. In the empty place of the “if () then” block, add a condition checking block from the operators palette block. At the first empty place, put the answer block from the sensing palette, and at the second place, write an appropriate statement.
  10. Inside the “if () then” block, add a “broadcast ()” block from the Events palette block. Select the “New message” option and write an appropriate statement for broadcasting a message to another sprite.
  11. Add the “turn () video on stage with () transparency” block from the Machine Learning palette. Select the option at the first empty place, and for the second, write a 0 value.
  12. Add the “() key points” block from the Machine Learning palette. Select the show option.
  13. Add the “Set () to ()” block from the Variables palette. Select the count option at the first empty place, and for the second, write a 30 value.
  14. Add the Show variable () block from the Variables palette. Select count.
  15. Add “forever” from the Control palette.
  16. Inside the “forever” block, add an “analysis image from ()” block from the Machine Learning palette. Select the Web camera option.
  17. Inside the “forever” block, add an “if () then” block from the Control palette.
  18. In the empty place of the “if () then” block, add an “is identified class ()” block from the Machine Learning palette. Select the appropriate class from the options.
  19. Inside the “if () then” block, add an “say ()” block from the Looks palette block. Write an appropriate statement in an empty place.
  20. Add “change () by ()” from the Variables palette. Select the count option in the first empty place, and for the second, write a -1 value.

  21. Add the “if () then” block from the control palette for checking the user’s input.
  22. In the empty place of the “if () then” block, add a condition checking block from the operators palette block. In the first empty place, put the “count” block from the sensing palette, and in the second place, write 0.
  23. Add the “Set () to ()” block from the Variables palette. Select the count option at the first empty place, and for the second, write a 30 value.
  24. Add the “turn () video on stage with () transparency” block from the Machine Learning palette. Select the off option at the first empty place, and for the second, write a 0 value.
  25. Inside the “if () then” block, add an “say ()” block from the Looks palette block. Write an appropriate statement in an empty place.
  26. Add the “() key points” block from the Machine Learning palette. Select the hide option
  27. Add the “stop ()” block to the control pallet. Select all options.
  28. Repeat “if () then” block code for other classes, make appropriate changes in copying block code according to other classes, and add code just below it.
  29. The final block code looks like
  30. Now click on another sprite and write code.
  31. We’ll start writing code for this sprite by adding a when flag is clicked block from the Events palette.
  32. Add the “hide” block from the Looks pallet.
  33. Write a new code in the same sprite according to class and add the “when I receive ()” block from the Events palette. Select the appropriate class from the options.
  34. Add the “show” block from the Looks pallet.
  35. Add the “switch costume to ()” block from the Looks palette. Select the appropriate class from the options.
  36. Repeat the same code for other classes and make changes according to the class.

    Final Result

Read More
The example shows how to use a number classifier in PictoBlox to make the Iris Classifier Bot.

Script

The idea is simple, we’ll add one image of  each class in the “costume” column by making one new sprite which will we display on the stage according to input from user. we’ll also change name of the image according to iris type.

  1. Add iris image as another sprite and upload one image of all iris classes on costume.
  2. Now, come back to the coding tab and select the Tobi sprite.
  3. We’ll start by adding a when flag clicked block from the Events palette.
  4. Add an “ask () and wait” block from the Sensing palette. Write an appropriate statement in an empty place.
  5. Add the “set () as ()” block from the Machine Learning palette. Select the SepalLengthCm option at the first empty place, and for the second select an “answer” block from the Sensing palette.
  6. Add an “ask () and wait” block from the Sensing palette. Write an appropriate statement in an empty place.
  7. Add the “set () as ()” block from the Machine Learning palette. Select the SepalWidthCm option at the first empty place, and for the second select an “answer” block from the Sensing palette.
  8. Add an “ask () and wait” block from the Sensing palette. Write an appropriate statement in an empty place.
  9. Add the “set () as ()” block from the Machine Learning palette. Select the PetalLengthCm option at the first empty place, and for the second select an “answer” block from the Sensing palette.
  10. Add an “ask () and wait” block from the Sensing palette. Write an appropriate statement in an empty place.
  11. Add the “set () as ()” block from the Machine Learning palette. Select the PetalWidthCm option at the first empty place, and for the second select an “answer” block from the Sensing palette.
  12. Add an “analyse numbers” block from the Machine Learning palette.
  13. Add the “if () then” block from the control palette for checking the user’s input.
  14. In the empty place of the “if () then” block, add an “is identified class ()” block from the Machine Learning palette. Select the appropriate class from the options.
  15. Inside the “if () then” block, add an “say ()” block from the Looks palette block. Write an appropriate statement in an empty place.
  16. Inside the “if () then” block, add a “broadcast ()” block from the Events palette block. Select the “New message” option and write an appropriate statement for broadcasting a message to another sprite.
  17. Repeat “if () then” block code for other iris classes, make appropriate changes in copying block code according to other classes, and add code just below it.
  18. Final code of “Tobi” sprite is
  19. Now click on another sprite and write code.
  20. We’ll start writing code for this sprite by adding a when flag is clicked block from the Events palette.
  21. Add the “hide” block from the Looks pallet.
  22. Write a new code in the same sprite according to class and add the “when I receive ()” block from the Events palette. Select the appropriate class from the options.
  23. Add the “show” block from the Looks pallet.
  24. Add the “switch costume to ()” block from the Looks palette. Select the appropriate class from the options.
  25. Repeat the same code for other classes and make changes according to the class.

    Final Result

Read More
The example shows how to use a hand pose classifier in PictoBlox to make the Sign Classifier Bot.

Introduction

In this example project, we are going to create a machine learning model that can classify different sign messages from the camera feed or image.

Hand Gesture Classifier in Machine Learning Environment

The Hand Gesture Classifier is the extension of the ML Environment used for classifying different hand poses into different classes.

 

Hand Gesture Classifier Workflow

  1. Open PictoBlox and create a new file.
  2. You can click on “Machine Learning Environment” to open it.
  3. Click on “Create New Project“.
  4. A window will open. Type in a project name of your choice and select the Hand Gesture Classifier” extension. Click the “Create Project” button to open the Pose Classifier window.
  5. You shall see the Gesture Pose Classifier workflow with two classes already made for you. Your environment is all set. Now it’s time to upload the data.

Class in Pose Classifier

Class is the category in which the Machine Learning model classifies the poses. Similar posts are put in one class.

Class in Hand Pose Classifier

Class is the category in which the Machine Learning model classifies the hand poses. Similar hand poses are put in one class.

Adding Data to Class

You can perform the following operations to manipulate the data into a class.

  1. Naming the Class: You can rename the class by clicking on the edit button.
  2. Adding Data to the Class: You can add the data using the Webcam or by Uploading the files from the local folder.
    1. Webcam:

      Note: You can edit the capture setting in the camera with the following. Hold to Record allows you to capture images with pose till the time button is pressed. Whereas when it is off you can set the start delay and duration of the sample collection.

      If you want to change your camera feed, you can do it from the webcam selector in the top right corner.

Training the Model

After data is added, it’s fit to be used in model training. In order to do this, we have to train the model. By training the model, we extract meaningful information from the hand pose, and that in turn updates the weights. Once these weights are saved, we can use our model to make predictions on data previously unseen.

However, before training the model, there are a few hyperparameters that you should be aware of. Click on the “Advanced” tab to view them.

Note: These hyperparameters can affect the accuracy of your model to a great extent. Experiment with them to find what works best for your data.

Note: Hover your mouse over the question mark next to the hyperparameters to see their description.

It’s a good idea to train a numeric classification model for a high number of epochs. The model can be trained in both JavaScript and Python. In order to choose between the two, click on the switch on top of the Training panel.

Alert: Dependencies must be downloaded to train the model in Python, JavaScript will be chosen by default.

The accuracy of the model should increase over time. The x-axis of the graph shows the epochs, and the y-axis represents the accuracy at the corresponding epoch. Remember, the higher the reading in the accuracy graph, the better the model. The x-axis of the graph shows the epochs, and the y-axis represents the corresponding accuracy. The range of the accuracy is 0 to 1.

Testing the Model

To test the model, simply enter the input values in the “Testing” panel and click on the “Predict” button.

The model will return the probability of the input belonging to the classes.

Export in Block Coding

Click on the “Export Model” button on the top right of the Testing box, and PictoBlox will load your model into the Block Coding Environment if you have opened the ML Environment in the Block Coding.

Script

The idea is simple, we’ll add one image of  each class in the “costume” column by making one new sprite which will we display on the stage according to input from user. we’ll also change name of the image according to sign class type.

  1. Add one sign image as another sprite and upload at-least one image of all sign classes on costume.
  2. Now, come back to the coding tab and select the Tobi sprite.
  3. We’ll start by adding a when flag clicked block from the Events palette.
  4. Add the “open recognition window” block from the Machine Learning palette.
  5. Add an “forever” block from the Control palette.
  6. Add the “if () then” block from the control palette for checking the user’s input.
  7. In the empty place of the “if () then” block, add an “is identified class ()” block from the Machine Learning palette. Select the appropriate class from the options.
  8. Inside the “if () then” block, add an “say ()” block from the Looks palette block. Write an appropriate statement in an empty place.
  9. Inside the “if () then” block, add a “broadcast ()” block from the Events palette block. Select the “New message” option and write an appropriate statement for broadcasting a message to another sprite.
  10. Repeat “if () then” block code for other classes, make appropriate changes in copying block code according to other classes, and add code just below it.
  11. Final code of “Tobi” sprite is
  12. Now click on another sprite and write code.
  13. We’ll start writing code for this sprite by adding a when flag is clicked block from the Events palette.
  14. Add the “hide” block from the Looks pallet.
  15. Write a new code in the same sprite according to class and add the “when I receive ()” block from the Events palette. Select the appropriate class from the options.
  16. Add the “show” block from the Looks pallet.
  17. Add the “switch costume to ()” block from the Looks palette. Select the appropriate class from the options.
  18. Repeat the same code for other classes and make changes according to the class.

Final Output

 

Read More
All articles loaded
No more articles to load