-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Widgets] Refactor examples running #1023
Merged
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
667710d
Rm `previewInputSample` by reusing `applyInputSample`
mishig25 85aac2e
Rm unneeded `getDemoInputs` function
mishig25 c56c64f
better naming
mishig25 aa2396e
format
mishig25 d2374e4
correct typing
mishig25 d5325f9
add missing await
mishig25 2730c9c
Update js/src/lib/components/InferenceWidget/shared/helpers.ts
mishig25 3ba2298
format
mishig25 7858186
use `opts` syntax
mishig25 fd40b25
run onMount widget example inside WidgetWrapper
mishig25 756223d
all widgets run onMount example inside WidgetWrapper
mishig25 580c830
Rm `previewInputSample` by reusing `applyInputSample`
mishig25 f89936c
Rm unneeded `getDemoInputs` function
mishig25 0654367
better naming
mishig25 94249c4
format
mishig25 353f172
correct typing
mishig25 23a2fe0
add missing await
mishig25 c36fcdc
Update js/src/lib/components/InferenceWidget/shared/helpers.ts
mishig25 06420aa
format
mishig25 44eb4f1
use `opts` syntax
mishig25 ada2b70
run onMount widget example inside WidgetWrapper
mishig25 37f2ccd
all widgets run onMount example inside WidgetWrapper
mishig25 8446c3e
Merge branch 'rebase' into refactor_examples_running
mishig25 7ebca52
fix logic
mishig25 c89086b
stronger typing
mishig25 4d03786
format
mishig25 9ea310a
more refactor
mishig25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,30 +3,18 @@ import { randomItem, parseJSON } from "../../../utils/ViewUtils"; | |
import type { WidgetExample } from "./WidgetExample"; | ||
import type { ModelLoadInfo, TableData } from "./types"; | ||
|
||
const VALID_QUERY_PARAMS = [ | ||
// string vals | ||
"text", | ||
"context", | ||
"question", | ||
"query", | ||
"candidateLabels", | ||
// table vals | ||
"multiClass", | ||
"table", | ||
// boolean vals | ||
"structuredData", | ||
]; | ||
export type QueryParam = typeof VALID_QUERY_PARAMS[number]; | ||
type KeysOfUnion<T> = T extends any ? keyof T : never; | ||
export type QueryParam = KeysOfUnion<WidgetExample>; | ||
type QueryParamVal = string | null | boolean | (string | number)[][]; | ||
export function getQueryParamVal(key: QueryParam): QueryParamVal { | ||
const searchParams = new URL(window.location.href).searchParams; | ||
const value = searchParams.get(key); | ||
if (["text", "context", "question", "query", "candidateLabels"].includes(key)) { | ||
if (["text", "context", "question", "query", "candidate_labels"].includes(key)) { | ||
return value; | ||
} else if (["table", "structuredData"].includes(key)) { | ||
} else if (["table", "structured_data"].includes(key)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as the comment above but for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const table = convertDataToTable((parseJSON(value) as TableData) ?? {}); | ||
return table; | ||
} else if (key === "multiClass") { | ||
} else if (key === "multi_class") { | ||
return value === "true"; | ||
} | ||
return value; | ||
|
@@ -43,7 +31,7 @@ export function getWidgetExample<TWidgetExample extends WidgetExample>( | |
} | ||
|
||
// Update current url search params, keeping existing keys intact. | ||
export function updateUrl(obj: Record<QueryParam, string | undefined>): void { | ||
export function updateUrl(obj: Partial<Record<QueryParam, string | undefined>>): void { | ||
if (!window) { | ||
return; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not work on existing URLs of ZeroShotClassification widget with URL query
candidateLabels
rather thancandidate_labels
. However, ZeroShotClassification widgets are not used widely. Therefore, I think this breaking change is fineThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i agree for
candidate_labels
(it's used in the spec for widget examples) but forstructuredData
it's used that way in the spec no?https://huggingface.co/docs/hub/models-widgets-examples#structured-data-classification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdyt #1064?
I can either merge #1064 or revert the changes back to using
strucutredData
. I will let you decideThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comment there