芝麻web文件管理V1.00
编辑当前文件:/home/paymbalq/demo.tamela.org/js/cardio-script-video-original.js
LoadModel(); let video; var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); var result = document.getElementById('result'); var message = document.getElementById('message'); let model; let maxPredictions; function onPredict(video_name){ document.getElementById('modal-display').style.display = "block"; setTimeout(function() { try { predict(video_name); }catch (e) { message.innerHTML = "Oops! Prediction failed :("; document.getElementById('cd-hide-show').style.display = "block"; } }, 1000); } async function LoadModel() { const URL = "https://teachablemachine.withgoogle.com/models/4Pyk9OIuy/"; const modelURL = URL + "model.json"; const metadataURL = URL + "metadata.json"; try { model = await tmImage.load(modelURL, metadataURL); maxPredictions = model.getTotalClasses(); } catch (e) { message.innerHTML = "There was an error trying to load our AI model. Please check your internet connection..."; document.getElementById('cd-hide-show').style.display = "block"; } } async function predict(video_name) { var great = ""; var sample = ""; var ef = ""; var result_color = ""; var cross_video = ""; great = document.getElementById('cd-great'); sample = document.getElementById('cd-sample'); ef = document.getElementById('cd-ejection-fraction'); result_color = document.getElementById('result-container'); cross_video = document.getElementById('video'); switch(video_name){ case "video_1": video = document.getElementById(video_name); sample.innerHTML = "Sample 1"; cross_video.src = "assets/high.mp4"; break; case "video_2": video = document.getElementById(video_name); sample.innerHTML = "Sample 2"; cross_video.src = "assets/low.mp4"; break; case "video_3": video = document.getElementById(video_name); sample.innerHTML = "Sample 3"; cross_video.src = "assets/low2.mp4"; break; case "video_4": video = document.getElementById(video_name); sample.innerHTML = "Sample 4"; cross_video.src = "assets/x-ray.mp4"; break; default: message.innerHTML = "Something went wrong..."; document.getElementById('cd-hide-show').style.display = "block"; } context.translate((canvas.width + video.width) / 2, 0); context.scale(-1, 1); context.drawImage(video, 0, 0, video.width, video.height); context.setTransform(1, 0, 0, 1, 0, 0); var data = ""; var maxClassName = ""; var maxProbability = ""; var prediction = await model.predict(canvas); document.getElementById('modal-display').style.display = "none"; if (maxPredictions > 0) { for (let i = 0; i < maxPredictions; i++) { prediction[i].probability.toFixed(0); if (prediction[i].className == "high_ef" && prediction[i].probability == 1) { great.innerHTML = "Great! :)"; ef.innerHTML = "has a high ejection fraction."; result_color.style.backgroundColor = "#b5ffd6"; }else if (prediction[i].className == "low_ef" && prediction[i].probability == 1) { great.innerHTML = "Hmmm :("; ef.innerHTML = "has a low ejection fraction."; result_color.style.backgroundColor = "#f9ffd1"; }else if (prediction[i].className == "non_cardiac" && prediction[i].probability == 1) { great.innerHTML = "Oh snap :("; ef.innerHTML = "must be an echo-cardiogram video."; result_color.style.backgroundColor = "#ffc9cf"; } } } else setTimeout(function() { predict(); }, 100); } video.addEventListener("loadedmetadata", function() { canvas.setAttribute("width", video.videoWidth); canvas.setAttribute("height", video.videoHeight); }, false);