Skip to content

Commit

Permalink
Adds GeneratedURL type and displays content to the GeneratedText and
Browse files Browse the repository at this point in the history
GeneratedImages modules.

PiperOrigin-RevId: 445168285
  • Loading branch information
RyanMullins authored and LIT team committed Apr 28, 2022
1 parent cfabe78 commit bb06368
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 7 additions & 1 deletion lit_nlp/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,13 @@ class TopTokens(LitType):
@attr.s(auto_attribs=True, frozen=True, kw_only=True)
class URL(TextSegment):
"""TextSegment that should be interpreted as a URL."""
align: Text = None # name of field in the model output
pass


@attr.s(auto_attribs=True, frozen=True, kw_only=True)
class GeneratedURL(TextSegment):
"""A URL that was generated as part of a model prediction."""
align: Optional[Text] = None # name of a field in the model output


@attr.s(auto_attribs=True, frozen=True, kw_only=True)
Expand Down
3 changes: 2 additions & 1 deletion lit_nlp/client/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export type LitName = 'type'|'LitType'|'String'|'TextSegment'|'GeneratedText'|
'AttentionHeads'|'SparseMultilabel'|'FieldMatcher'|'MultiFieldMatcher'|
'Gradients'|'Boolean'|'TokenSalience'|'ImageBytes'|'SparseMultilabelPreds'|
'ImageGradients'|'ImageSalience'|'SequenceSalience'|'ReferenceScores'|
'FeatureSalience'|'TopTokens'|'CurveDataPoints'|'InfluentialExamples';
'FeatureSalience'|'TopTokens'|'CurveDataPoints'|'InfluentialExamples'|
'GeneratedURL';

export const listFieldTypes: LitName[] =
['Tokens', 'SequenceTags', 'SpanLabels', 'EdgeLabels', 'SparseMultilabel'];
Expand Down
19 changes: 10 additions & 9 deletions lit_nlp/client/modules/generated_image_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class GeneratedImageModule extends LitModule {
static override template = (model = '', selectionServiceIndex = 0) => {
return html`
<generated-image-module model=${model}
selectionServiceIndex=${selectionServiceIndex}>
selectionServiceIndex=${selectionServiceIndex}>
</generated-image-module>`;
};

Expand Down Expand Up @@ -77,7 +77,8 @@ export class GeneratedImageModule extends LitModule {
const dataset = this.appState.currentDataset;
const promise = this.apiService.getPreds(
[input], this.model, dataset,
[...GeneratedImageModule.supportedTypes, 'URL'], 'Generating images');
[...GeneratedImageModule.supportedTypes, 'GeneratedURL'],
'Generating images');
const results = await this.loadLatest('generatedImages', promise);
if (results === null) return;

Expand Down Expand Up @@ -113,17 +114,17 @@ export class GeneratedImageModule extends LitModule {
<div class="module-results-area">
${Object.entries(this.generatedImages).map(([key, value]) => {
const keyType = output[key];
if (isLitSubtype(keyType, 'URL') && keyType.align != null &&
keyType.align in this.generatedImages) {
return this.renderLink(key, value);
}
if (isLitSubtype(keyType, GeneratedImageModule.supportedTypes)) {
return this.renderImage(key, value);
}
return html``;
const {align} = keyType;
if (isLitSubtype(keyType, 'GeneratedURL') &&
align != null && align in this.generatedImages) {
return this.renderLink(key, value);
}
return null;
})}
</div>
</div>
Expand Down

0 comments on commit bb06368

Please sign in to comment.