-
Notifications
You must be signed in to change notification settings - Fork 2
/
explore.html
144 lines (118 loc) · 6.29 KB
/
explore.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<!--
CODEPROJECT.AI SERVER MODULE EXPLORER
This page provides the means to test this module using the same infrastructure as
the CodeProject.AI Server explorer. This page also provides the UI elements that
the explorer will parse and use to build up the UI of the main explorer itself.
RULES AND CONVENTIONS
1. This page should provide sufficient functionality to test and explore this
module.
2. This page should use the functionality in the explorer.js file so that when
the elements of this page are inserted into the main explorer, it all works
seamlessly. Specifically, you will probably use
- clearImagePreview: Clears the image preview area.
- previewImage: Displays an image in the shared image preview area and takes a
input[type=file] as parameter.
- submitRequest: Sends a request to the AI server.
- setResultsHtml: Sets the HTML in the shared 'results' element. Parameter is the HTML
to display.
- getProcessingMetadataHtml: Gets HTML representing the common data returned from a call to a
module.
- displayBaseResults: Displays the common data returned from a call to a module.
- showPredictionSummary: Displays in the shared HTML results pane the list of predictions
returned from an inference operation.
- clearImageResult: Clears the image result area
- showResultsImageData: Displays an image in the shared image results area using the data
returned from a call to a module, and overlays bounding boxes if
present in the data
- showResultsBoundingBoxes: Displays bounding boxes on the shared image results area based on
the boxes returned in the predictions parameter. The first param is
an array of predictions returned from a computer vision operation.
3. There are 3 parts of this page that will be pulled into the main explorer
during runtime: The HTML, the script, and the CSS. These sections are marked:
- HTML: START EXPLORER MARKUP / END EXPLORER MARKUP pair, each within HTML comment brackets
- Script: START EXPLORER SCRIPT / END EXPLORER SCRIPT pair, each as a // comment on its own line
- CSS: START EXPLORER STYLE / END EXPLORER STYLE pair, each inside /* ... */ comments
These delimiters should be on a line by themselves
4. **Please provide output elements to display the results of operations** if
you wish to use the standard HTML / Image results elements in the main explorer
- For HTML output, include a DIV with id 'results'
- For Image preview/output, include an IMG element with id img and a DIV with
id 'imageMask'
- For Sound preview, include an AUDIO element with id 'snd' that contains a
SOURCE tag
5. When this file is parsed and injected into the larger explorer, the HTML is
injected first, then the script, then the CSS.
6. **To ensure uniqueness of elements** you can include the _MID_ macro in any
name. This will be expanded to be [ModuleId]_ where [ModuleId] is the literal
ID of this module. For instance <div id="_MID_TextBox"> becomes <div id="MyModuleId_TextBox">
-->
<head>
<meta charset="utf-8" />
<title>Cartoonizer Module Test</title>
<link id="bootstrapCss" rel="stylesheet" type="text/css" href="http://localhost:32168/assets/bootstrap-dark.min.css">
<link rel="stylesheet" type="text/css" href="http://localhost:32168/assets/server.css?v=2.5.0.0">
<script type="text/javascript" src="http://localhost:32168/assets/server.js"></script>
<script type="text/javascript" src="http://localhost:32168/assets/explorer.js"></script>
<style>
/* START EXPLORER STYLE */
/* END EXPLORER STYLE */
</style>
</head>
<body class="dark-mode">
<div class="mx-auto" style="max-width: 800px;">
<h2 class="mb-3">Cartoonizer Module Test</h2>
<form method="post" action="" enctype="multipart/form-data" id="myform">
<!-- START EXPLORER MARKUP -->
<div class="form-group row">
<label class="col-form-label col-2">Image</label>
<input class="col form-control btn-light" id="_MID_cartoonInput" type="file"
style="width:17rem" onchange="return previewImage(this)" />
<input id="_MID_on-cartoonize" class="form-control btn-success" type="button"
value="Cartoonize" style="width:10rem"
onclick="_MID_onCartoonize(_MID_cartoonModel.value, _MID_cartoonInput)" />
</div>
<div class="form-group d-flex justify-content-end mt-2">
<label class="col-form-label col-2">Model</label>
<select id="_MID_cartoonModel" class="form-select" style="width:10rem">
<option value="celeba_distill">Celebrity</option>
<option value="face_paint_512_v1">Face paint v1</option>
<option value="face_paint_512_v2">Face paint v2</option>
<option value="paprika">Paprika</option>
</select>
</div>
<!-- END EXPLORER MARKUP -->
<div class="w-100 position-relative form-control my-4 p-0">
<div id="imgMask" class="position-absolute"
style="left:0;top:0;pointer-events:none;z-index:10"></div>
<img src="" id="imgPreview" class="w-100" style="height:250px;visibility:hidden">
</div>
<div>
<h2>Results</h2>
<div id="results" name="results" class="bg-light p-3" style="min-height: 100px;"></div>
</div>
</form>
<script type="text/javascript">
// START EXPLORER SCRIPT
async function _MID_onCartoonize(model_name, fileChooser) {
clearImagePreview();
if (fileChooser.files.length == 0) {
alert("No file was selected for cartoonization");
return;
}
showPreviewImage(fileChooser.files[0]);
let images = [fileChooser.files[0]];
params = [["model_name", model_name]]
setResultsHtml("Cartoonizing face...");
let data = await submitRequest('image', 'cartoonize', images, params);
if (data) {
setResultsHtml("onCartoonization complete" + getProcessingMetadataHtml(data));
showResultsImageData(data);
};
}
// END EXPLORER SCRIPT
</script>
</div>
</body>
</html>