Spaces:
Runtime error
Runtime error
File size: 25,018 Bytes
32f0b26 b5e7dfa 32f0b26 1882b75 32f0b26 9a85cb5 32f0b26 b5e7dfa 32f0b26 70ab0be 32f0b26 1882b75 32f0b26 37d1f1c 32f0b26 9a85cb5 b5e7dfa 32f0b26 e7655e6 9a85cb5 32f0b26 b5e7dfa 32f0b26 b5e7dfa 32f0b26 4adf2d3 32f0b26 9a85cb5 32f0b26 9a85cb5 32f0b26 e7655e6 32f0b26 e7655e6 32f0b26 9a85cb5 e7655e6 9a85cb5 32f0b26 9a85cb5 1882b75 32f0b26 1882b75 32f0b26 1882b75 e7655e6 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 1882b75 32f0b26 9a85cb5 1882b75 32f0b26 559a7ba 1882b75 9a85cb5 32f0b26 1882b75 b5e7dfa 1882b75 b5e7dfa 1882b75 32f0b26 b5e7dfa 1882b75 b5e7dfa 1882b75 b5e7dfa 9a85cb5 1882b75 e7655e6 1882b75 9a85cb5 efceaac 9a85cb5 efceaac 48122fa efceaac 32f0b26 1882b75 32f0b26 efceaac 32f0b26 efceaac 32f0b26 70ab0be 32f0b26 |
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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
<script lang="ts">
import { onMount } from "svelte";
import { fade } from 'svelte/transition';
import ClusterResults from "./ClusterResults.svelte";
import SubmitReportDialog from "./SubmitReportDialog.svelte";
import Button, { Label } from "@smui/button";
import Textfield from '@smui/textfield';
import Select, { Option } from "@smui/select";
import { new_evidence } from './stores/new_evidence_store.js';
import { open_evidence } from './stores/open_evidence_store.js';
import { topic_chosen } from './stores/cur_topic_store.js';
import Drawer, {
AppContent,
Content,
Header,
Title,
Subtitle,
} from '@smui/drawer';
import List, { Item, Text, Graphic, PrimaryText, SecondaryText } from '@smui/list';
import LinearProgress from "@smui/linear-progress";
import CircularProgress from '@smui/circular-progress';
import Checkbox from '@smui/checkbox';
import FormField from '@smui/form-field';
import IconButton from "@smui/icon-button";
import { Icon } from "@smui/common";
import Radio from '@smui/radio';
export let model;
export let cur_user;
let all_reports = [];
let cur_topic;
topic_chosen.subscribe(value => {
cur_topic = value;
});
// Handle submit report dialog
let submit_dialog_open = false;
// Handle routing
let searchParams = new URLSearchParams(window.location.search);
let scaffold_method = searchParams.get("scaffold");
if (scaffold_method == null) {
scaffold_method = "personal"; // Default to personalized model scaffold
}
let topic_vis_method = searchParams.get("topic_vis_method");
// Handle drawer
let open = false;
let selected = null;
let promise = Promise.resolve(null);
let editTitle = false;
let editErrorType = false;
let unfinished_count = 0;
let has_complete_report = false;
let save_check_visible = false; // Whether the save checkmark is visible
function setActive(value: string) {
selected = value;
// Set local and store value of open evidence to selected report's
cur_open_evidence = selected["evidence"];
open_evidence.update((value) => cur_open_evidence);
let isolated_topic = selected["title"].replace(/^(Topic: )/,'');
// Close panel
open = false;
// Update topic if in personal mode
if (scaffold_method == "personal" || scaffold_method == "personal_group" || scaffold_method == "personal_test" || scaffold_method == "tutorial") {
topic_chosen.update((value) => isolated_topic);
}
}
onMount(async () => {
promise = getReports();
});
async function getReports() {
if (model == "" || model == undefined){
return [];
}
let req_params = {
cur_user: cur_user,
scaffold_method: scaffold_method,
model: model,
topic_vis_method: topic_vis_method,
};
let params = new URLSearchParams(req_params).toString();
const response = await fetch("./get_reports?" + params);
const text = await response.text();
const data = JSON.parse(text);
all_reports = data["reports"]
// Select first report initially
selected = all_reports[0];
setActive(selected);
cur_open_evidence = selected["evidence"];
unfinished_count = all_reports.filter(item => (item.evidence.length == 0) || (item.text_entry == "") || !(item.sep_selection)).length
has_complete_report = hasCompleteReport();
return all_reports;
}
// Handle evidence saving
let cur_open_evidence = [];
new_evidence.subscribe(value => {
if (value != []) {
// Check if any values with the same ID exist
for (let i = 0; i < cur_open_evidence.length; i++) {
if (cur_open_evidence[i]["id"] == value["id"]) {
return; // If so, don't add the item
}
}
cur_open_evidence = cur_open_evidence.concat(value); // add new evidence item
// Add to open evidence in store
open_evidence.update((value) => cur_open_evidence);
// Save to selected value
if (selected != null) {
selected["evidence"] = cur_open_evidence;
}
}
});
// Handle evidence removal
open_evidence.subscribe(value => {
if ((value != cur_open_evidence) && (value.length < cur_open_evidence.length)) {
// Update local open evidence
cur_open_evidence = value;
// Save to selected value
if (selected != null) {
selected["evidence"] = cur_open_evidence;
}
}
});
let promise_save = Promise.resolve(null);
function handleSaveReport() {
// Briefly display checkmark
promise_save = saveReport();
save_check_visible = true;
// Hide save checkmark after 1 second
setTimeout(() => save_check_visible = false, 1000);
}
async function saveReport() {
let req_params = {
cur_user: cur_user,
reports: JSON.stringify(all_reports),
scaffold_method: scaffold_method,
model: model,
};
let params = new URLSearchParams(req_params).toString();
const response = await fetch("./save_reports?" + params);
const text = await response.text();
const data = JSON.parse(text);
has_complete_report = hasCompleteReport();
return data;
}
function handleNewReport() {
let new_report = {
title: "",
error_type: "",
evidence: [],
text_entry: "",
sep_selection: "",
};
all_reports = all_reports.concat(new_report);
promise = Promise.resolve(all_reports);
// Open this new report
selected = all_reports[all_reports.length - 1];
cur_open_evidence = selected["evidence"];
unfinished_count = all_reports.filter(item => (item.evidence.length == 0) || (item.text_entry == "") || !(item.sep_selection)).length
}
function handleDeleteReport() {
// Remove selected item from reports
all_reports = all_reports.filter(item => item != selected);
promise = Promise.resolve(all_reports);
selected = all_reports[0];
cur_open_evidence = selected["evidence"];
unfinished_count = all_reports.filter(item => (item.evidence.length == 0) || (item.text_entry == "") || !(item.sep_selection)).length
}
function hasCompleteReport() {
return all_reports.some(item => (item.evidence.length > 0) && (item.text_entry != "") && (item.sep_selection));
}
// Error type
let error_type_options = [
{
"opt": 'Both',
"descr": '(System is under- or over-sensitive)',
"help": "View both types of potential system errors"
},
{
"opt": 'System is under-sensitive',
"descr": '(Incorrectly rates as non-toxic)',
"help": "Focus on system errors where the system labeled content as Non-toxic when it should have been labeled as Toxic."
},
{
"opt": 'System is over-sensitive',
"descr": '(Incorrectly rates as toxic)',
"help": "Focus on system errors where the system labeled content as Toxic when it should have been labeled as Non-toxic."
},
{
"opt": 'Show errors and non-errors',
"descr": '',
"help": "Also show cases that are not likely to be potential errors"
},
]
// Save current error type
async function updateErrorType() {
// Update error type on main page to be the selected error type
editErrorType = false;
}
// SEP selection
let all_sep_options = [
"Accuracy",
"Bias/Discrimination",
"Adversarial Example",
"Other",
];
let promise_submit = Promise.resolve(null);
function handleSubmitReport() {
promise_submit = submitReport();
}
async function submitReport() {
submit_dialog_open = true;
return true;
}
</script>
<div>
{#await promise_submit}
<CircularProgress style="height: 32px; width: 32px;" indeterminate />
{:then}
<SubmitReportDialog bind:open={submit_dialog_open} cur_user={cur_user} all_reports={all_reports}/>
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
<div class="hypothesis_panel">
<div class="panel_header">
<div class="panel_header_content">
<div class="page_header">
<img src="/logo.png" style="height: 50px; padding: 0px 20px;" alt="IndieLabel" />
<Button class="user_button" color="secondary" style="margin: 12px 10px;" >
<Label>User: {cur_user}</Label>
</Button>
</div>
<div class="hypotheses_header">
<h5 style="float: left; margin: 0; padding: 5px 20px;">Your Audit Reports</h5>
<Button
on:click={() => (open = !open)}
color="primary"
disabled={model == null}
style="float: right; padding: 10px; margin-right: 10px;"
>
{#if open}
<Label>Close</Label>
{:else}
{#key unfinished_count}
<Label>Unfinished reports ({unfinished_count})</Label>
{/key}
{/if}
</Button>
</div>
</div>
</div>
{#if model == null}
<div class="panel_contents">
<p>You can start to author audit reports in this panel after you've trained your personalized model in the "Labeling" tab.</p>
</div>
{:else}
<div class="panel_contents">
<!-- Drawer -->
{#await promise}
<div class="app_loading_fullwidth">
<LinearProgress indeterminate />
</div>
{:then reports}
{#if reports}
<div class="drawer-container">
{#key open}
<Drawer variant="dismissible" bind:open>
<Header>
<Title>Your Reports</Title>
<Subtitle>Select a report to view.</Subtitle>
</Header>
<Content>
<List twoLine>
{#each reports as report}
<Item
href="javascript:void(0)"
on:click={() => setActive(report)}
activated={selected === report}
>
{#if (report["evidence"].length > 0) && (report["text_entry"] != "") && (report["sep_selection"])}
<Graphic class="material-icons" aria-hidden="true">task_alt</Graphic>
{:else}
<Graphic class="material-icons" aria-hidden="true">radio_button_unchecked</Graphic>
{/if}
<Text>
<PrimaryText>
{report["title"]}
</PrimaryText>
<SecondaryText>
{report["error_type"]}
</SecondaryText>
</Text>
</Item>
{/each}
</List>
</Content>
</Drawer>
{/key}
<AppContent class="app-content">
<main class="main-content">
{#if selected}
<div class="head_6_highlight">
Current Report
</div>
<div class="panel_contents2">
<!-- Title -->
<div class="spacing_vert">
<div class="edit_button_row">
{#if editTitle}
<div class="edit_button_row_input">
<Textfield
bind:value={selected["title"]}
label="Your report title"
input$rows={4}
textarea
variant="outlined"
style="width: 100%;"
helperLine$style="width: 100%;"
/>
</div>
<div>
<IconButton class="material-icons grey_button" size="button" on:click={() => (editTitle = false)}>
check
</IconButton>
</div>
{:else}
{#if selected["title"] != ""}
<div class="head_5">
{selected["title"]}
</div>
{:else}
<div class="grey_text">Enter a report title</div>
{/if}
<div>
<IconButton class="material-icons grey_button" size="button" on:click={() => (editTitle = true)}>
create
</IconButton>
</div>
{/if}
</div>
</div>
<!-- Error type -->
<div class="spacing_vert_40">
<div class="head_6">
<b>Error Type</b>
</div>
<div class="edit_button_row">
{#if editErrorType}
<div>
{#each error_type_options as e}
<div style="display: flex; align-items: center;">
<FormField>
<Radio bind:group={selected["error_type"]} value={e.opt} on:change={updateErrorType} color="secondary" />
<span slot="label">
<b>{e.opt}</b> {e.descr}
</span>
</FormField>
</div>
{/each}
</div>
{:else}
{#if selected["error_type"] != ""}
<div>
<p>{selected["error_type"]}</p>
</div>
{:else}
<div class="grey_text">Select an error type</div>
{/if}
<div>
<IconButton class="material-icons grey_button" size="button" on:click={() => (editErrorType = true)}>
create
</IconButton>
</div>
{/if}
</div>
</div>
<!-- Evidence -->
<div class="spacing_vert_40">
<div class="head_6">
<b>Evidence</b>
</div>
{#key cur_open_evidence}
<div>
{#if cur_open_evidence.length > 0}
<ClusterResults
cluster={cur_topic}
model={model}
data={{"cluster_comments": cur_open_evidence}}
show_vis={false}
show_checkboxes={false}
table_width_pct={100}
rowsPerPage={25}
table_id={"panel"}
/>
{:else}
<p class="grey_text">
Add examples from the main panel to see them here!
</p>
{/if}
</div>
{/key}
</div>
<div class="spacing_vert_40">
<div class="head_6">
<b>Summary/Suggestions</b>
</div>
<div class="spacing_vert">
<Textfield
style="width: 100%;"
helperLine$style="width: 100%;"
input$rows={8}
textarea
bind:value={selected["text_entry"]}
label="My current hunch is that..."
>
</Textfield>
</div>
</div>
<div class="spacing_vert_40 spacing_vert_100_bottom">
<div class="head_6">
<b>Audit Category</b>
</div>
<div>
<Select bind:value={selected["sep_selection"]} label="Audit category" style="width: 90%">
{#each all_sep_options as opt}
<Option value={opt}>{opt}</Option>
{/each}
</Select>
</div>
</div>
</div>
{/if}
</main>
</AppContent>
</div>
{/if}
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
</div>
<div class="panel_footer">
<div class="panel_footer_contents">
<!-- New button -->
<Button
on:click={handleNewReport}
variant="outlined"
>
<Label>New</Label>
</Button>
<!-- Delete button -->
<!-- <Button
on:click={handleDeleteReport}
variant="outlined"
>
<Label>Delete</Label>
</Button> -->
<!-- Save button -->
<Button
on:click={handleSaveReport}
variant="outlined"
>
<Label>
{#await promise_save}
<CircularProgress style="height: 13.5px; width: 13.5px;" indeterminate />
{:then result}
{#if result && save_check_visible}
<span transition:fade>
<Icon class="material-icons">check</Icon>
</span>
{/if}
{:catch error}
<span style="color: red">{error.message}</span>
{/await}
Save
</Label>
</Button>
<!-- Send to Avid button -->
{#key has_complete_report}
<Button
on:click={handleSubmitReport}
variant="outlined"
>
<Label>Send Reports to AVID</Label>
</Button>
{/key}
</div>
<div class="feedback_section">
<a href="https://forms.gle/vDXchpbBFjDeKjJA6" target="_blank" class="feedback_link">
Share feedback about the tool
</a>
</div>
</div>
{/if}
</div>
</div>
<style>
.panel_contents {
padding: 0 20px;
overflow-y: auto;
top: 150px;
position: relative;
height: 82%;
}
.panel_contents2 {
padding-left: 10px;
}
.panel_header {
position: fixed;
width: 30%;
border-bottom: 1px solid #d7d7d7; /* c5c5c5 */
background: #f3f3f3;
z-index: 11;
}
.panel_footer {
position: fixed;
width: 30%;
border-top: 1px solid #d7d7d7;
background: #f3f3f3;
z-index: 11;
bottom: 0;
padding: 5px 0px;
}
.panel_footer_contents {
display: flex;
justify-content: space-around;
align-items: center;
padding: 5px 0px 10px 0px;
}
.feedback_section {
display: flex;
justify-content: space-around;
align-items: center;
}
.feedback_link {
color: var(--mdc-theme-secondary);
font-size: 10px;
text-decoration: underline;
}
:global(.mdc-button.user_button) {
float: right;
margin-right: 20px;
max-width: 200px;
}
:global(.mdc-button.user_button span) {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.page_header {
width: 100%;
background: #e3d6fd;
/* padding: 21px 0; */
/* border-bottom: 1px solid #e3d6fd; */
padding: 10.5px 0;
position: relative;
display: inline-block;
}
.page_header:before {
content: '';
border-right: 1px solid rgb(0 0 0 / 7%);
position: absolute;
height: 80%;
top: 10%;
right: 0;
}
.hypotheses_header {
display: inline-block;
width: 100%;
padding: 10px 0;
vertical-align: middle;
}
</style>
|