{"id":2437,"date":"2021-05-25T00:59:58","date_gmt":"2021-05-24T15:59:58","guid":{"rendered":"https:\/\/appinventor.tmsoftwareinc.com\/?p=2437"},"modified":"2021-05-26T11:00:36","modified_gmt":"2021-05-26T02:00:36","slug":"%e4%ba%ba%e5%b7%a5%e7%9f%a5%e8%83%bd%e7%94%bb%e5%83%8f%e5%88%86%e9%a1%9e%e3%82%a2%e3%83%97%e3%83%aa2","status":"publish","type":"post","link":"https:\/\/appinventor.tmsoftwareinc.com\/en\/archives\/2437","title":{"rendered":"Artificial intelligence Image Classification App 2"},"content":{"rendered":"<h2>Let&#8217;s make an Image Classification App with higher accuracy without extension!<\/h2>\r\n<p>You can change the machine learning model easily, because this app does not use extension.<\/p>\r\n<figure id=\"attachment_2445\" aria-describedby=\"caption-attachment-2445\" style=\"width: 500px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/youtu.be\/px1sihG2xBQ\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/mq1-300x169.jpeg\" alt=\"\" class=\"wp-image-2445\" width=\"500\" height=\"281\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/mq1-300x169.jpeg 300w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/mq1.jpeg 320w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2445\" class=\"wp-caption-text\">Click to see the app in action!<\/figcaption><\/figure>\r\n<p><span>From the Project menu, select New Project and name it &#8220;WhatisThis2&#8221;.<\/span><\/p>\r\n<h3>Why LookExtension extension is not needed?<\/h3>\r\n<p><span data-preserver-spaces=\"true\">With tensorflow.js, you can use machine learning models in a browser. The LookExtension extension developed at MIT uses tensorflow.js. However, it is not easy to change the model because the extension must be rebuilt to change the machine learning model. In addition, the model used in this extension is small in size, so the accuracy is not that good. To solve this problem, we have developed a method for image classification using machine learning models by simply using a web page that contains JavaScript to be used in the browser. This method uses an external website to load the image files on the web page, but the model can be easily modified by simply changing the JavaScript on the web page.<\/span><\/p>\r\n<h3><span><span class=\"\">Design editing<\/span><\/span><\/h3>\r\n<h4><span><span class=\"\">Layout and component placement<\/span><\/span><\/h4>\r\n<p>As shown in the figure below, place a WebView, a TextBox from the User Interface palette, and a HorizontalArrangement layout from the Layout palette. Drag and drop two buttons from the User Interface palette and rename them as the PictureButton and the InferenceButton, and place them in the HorizontalArrangement1. and place them in the layout. As invisible components, drag and drop a Camera from the Media palette and a Clock from the Sensors palette, and two Webs from the Connectivity palette. Rename one Web component to &#8220;upload&#8221; and the other to &#8220;removefile&#8221;. Rename the hint in TextBox 1 to &#8220;Result&#8221;, the text in the PictureButton to &#8220;Take Picture&#8221;, and the text in the InferenceButton to &#8220;Inference&#8221;.<\/p>\r\n<figure id=\"attachment_2454\" aria-describedby=\"caption-attachment-2454\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/appinventor.tmsoftwareinc.com\/en\/archives\/2437\/screen-shot-2021-05-25-at-9-11-09-am\" rel=\"attachment wp-att-2454\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM-300x275.png\" alt=\"\" class=\"wp-image-2454\" width=\"600\" height=\"549\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM-300x275.png 300w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM-1024x937.png 1024w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM-768x703.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM-1536x1406.png 1536w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM-530x485.png 530w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM-565x517.png 565w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM-710x650.png 710w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM-725x663.png 725w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-9.11.09-AM.png 1696w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2454\" class=\"wp-caption-text\">Click to enlarge<\/figcaption><\/figure>\r\n<h4>Adding a web page that contains JavaScript<\/h4>\r\n<p>Create the following html file and add it to your assets by clicking the &#8220;Upload File&#8221; button on the Media. The file name should be index.html. The following is a brief description of this file.<\/p>\r\n<p>Line 3: Read tensowflow.js<br \/>Line 4: Read MobileNet<br \/>Line 10: Image tags for captured image files<br \/>Line 18-24: WebGL2 function<br \/>Line 27-30: setimage() function. Set the URL of the image file passed from the App Inventor app.<br \/>Line 33-44: classify() function. Make inferences and pass the results to the App Inventor app.<br \/>Line <span>47-62<\/span>: app() function. Determine if WebGL2 is present and set backEnd appropriately, then load the MobileNet model.<\/p>\r\n<div>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-html\" data-lang=\"HTML\"><code>&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/@tensorflow\/tfjs\"&gt;&lt;\/script&gt;\r\n&lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/@tensorflow-models\/mobilenet\"&gt;&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div&gt;&lt;input type=\"text\" id=\"output\" size=\"100\" value=\"\"&gt;&lt;\/div&gt;\r\n\r\n\r\n&lt;img id=\"img\" crossorigin src=\"https:\/\/img.appinventor.tmsoftwareinc.com\/images\/tfjs.png\" width=\"80%\"\/&gt;\r\n\r\n\r\n\r\n&lt;script &gt;\r\nlet net;\r\n\r\n\r\nvar supportsWebGL2 = ( function () {\r\ntry {\r\nreturn !! window.WebGLRenderingContext &amp;&amp; !! document.createElement( 'canvas' ).getContext( 'webgl2' );\r\n} catch( e ) {\r\nreturn false;\r\n}\r\n} )();\r\n\r\n\r\nfunction setimage() {\r\nvar appInventorInput = window.AppInventor.getWebViewString();\r\ndocument.getElementById('img').src = appInventorInput;\r\n}\r\n\r\n\r\nasync function classify() {\r\nwindow.AppInventor.setWebViewString('');\r\n\r\n\r\nconst imgEl = document.getElementById('img');\r\n\r\n\r\nconst result = await net.classify(imgEl);\r\nconst ret = result[0]['className'];\r\n\/\/ document.getElementById(\"output\").value = ret;\r\nwindow.AppInventor.setWebViewString(ret);\r\n}\r\n\r\n\r\nasync function app() {\r\nif(supportsWebGL2){\r\ndocument.getElementById(\"output\").value = 'WebGL2 is supported';\r\n}else{\r\ndocument.getElementById(\"output\").value = 'WebGL2 is not supported';\r\ntf.setBackend('cpu');\r\n}\r\n\r\n\r\ndocument.getElementById(\"output\").value = 'Loading MobileNet..';\r\n\r\n\r\n\/\/ Read MobileNet\r\nnet = await mobilenet.load();\r\ndocument.getElementById(\"output\").value = 'Successfully loaded model';\r\n}\r\n\r\n\r\napp();\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\r\n<\/div>\r\n<\/div>\r\n<h3>Programming using the block editing function<\/h3>\r\n<h4>Global Variables<\/h4>\r\n<p>The first step is to define the global variables. Click on the variable in the Built-in block and drag and drop the &#8220;Initialize global name to&#8221; blocks to set it as shown below. production is true when building apk file and\u00a0 false when using <span>MIT AI2 Companion<\/span>. imageHost is the webserver to upload the image files. waitTime is the time in milliseconds to wait to get the inference results. The other variables are temporary.<\/p>\r\n<figure id=\"attachment_2480\" aria-describedby=\"caption-attachment-2480\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM.png\" rel=\"attachment wp-att-2480\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM-300x124.png\" alt=\"\" class=\"wp-image-2480\" width=\"600\" height=\"249\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM-300x124.png 300w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM-1024x425.png 1024w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM-768x319.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM-530x220.png 530w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM-565x234.png 565w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM-710x295.png 710w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM-725x301.png 725w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.29.51-PM.png 1162w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2480\" class=\"wp-caption-text\">Click to enlarge<\/figcaption><\/figure>\r\n<h4>Screen Initialize event<\/h4>\r\n<p>Incorporate the following blocks into the &#8220;when Screen1 Initialize&#8221; block. The first three blocks set temporary global variables. They are, in order, the URL of the uploaded image file, the URL of the PHP script used to upload the image file, and the URL of the PHP script used to delete the image file. The next if block sets the URL of the WebViewer1 to a different path because the asset path is different when building the apk file and when running on MIT AI2 Companion. Finally, we set the wait time for the timer and disable the timer.<\/p>\r\n<figure id=\"attachment_2484\" aria-describedby=\"caption-attachment-2484\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM.png\" rel=\"attachment wp-att-2484\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM-300x173.png\" alt=\"\" class=\"wp-image-2484\" width=\"600\" height=\"345\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM-300x173.png 300w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM-1024x589.png 1024w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM-768x442.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM-530x305.png 530w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM-565x325.png 565w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM-710x408.png 710w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM-725x417.png 725w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.38.18-PM.png 1474w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2484\" class=\"wp-caption-text\">Click to enlarge<\/figcaption><\/figure>\r\n<h4>PictureButton click event<\/h4>\r\n<p>Incorporate a &#8220;TextBox1 Text&#8221; block with blank text, a &#8220;call Camera1 TakePictire&#8221; block, and a &#8220;InferenceButton Enabled&#8221; block with a false logic block into the &#8220;when PictureButton Click&#8221; block<span><\/span><span><\/span><\/p>\r\n<p><a href=\"https:\/\/appinventor.tmsoftwareinc.com\/en\/archives\/2437\/screen-shot-2021-05-25-at-3-44-54-pm\" rel=\"attachment wp-att-2486\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.44.54-PM-300x77.png\" alt=\"\" class=\"alignnone wp-image-2486\" width=\"600\" height=\"154\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.44.54-PM-300x77.png 300w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.44.54-PM-768x198.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.44.54-PM-530x136.png 530w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.44.54-PM-565x145.png 565w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.44.54-PM-710x183.png 710w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.44.54-PM-725x187.png 725w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.44.54-PM.png 1002w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\r\n<h4>Camera1 AfterPicture event<\/h4>\r\n<p>In the &#8220;when Camera1 AfterPicture&#8221; block, set the global variable &#8220;photoPath&#8221; to the image taken by the Camera1, set the global variable &#8220;uploadURL&#8221; to the URL of the upload web, and call upload PostFile with the image to upload it. At the same time, activate the InferenceButton.<\/p>\r\n<p><a href=\"https:\/\/appinventor.tmsoftwareinc.com\/en\/archives\/2437\/screen-shot-2021-05-25-at-3-59-43-pm\" rel=\"attachment wp-att-2488\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.59.43-PM-300x128.png\" alt=\"\" class=\"alignnone wp-image-2488\" width=\"600\" height=\"255\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.59.43-PM-300x128.png 300w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.59.43-PM-768x326.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.59.43-PM-530x225.png 530w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.59.43-PM-565x240.png 565w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.59.43-PM-710x302.png 710w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.59.43-PM-725x308.png 725w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-3.59.43-PM.png 974w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\r\n<h4>Upload GotText event<\/h4>\r\n<p>In the &#8220;When upload GotText&#8221; block, if the upload is successful, the name of the uploaded file will be returned in the responseContent, so set the global variable imageName to this file name. Then set the full URL of the image file to the WebViewString in WebView1 and call the setimage() JavaScipt function. This will display the uploaded image in the WebView1.<\/p>\r\n<p><a href=\"https:\/\/appinventor.tmsoftwareinc.com\/en\/archives\/2437\/screen-shot-2021-05-25-at-4-06-41-pm\" rel=\"attachment wp-att-2492\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-4.06.41-PM-300x105.png\" alt=\"\" class=\"alignnone wp-image-2492\" width=\"800\" height=\"279\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-4.06.41-PM-300x105.png 300w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-4.06.41-PM-1024x358.png 1024w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-4.06.41-PM-768x268.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-4.06.41-PM-530x185.png 530w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-4.06.41-PM-565x197.png 565w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-4.06.41-PM-710x248.png 710w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-4.06.41-PM-725x253.png 725w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-4.06.41-PM.png 1460w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\r\n<h4>InferenceButton click event<\/h4>\r\n<p><span>In the &#8220;when InferenceButton Click&#8221; block, put the blank text in the &#8220;TextBox1 Text&#8221; block, and call the classify() JavaScipt function to perform the inference. At the same time, enable the timer.<\/span><\/p>\r\n<p><a href=\"https:\/\/appinventor.tmsoftwareinc.com\/en\/archives\/2437\/screen-shot-2021-05-25-at-6-18-13-pm\" rel=\"attachment wp-att-2499\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.18.13-PM-300x93.png\" alt=\"\" class=\"alignnone wp-image-2499\" width=\"700\" height=\"216\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.18.13-PM-300x93.png 300w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.18.13-PM-1024x317.png 1024w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.18.13-PM-768x237.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.18.13-PM-530x164.png 530w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.18.13-PM-565x175.png 565w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.18.13-PM-710x219.png 710w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.18.13-PM-725x224.png 725w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.18.13-PM.png 1100w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\r\n<h4>Timer event<span><\/span><span><\/span><\/h4>\r\n<p>It takes some time for the WebViewString of WebView1 to be returned after calling the classify() JavaScript function, so we use a timer to wait for a while. This time is set in the global variable waitTime, which is 500 milliseconds (0.5 seconds). In the &#8220;when Clock1 Timer&#8221; block, disable Clock1, display the WebViewString of WebView1 in the TextBox1 Text, set removeURL with imageName to the URL of the removefile web, and then call the removefile Get method to delete the file from the webserver.<\/p>\r\n<p><a href=\"https:\/\/appinventor.tmsoftwareinc.com\/en\/archives\/2437\/screen-shot-2021-05-25-at-6-27-46-pm\" rel=\"attachment wp-att-2501\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.27.46-PM-300x109.png\" alt=\"\" class=\"alignnone wp-image-2501\" width=\"700\" height=\"254\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.27.46-PM-300x109.png 300w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.27.46-PM-1024x371.png 1024w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.27.46-PM-768x278.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.27.46-PM-530x192.png 530w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.27.46-PM-565x205.png 565w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.27.46-PM-710x257.png 710w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.27.46-PM-725x263.png 725w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-25-at-6.27.46-PM.png 1242w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\r\n<div class=\"clearfix\">That&#8217;s it! Test it on your phone. The classification results will be displayed at the bottom.<\/div>\r\n<div>\r\n<figure id=\"attachment_2494\" aria-describedby=\"caption-attachment-2494\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52.png\" rel=\"attachment wp-att-2494\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52-188x300.png\" alt=\"\" class=\"wp-image-2494\" width=\"300\" height=\"480\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52-188x300.png 188w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52-640x1024.png 640w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52-768x1229.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52-331x530.png 331w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52-353x565.png 353w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52-444x710.png 444w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52-453x725.png 453w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2021\/05\/Screenshot-2021_05_25-16-27-52.png 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-2494\" class=\"wp-caption-text\">Click to enlarge<\/figcaption><\/figure>\r\n<\/div>\r\n<div class=\"clearfix\">\r\n<h4>Download source<\/h4>\r\n<!-- \/wp:heading -->\r\n\r\n<!-- wp:paragraph --> Source code of this App is available at <a href=\"https:\/\/gallery.appinventor.mit.edu\/?galleryid=45494e02-cbd8-484d-86a7-662ea4c09484\" target=\"_blank\" rel=\"noopener\">MIT App Inventor Gallery<\/a><\/div>\r\n<div>\r\n<h4>PHP source codes<\/h4>\r\n<p>They are the PHP source codes used to upload and delete image files. You can refer to it when using your own web server. For browser security, web servers need to return Access-Control-Allow-Origin &#8220;*&#8221; in the Header. For Apache web server, set Header set Access-Control-Allow-Origin &#8220;*&#8221;.<\/p>\r\n<p>upload.php<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>&lt;?php\r\n$data = file_get_contents('php:\/\/input');\r\n$tmpfname = tempnam(\"\/var\/www\/------\/images\", \"prefix\");\r\nif (!(file_put_contents($tmpfname,$data) === FALSE)) echo basename($tmpfname); \/\/ file could be empty\r\nelse echo \"File xfer failed.\";\r\n?&gt;<\/code><\/pre>\r\n<\/div>\r\n<p>remove.php<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>&lt;?php\r\nif(isset($_GET['fn'])) {\r\n    $fname = \"\/var\/www\/------\/images\/\" . $_GET['fn'];;\r\n    if(file_exists($fname)) {\r\n        echo \"unlinked $fname\";\r\n        unlink($fname);\r\n    }\r\n}\r\n?&gt;<\/code><\/pre>\r\n<\/div>\r\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s make an Image Classification App with higher accuracy without extension! You can change the machine learning model easily, because this app does not use extension. From the Project menu, select New Project and name it &#8220;WhatisThis2&#8221;. Why LookExtension extension is not needed? With tensorflow.js, you can use machine learning models in a browser. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":"","_locale":"en_US","_original_post":"https:\/\/appinventor.tmsoftwareinc.com\/?p=2375"},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/posts\/2437"}],"collection":[{"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/comments?post=2437"}],"version-history":[{"count":52,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/posts\/2437\/revisions"}],"predecessor-version":[{"id":2508,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/posts\/2437\/revisions\/2508"}],"wp:attachment":[{"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/media?parent=2437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/categories?post=2437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/tags?post=2437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}