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

Add an anchor_links parameter to gr.ParamViewer that allows linking to specific parameters. #10495

Merged
merged 11 commits into from
Feb 5, 2025

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Feb 3, 2025

Closes: #10339 and updates our docs to use this.

Test with:

import gradio as gr

with gr.Blocks() as demo:
    gr.Markdown("The `round()` function in Python takes two parameters"*1000)
    gr.ParamViewer(
        {
           "number": {
             "type": "int | float",
             "description": "The number to round",
             "default": None
            },
            "ndigits": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits2": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits3": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits4": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits5": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits6": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
        },
        anchor_links=True,
    )

if __name__ == "__main__":
    demo.launch()

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Feb 3, 2025

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/f331adcd354ebe18c74608a76dc229b70270d929/gradio-5.14.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/f331adcd354ebe18c74608a76dc229b70270d929/gradio-client-1.10.0.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/f331adcd354ebe18c74608a76dc229b70270d929/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Feb 3, 2025

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/paramviewer minor
gradio minor
website minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Add an anchor_links parameter to gr.ParamViewer that allows linking to specific parameters.

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.

@abidlabs abidlabs requested a review from aliabd February 3, 2025 23:57
@abidlabs abidlabs marked this pull request as ready for review February 4, 2025 19:58
@aliabd
Copy link
Collaborator

aliabd commented Feb 4, 2025

@abidlabs, there's a problem in your website code that if there are multiple params on the page with the same name, they're both getting the same id so the linking gets broken because it doesn't know which to reference. For example, the docs for interface has fn paramater in the class and also in load. Both get the id "param-fn" so this link is broken: https://d3a08c02.gradio-website.pages.dev/docs/gradio/interface#param-fn

It should be param-{class/function name}-{param-name} I've done something similar before. so let me fix this

@abidlabs
Copy link
Member Author

abidlabs commented Feb 4, 2025

Ah right of course, thanks for taking care of it!

Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

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

LGTM now!

Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

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

nevermind. like you notes @abidlabs this won't work because it will change the hash everything the website rebuilds. working on new fix now

Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

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

Ok @abidlabs. based on your suggestion you can now pass a string to anchor_links that will act as a prefix.

I tested this with the website and this modified demo:

import gradio as gr

with gr.Blocks() as demo:
    gr.Markdown("The `round()` function in Python takes two parameters"*1000)
    gr.ParamViewer(
        {
           "number": {
             "type": "int | float",
             "description": "The number to round",
             "default": None
            },
            "ndigits": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits2": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits3": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits4": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits5": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            }
        },
        anchor_links=True,
    )

    gr.ParamViewer(
        {
           "number": {
             "type": "int | float",
             "description": "The number to round",
             "default": None
            },
            "ndigits": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits2": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits3": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits4": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits5": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            }
        },
        anchor_links=False,
    )


    gr.ParamViewer(
        {
           "number": {
             "type": "int | float",
             "description": "The number to round",
             "default": None
            },
            "ndigits": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits2": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits3": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits4": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits5": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            }
        },
        anchor_links="bananas",
    )

    gr.ParamViewer(
        {
           "number": {
             "type": "int | float",
             "description": "The number to round",
             "default": None
            },
            "ndigits": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits2": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits3": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits4": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            },
            "ndigits5": {
             "type": "int",
             "description": "The number of digits to round to",
                "default": "0",
            }
        },
        anchor_links="",
    )


if __name__ == "__main__":
    demo.launch()

And it's working great. Because paramtable.svelte wasn't passing fn/class names i had to edit all the svx files. but now should be good to go. please take a look at my changes though

@abidlabs
Copy link
Member Author

abidlabs commented Feb 5, 2025

LGTM @aliabd thanks so much for the fix!

@abidlabs abidlabs merged commit 35fda36 into main Feb 5, 2025
23 checks passed
@abidlabs abidlabs deleted the param-links branch February 5, 2025 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support linking to specific parameters in the docs
3 participants