Last active
December 7, 2020 13:21
-
-
Save Fountaincoder/4a9ccbe1faab797c8d201843b5adb42f to your computer and use it in GitHub Desktop.
ML system for HandN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: LQ AI 0.1 | |
description: ML system for HandN | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
function clearDefault(a) { | |
if (a.defaultValue == a.value) { | |
a.value = ""; | |
} | |
} | |
$("#run").click(() => tryCatch(run)); | |
async function run() { | |
await Excel.run(async (context) => { | |
var in_vect = []; | |
const UID = $("#uid").val(); | |
const age = $("#a").val(); | |
in_vect.push(Number(age)); | |
in_vect.push(Number($("#g").val())); | |
const h = Number($("#hgt").val()); | |
in_vect.push(h); | |
const w = Number($("#wgt").val()); | |
in_vect.push(w); | |
const bmi = (w / (h * h)).toFixed(2); | |
in_vect.push(bmi); | |
var outString = ""; | |
const codes = [ | |
["hv", "hoarse voice"], | |
["ds", "difficulty swallowing"], | |
["ps", "pain swallowing"], | |
["o", "otalgia"], | |
["u", "unilatoral nasal obstruction"], | |
["nl", "neck lump"], | |
["tl", "throat lump"], | |
["f", "feeling of something in throat"], | |
["st", "sore throat"] | |
]; | |
for (var i of codes) { | |
if ($("#".concat(i[0])).is(":checked")) { | |
in_vect.push(1); | |
outString += i[1] + ", "; | |
} else { | |
in_vect.push(0); | |
} | |
} | |
outString = outString.slice(0, outString.length - 2) + "."; | |
if (outString == "") outString = "none"; | |
if (in_vect.includes(NaN)) { | |
alert("Missing Element on form, please amend and resubmit"); | |
} else { | |
const state = context.workbook.worksheets.getItem("State"); | |
const crowr = state.getRange("B1"); | |
crowr.load("values"); | |
await context.sync(); | |
const crow = crowr.values[0][0]; | |
crowr.values = [[crow + 1]]; | |
await context.sync(); | |
// Build the model | |
const model = tf.sequential(); | |
model.add(tf.layers.dense({ units: 1, inputShape: [14], activation: "sigmoid" })); | |
model.compile({ optimizer: "adam", loss: "binaryCrossentropy", metrics: ["accuracy"] }); | |
// Extract the features from the spreadsheet | |
const mlfeatures = context.workbook.worksheets.getItem("MLFeatures"); | |
const X = mlfeatures.getRange("A1:N272"); | |
X.load("values"); | |
// Extract Classes | |
const outcomes = context.workbook.worksheets.getItem("Outcomes"); | |
const Y = outcomes.getRange("A1:A272"); | |
Y.load("values"); | |
// SYNC | |
await context.sync(); | |
//FIT | |
await model.fit(tf.tensor2d(X.values, [272, 14]), tf.tensor2d(Y.values, [272, 1]), { | |
epochs: 25, | |
classWeight: { 0: 0.001, 1: 0.99 } | |
}); | |
//PREDICT | |
const out = model.predict(tf.tensor2d(in_vect, [1, 14])).dataSync(); | |
in_vect.push(out[0]); | |
const sheet = context.workbook.worksheets.getItem("New"); | |
var range = sheet.getRange("A" + String(crow) + ":Q" + String(crow)); | |
range.values = [[(new Date()).toDateString()].concat([UID].concat(in_vect))]; | |
range.format.autofitColumns(); | |
await context.sync(); | |
//write to new | |
console.log("Predicted prob of cancer:".concat(out)); | |
$("#outtxt").val("Patient: " + UID + " age " + age + " BMI: " + bmi + " symptoms: " + outString); | |
} | |
}); | |
} | |
/** Default helper for invoking an action and handling errors. */ | |
async function tryCatch(callback) { | |
try { | |
await callback(); | |
} catch (error) { | |
// Note: In a production add-in, you'd want to notify the user through your add-in's UI. | |
console.error(error); | |
} | |
} | |
language: typescript | |
template: | |
content: "<section class=\"samples ms-font-m\">\n\t<h1>LQ0.1: Head and Neck Cancer AI</h1>\n\t<p class=\"ms-font-m\"><i> Only for the use of</i><b> Mr J. Moor</b>.</p>\n\t<B> <label> NHS no: </label> </B> <input id=\"uid\" type=\"text\" size=\"10\" value=\"NHS1234\" onFocus=\"clearDefault(this)\">\n\t<br> <br>\n\t<label> Age (Yrs): </label> <input id=\"a\" type=\"text\" size=\"4\" value=\"eg. 55.5\" onFocus=\"clearDefault(this)\">\n\t<label> Gender: </label> <select id=\"g\">\n\t\t\t <option value=\"0\">Female</option>\n\t\t\t <option value=\"1\">Male</option>\n\t\t\t</select><br><br>\n\t<label> Height (M): </label>\n\t<input id=\"hgt\" type=\"text\" size=\"4\" value=\"eg. 1.7\" onFocus=\"clearDefault(this)\">\n\t<label> Weight (Kg): </label>\n\t<input id=\"wgt\" type=\"text\" size=\"4\" value=\"eg. 80\" onFocus=\"clearDefault(this)\"><br><br>\n\t<h3> Select Symptoms: </h3>\n\t<input id=\"hv\" type=\"checkbox\"><label> Hoarse voice </label> <br>\n\t<input id=\"ds\" type=\"checkbox\"><label> Difficulty swallowing: </label> <br>\n\t<input id=\"ps\" type=\"checkbox\"><label> Pain swallowing:</label><br>\n\t<input id=\"o\" type=\"checkbox\"><label> Otalgia: </label> <br>\n\t<input id=\"u\" type=\"checkbox\"><label> Unilateral NO: </label> <br>\n\t<input id=\"nl\" type=\"checkbox\"><label> Neck lump: </label><br>\n\t<input id=\"tl\" type=\"checkbox\"><label> Throat lump: </label> <br>\n\t<input id=\"f\" type=\"checkbox\"><label> FOSIT: </label> <br>\n\t<input id=\"st\" type=\"checkbox\"> <label> Sore throat: </label> <br><br><br>\n\t<button id=\"run\" class=\"ms-Button\">\n\t\t\t\t\t\t\t <span class=\"ms-Button-label\">Submit and Check Diagnosis</span>\n\t\t\t\t\t\t\t </button> <br>\n\t<label> Copy </label>\n\t<textarea id=\"outtxt\" name=\"outtxt\" rows=\"5\" cols=\"40\">\n\n\t</textarea>\n\t<br><br>\n</section>" | |
language: html | |
style: | |
content: |- | |
section.samples { | |
margin-top: 20px; | |
} | |
section.samples .ms-Button, section.setup .ms-Button { | |
display: block; | |
margin-bottom: 5px; | |
margin-left: 20px; | |
min-width: 80px; | |
} | |
/* label { | |
display: block; | |
padding-left: 15px; | |
text-indent: -15px; | |
} | |
input { | |
width: 20px; | |
height: 10px; | |
padding: 0; | |
margin:0; | |
vertical-align: bottom; | |
position: relative; | |
top: -1px; | |
*overflow: hidden; | |
} */ | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
@types/office-js | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
core-js@2.4.1/client/core.min.js | |
@types/core-js | |
https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest | |
jquery@3.1.1 | |
@types/jquery@3.3.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: LQ AI 0.1 | |
description: ML system for HandN | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#run").click(() => tryCatch(run)); | |
async function run() { | |
await Excel.run(async (context) => { | |
const state = context.workbook.worksheets.getItem("State"); | |
const crowr = state.getRange("B1"); | |
crowr.load("values"); | |
await context.sync(); | |
const crow = crowr.values[0][0]; | |
crowr.values = [[crow + 1]]; | |
await context.sync(); | |
let in_vect = []; | |
const UID = $("#uid").val(); | |
in_vect.push(Number($("#a").val())); | |
in_vect.push(Number($("#g").val())); | |
const h = Number($("#hgt").val()); | |
in_vect.push(h); | |
const w = Number($("#wgt").val()); | |
in_vect.push(w); | |
in_vect.push(w / (h * h)); | |
for (var i of ["hv", "ds", "ps", "o", "u", "nl", "tl", "f", "st"]) { | |
if ($("#".concat(i)).is(":checked")) { | |
in_vect.push(1); | |
} else { | |
in_vect.push(0); | |
} | |
} | |
// Build the model | |
const model = tf.sequential(); | |
model.add(tf.layers.dense({ units: 1, inputShape: [14], activation: "sigmoid" })); | |
model.compile({ optimizer: "adam", loss: "binaryCrossentropy", metrics: ["accuracy"] }); | |
// Extract the features from the spreadsheet | |
const mlfeatures = context.workbook.worksheets.getItem("MLFeatures"); | |
const X = mlfeatures.getRange("A1:N272"); | |
X.load("values"); | |
// Extract Classes | |
const outcomes = context.workbook.worksheets.getItem("Outcomes"); | |
const Y = outcomes.getRange("A1:A272"); | |
Y.load("values"); | |
// SYNC | |
await context.sync(); | |
//FIT | |
await model.fit(tf.tensor2d(X.values, [272, 14]), tf.tensor2d(Y.values, [272, 1]), { | |
epochs: 25, | |
classWeight: { 0: 0.001, 1: 0.99 } | |
}); | |
//PREDICT | |
const out = model.predict(tf.tensor2d(in_vect, [1, 14])).dataSync(); | |
in_vect.push(out[0]); | |
const sheet = context.workbook.worksheets.getItem("New"); | |
var range = sheet.getRange("A" + String(crow) + ":P" + String(crow)); | |
range.values = [[UID].concat(in_vect)]; | |
range.format.autofitColumns(); | |
await context.sync(); | |
//write to new | |
console.log("Predicted prob of cancer:".concat(out)); | |
}); | |
} | |
/** Default helper for invoking an action and handling errors. */ | |
async function tryCatch(callback) { | |
try { | |
await callback(); | |
} catch (error) { | |
// Note: In a production add-in, you'd want to notify the user through your add-in's UI. | |
console.error(error); | |
} | |
} | |
language: typescript | |
template: | |
content: "<section class=\"samples ms-font-m\">\n\t<h1>LQ1: Head and Neck Cancer AI</h1>\n\t<p class=\"ms-font-m\"><i> Only for the use of</i><b> Mr J. Moor</b>.</p>\n\t<B> <label> UID: </label> </B> <input id=\"uid\" type=\"text\" size=\"4\" value=\"NHS1234\">\n\t<br> <br>\n\t<label> Age (Yrs): </label> <input id=\"a\" type=\"text\" size=\"4\" value=\"eg. 55.5\">\n\t<label> Gender: </label> <select id=\"g\">\n\t\t\t <option value=\"0\">Female</option>\n\t\t\t <option value=\"1\">Male</option>\n\t\t\t</select><br>\n\t<label> Height (M): </label> <input id=\"hgt\" type=\"text\" size=\"4\" value=\"eg. 1.7\">\n\t<label> Weight (Kg): </label> <input id=\"wgt\" type=\"text\" size=\"4\" value=\"eg. 80\"><br>\n\t<h3> Select Symptoms: </h3>\n\t<label> Hoarse Voice: </label> <input id=\"hv\" type=\"checkbox\"><br>\n\t<label> Difficulty Swallowing: </label> <input id=\"ds\" type=\"checkbox\"><br>\n\t<label> Pain Swallowing:</label> <input id=\"ps\" type=\"checkbox\"><br>\n\t<label> Otalgia: </label> <input id=\"o\" type=\"checkbox\"><br>\n\t<label> UnilatoNo: </label> <input id=\"u\" type=\"checkbox\"><br>\n\t<label> NeckLump: </label> <input id=\"nl\" type=\"checkbox\"><br>\n\t<label> ThroatLump: </label> <input id=\"tl\" type=\"checkbox\"><br>\n\t<label> FOSIT: </label> <input id=\"f\" type=\"checkbox\"><br>\n\t<label> SoreThroat: </label> <input id=\"st\" type=\"checkbox\"> <br><br><BR>\n\t<button id=\"run\" class=\"ms-Button\">\n\t\t\t\t\t\t\t <span class=\"ms-Button-label\">Submit and Check Diagnosis</span>\n\t\t\t\t\t\t\t </button> <br>\n</section>" | |
language: html | |
style: | |
content: |- | |
section.samples { | |
margin-top: 20px; | |
} | |
section.samples .ms-Button, section.setup .ms-Button { | |
display: block; | |
margin-bottom: 5px; | |
margin-left: 20px; | |
min-width: 80px; | |
} | |
/* label { | |
display: block; | |
padding-left: 15px; | |
text-indent: -15px; | |
} | |
input { | |
width: 20px; | |
height: 10px; | |
padding: 0; | |
margin:0; | |
vertical-align: bottom; | |
position: relative; | |
top: -1px; | |
*overflow: hidden; | |
} */ | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
@types/office-js | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
core-js@2.4.1/client/core.min.js | |
@types/core-js | |
https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest | |
jquery@3.1.1 | |
@types/jquery@3.3.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment