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 gradio tool demos #31230

Merged
merged 2 commits into from
Jun 11, 2024
Merged

Fix gradio tool demos #31230

merged 2 commits into from
Jun 11, 2024

Conversation

aymeric-roucher
Copy link
Contributor

What does this PR do?

Resolves Gradio demos on Spaces for tools not working properly.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@aymeric-roucher aymeric-roucher force-pushed the fix-gradio-tool-demos branch 2 times, most recently from c2ecd5b to 663071c Compare June 5, 2024 10:08
@@ -88,7 +88,8 @@ class AgentImage(AgentType, ImageType):
"""

def __init__(self, value):
super().__init__(value)
AgentType.__init__(self, value)
ImageType.__init__(self)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found that without this, the ImageType attributes would not be inherited.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm I'm curious why that is the case, I'll investigate

@@ -125,6 +128,10 @@ def to_raw(self):
self._raw = Image.open(self._path)
return self._raw

if self._tensor is not None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This case was missing in the original function

@@ -125,6 +128,10 @@ def to_raw(self):
self._raw = Image.open(self._path)
return self._raw

if self._tensor is not None:
array = self._tensor.cpu().detach().numpy()
return Image.fromarray((255 - array * 255).astype(np.uint8))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I invert the image colors with this (255 - array*255), else the image appears in negative.


class AgentAudio(AgentType):
class AgentAudio(AgentType, str):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I add the str type so that gradio postprocessor can recognize the AgentAudio as a path to an audio.

@aymeric-roucher aymeric-roucher force-pushed the fix-gradio-tool-demos branch 3 times, most recently from 306a52d to 5163ab6 Compare June 5, 2024 12:31
@aymeric-roucher aymeric-roucher force-pushed the fix-gradio-tool-demos branch 2 times, most recently from b9c774e to af90dab Compare June 5, 2024 12:36
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Ok it looks good! I'm just curious about the need to instantiate the two types, it shouldn't be the case (I'll investigate and we can merge afterwards)

@@ -88,7 +88,8 @@ class AgentImage(AgentType, ImageType):
"""

def __init__(self, value):
super().__init__(value)
AgentType.__init__(self, value)
ImageType.__init__(self)
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm I'm curious why that is the case, I'll investigate

@aymeric-roucher aymeric-roucher merged commit 12ae6d3 into main Jun 11, 2024
21 checks passed
@aymeric-roucher aymeric-roucher deleted the fix-gradio-tool-demos branch June 11, 2024 09:35
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Jun 14, 2024
itazap pushed a commit that referenced this pull request Jun 17, 2024
* Fix gradio tool demos
itazap pushed a commit that referenced this pull request Jun 17, 2024
* Fix gradio tool demos
itazap pushed a commit that referenced this pull request Jun 17, 2024
* Fix gradio tool demos
itazap pushed a commit that referenced this pull request Jun 18, 2024
* Fix gradio tool demos
itazap pushed a commit that referenced this pull request Jun 20, 2024
* Fix gradio tool demos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants