-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexplore.html
235 lines (199 loc) · 11.4 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!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 bounded by
- 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, include an IMG element with id imgPreview
- For image results, include an IMG with element imgPreview and a DIV with
id 'imageMask'.
- You can use a single image for both preview and results if you wish by only
including a imgPreview image. Make sure you have the imageMask DIV though.
- 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>Text2Image 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">Text2Image Module Test</h2>
<form method="post" action="" enctype="multipart/form-data" id="myform">
<!-- START EXPLORER MARKUP -->
<div class="form-group row">
<div>
<label for="_MID_prompt" class="col-form-label col-2">Prompt</label>
<textarea id="_MID_prompt" class="w-100" style="height:100px"
title="The prompt to be used by Stable Diffusion to create the image"></textarea>
</div>
<div>
<label for="_MID_negative_prompt" class="col-form-label">Negative Prompt</label>
<textarea id="_MID_negative_prompt" class="w-100" style="height:100px"
title="The negative prompt to be used by Stable Diffusion to create the image"></textarea>
</div>
<div class="row mb-3">
<div class="col-4">
<label for"_MID_num_images" class="form-label">Images</label>
<input type="number" id="_MID_num_images" class="form-control"
min="1" max="4" steps="1" value="1" title="The number of images to generate. Defaults to 1."/>
</div>
<div class="col-4">
<label for="_MID_seed" class="form-label">Seed</label>
<input id="_MID_seed" class="form-control" type="number" value="0"
title="The seed to use for the diffusion random number generator. If Fixed is checked will use this value, otherwise uses random value."/>
<label for="_MID_seed_fixed" class="form-check-label" >Fixed</label>
<input id="_MID_seed_fixed" class="form-check-input ms-2" type="checkbox"
title="If checked, will use the value above rather than a random value. This allows for reproducible image generation."/>
</div>
<div class="col-4">
<label for="_MID_num_steps" class="form-label">Steps</label>
<input type="number" id="_MID_num_steps" class="form-control" min="1" max="100"
steps="1" value="40" title="The number of inference steps to run"/>
</div>
</div>
<div class="row mb-3">
<div class="col-4">
<label for="_MID_guidance" class="form-label">Guidance</label>
<input type="number" id="_MID_guidance" class="form-control" min="0.0" max="20.0"
steps="0.1" value="7" title="How well the process aligns with the prompt for image generation (0.0 - 20.0)."/>
</div>
<div class="col-4">
<label for="_MID_width" class="form-label">Width</label>
<input type="number" id="_MID_width" class="form-control" min="128" max="1024"
steps="8" value="512" title="The width of the image to be created. Defaults to 512. Must be a multiple of 8."/>
</div>
<div class="col-4">
<label for="_MID_height" class="form-label">Height</label>
<input type="number" id="_MID_height" class="form-control" min="128" max="1024"
steps="8" value="512" title="The height of the image to be created. Must be a multiple of 8."/>
</div>
</div>
<input id="_MID_generte" class="form-control btn-success" type="button" value="Generate Image"
style="width:11rem" onclick="_MID_onGenerateImages()" />
</div>
<hr>
<!-- 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_onGenerateImages() {
clearImagePreview();
if (!_MID_prompt.value) {
alert("No image prompt specified");
return;
}
setResultsHtml("Generating Images...");
let params = [['prompt', _MID_prompt.value],
['num_images_per_prompt', _MID_num_images.value],
['seed', _MID_seed_fixed.checked ? _MID_seed.value : null],
['num_inference_steps', _MID_num_steps.value],
['guidance_scale', _MID_guidance.value],
['width', _MID_width.value],
['height', _MID_height.value]];
if (_MID_negative_prompt.value != "") {
params.push(['negative_prompt', _MID_negative_prompt.value]);
}
let data = await submitRequest('text2image', 'create', null, params);
if (data) {
// get the commandId to so we can poll for the results
_MID_commandId = data.commandId;
_MID_moduleId = data.moduleId;
params = [['commandId', _MID_commandId], ['moduleId', _MID_moduleId]];
done = false;
loopCount = 0;
spinner = "|/-\\";
while (!done) {
await delay(1000);
let results = await submitRequest('text2image', 'get_command_status', null, params);
if (results && results.success) {
if (results.commandStatus == "failed") {
done = true;
setResultsHtml(results?.error || "Unknown error");
}
else {
let message = results.message;
if (results.commandStatus == "completed") {
done = true;
_MID_seed.value = results?.seed || 0;
}
else {
spinChar = spinner.charAt(loopCount++ % spinner.length);
message = spinChar + " " + message;
}
setResultsHtml(message);
if (results.images && results.images.length > 0)
showResultsImage(results.images[0], results.width, results.height);
}
}
else {
// TODO: check for timeouts and other network errors.
done = true;
// setResultsHtml(results?.error || "No response from server");
}
}
};
}
// =====================================================================
// Startup
// END EXPLORER SCRIPT
</script>
</div>
</body>
</html>