Skip to content
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

Fix gr.Interface.from_pipeline() to allow audio uploads and to display classification labels correctly #8080

Merged
merged 5 commits into from Apr 19, 2024

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Apr 19, 2024

Description

During #8052, I found something.


Reference: first commit of from_pipeline

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Apr 19, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detecting...

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/c7a99b6a98ebd8c1d30cb355bd371a87de8128b7/gradio-4.27.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@c7a99b6a98ebd8c1d30cb355bd371a87de8128b7#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Apr 19, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix gr.Interface.from_pipeline() to allow audio uploads and to display classification labels correctly

Maintainers or the PR author can modify the PR title to modify this entry.

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 update the changelog file directly.

@@ -66,7 +59,7 @@ def is_transformers_pipeline_type(pipeline, class_name: str):
),
"outputs": components.Label(label="Classification", render=False),
"preprocess": lambda i: {"images": i},
"postprocess": lambda r: {i["label"].split(", ")[0]: i["score"] for i in r},
Copy link
Member Author

@whitphx whitphx Apr 19, 2024

Choose a reason for hiding this comment

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

This transforms a label name like "tiger, Panthera tigris" into just "tiger", which looks not good.

On main:
CleanShot 2024-04-19 at 16 27 16@2x

This change:
CleanShot 2024-04-19 at 16 27 50@2x

Sample code:

import gradio as gr
from transformers import pipeline


pipe = pipeline("image-classification", "google/vit-base-patch16-224")

demo = gr.Interface.from_pipeline(pipe)

demo.launch()

Sample file to test: https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg

Copy link
Member

Choose a reason for hiding this comment

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

Yeah in the general case better to leave the labels as is

@whitphx whitphx marked this pull request as ready for review April 19, 2024 20:33
Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

lgtm @whitphx!

@abidlabs abidlabs added the v: patch A change that requires a patch release label Apr 19, 2024
@abidlabs
Copy link
Member

I would just suggest using a more precise name for this PR since that is what shows up in the changelog

@whitphx
Copy link
Member Author

whitphx commented Apr 19, 2024

that is what shows up in the changelog

Oh 👀
Will do it.

@whitphx whitphx changed the title Improve gr.Interface.from_pipeline() Fix gr.Interface.from_pipeline() to allow audio uploads and to display classification labels correctly Apr 19, 2024
@whitphx whitphx merged commit 568eeb2 into main Apr 19, 2024
7 checks passed
@whitphx whitphx deleted the from-pipeline-improve branch April 19, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v: patch A change that requires a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants