-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrf_test_min.html
88 lines (83 loc) · 3.28 KB
/
crf_test_min.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>crf_test_min</title>
</head>
<body>
<textarea id="ingredients_box" rows="20" cols="40">10g (1/202) butter
50g (202) onion, very finely chopped
450g (11b) beef (flank, chump or shin would be perfect), freshly minced
1/2 teaspoon fresh thyme leaves
1/2 teaspoon finely chopped parsley
1 small organic egg, beaten
salt and freshly ground pepper
pork caul fat (optional)
oil or dripping</textarea>
<script type='text/javascript'>
function parseIngredients(lines) {
return import_data(crfTest(export_data(lines)));
}
function crfTest(input) {
FS.writeFile('input.txt', input);
args = ['-v', '1', '-m', 'model_file', '-o', 'output.txt', 'input.txt'];
Module['callMain'](args);
return FS.readFile('output.txt', { encoding: 'utf8' }).split(/\n/);
}
function whenReady() {
// can start the program here
const text = document.getElementById('ingredients_box').value;
const lines = text.split(/\n/);
const foods = parseIngredients(lines);
const carbs = calculateCarbs(foods);
console.log(foods);
console.log(carbs);
}
var Module = {
arguments: ["-h"], // run help when it first loads (this is ignored)
preRun: [],
postRun: [whenReady],
print: (function() {
var element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// These replacements are necessary if you render to raw HTML
//text = text.replace(/&/g, "&");
//text = text.replace(/</g, "<");
//text = text.replace(/>/g, ">");
//text = text.replace('\n', '<br>', 'g');
console.log(text);
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight; // focus on bottom
}
};
})(),
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
setStatus: function(text) {
console.log("status:" + text);
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
Module.setStatus('Downloading...');
window.onerror = function(event) {
// TODO: do not warn on ok events like simulating an infinite loop or exitStatus
Module.setStatus('Exception thrown, see JavaScript console');
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};
</script>
<script async type="text/javascript" src="ingreedy.js"></script>
<script async type="text/javascript" src="crf_test.js"></script>
</body>
</html>