Skip to content

Fix ValueError in Controlling the Reload demo#11220

Merged
freddyaboulton merged 1 commit intogradio-app:mainfrom
jedick:main
May 19, 2025
Merged

Fix ValueError in Controlling the Reload demo#11220
freddyaboulton merged 1 commit intogradio-app:mainfrom
jedick:main

Conversation

@jedick
Copy link
Contributor

@jedick jedick commented May 19, 2025

Description

This PR changes the lambda function in the demo to return a value whose type is compatible with the gr.Label() output component.

The changed code uses dictionary comprehension to convert the list of dict with label and score keys returned by pipe() to a {Dict[str, float]} of classes and confidences used by gr.Label() to show classes and confidence bars.

Example of the value before this change. The list was the immediate cause of the ValueError:

s = "hooray"
pipe(s)
# [{'label': 'positive', 'score': 0.9420903325080872}]

Example of the value after this change. The dict has the class as key and confidence score as value:

s = "hooray"
{d["label"]: d["score"] for d in pipe(s)}
# {'positive': 0.9420903325080872}

Closes: #11170

Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jedick !

@freddyaboulton freddyaboulton enabled auto-merge (squash) May 19, 2025 12:42
@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented May 19, 2025

🪼 branch checks and previews

Name Status URL
Website ready! Website preview
🦄 Changes detected! Details
@gradio-pr-bot
Copy link
Collaborator

🦄 no changes detected

This Pull Request does not include changes to any packages.

__No changes detected. __

  • Maintainers can select this checkbox to manually select packages to update.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can create the changelog file directly.
@freddyaboulton freddyaboulton disabled auto-merge May 19, 2025 13:11
@freddyaboulton freddyaboulton merged commit e76545c into gradio-app:main May 19, 2025
25 of 27 checks passed
santibreo pushed a commit to santibreo/gradio that referenced this pull request May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants