Skip to main content

Python library for easily interacting with trained machine learning models

Project description

gradio_browser

PyPI - Version

Python library for easily interacting with trained machine learning models

Installation

pip install gradio_browser

Usage

import gradio as gr
from gradio_browser import Browser

with gr.Blocks(title="Browser Component Demo", fill_height=True) as demo:
    gr.Markdown("# 🌐 Custom Browser Component")

    with gr.Row():
        with gr.Column(scale=1):
            gr.Markdown("### Controls")
            url_input = gr.Textbox(
                label="Enter URL",
                value="https://www.gradio.app/",
                placeholder="https://www.gradio.app/",
            )

            show_hostname = gr.Checkbox(
                label="Show full hostname in address bar", value=True
            )

            gr.Markdown(
                """
            ### Features:
            - ← → Navigation buttons with history
            - ↻ Refresh button  
            - ↗ Open in new tab button
            - Address bar supports both full URLs and paths
            - Enter key navigation
            """
            )

            gr.Markdown("### Try these URLs:")

            gr.Button("Gradio.com").click(
                lambda: "https://www.gradio.app/", outputs=[url_input]
            )
            gr.Button("Example.com").click(
                lambda: "https://example.com", outputs=[url_input]
            )

        with gr.Column(scale=3):
            browser = Browser(
                url="https://example.com",
                show_hostname=True,
                min_height="600px",
                scale=1,
            )

    # Update browser when URL changes
    url_input.change(lambda url: url, inputs=[url_input], outputs=[browser])

    # Update show_hostname setting (requires component rebuild)
    show_hostname.change(
        lambda show_host, url: Browser(value=url, show_hostname=show_host),
        inputs=[show_hostname, url_input],
        outputs=[browser],
    )


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

Browser

Initialization

name type default description
value
str | Callable | None
None URL to display in the browser iframe
url
str
"https://example.com" Initial URL to load in the browser
width
str
"100%" Width of the browser component
min_height
str
"500px" Minimum height of the browser component
show_hostname
bool
False If True, shows full URL in address bar; if False, shows only path
placeholder
str | None
None placeholder hint to provide behind textbox.
label
str | I18nData | None
None the label for this component
every
Timer | float | None
None Continously calls `value` to recalculate it if `value` is a function
inputs
Component | Sequence[Component] | set[Component] | None
None Components that are used as inputs to calculate `value` if `value` is a function
show_label
bool | None
None if True, will display label.
scale
int | None
None relative size compared to adjacent Components
min_width
int
160 minimum pixel width
interactive
bool | None
None if True, will be rendered as an editable component
visible
bool | Literal["hidden"]
True If False, component will be hidden
rtl
bool
False If True, sets the direction of the text to right-to-left
elem_id
str | None
None An optional string that is assigned as the id of this component in the HTML DOM
elem_classes
list[str] | str | None
None An optional list of strings that are assigned as the classes of this component in the HTML DOM
render
bool
True If False, component will not render be rendered in the Blocks context
key
int | str | tuple[int | str, ...] | None
None in a gr.render, Components with the same key across re-renders are treated as the same component
preserved_by_key
list[str] | str | None
"value" A list of parameters from this component's constructor

Events

name description
change Triggered when the value of the Browser changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input.
input This listener is triggered when the user changes the value of the Browser.
submit This listener is triggered when the user presses the Enter key while the Browser is focused.

User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

  • When used as an Input, the component only impacts the input signature of the user function.
  • When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

  • As output: Is passed, passes URL value as a {str} into the function.
  • As input: Should return, expects a URL {str} to display in browser.
def predict(
    value: str | None
) -> str | None:
    return value

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_browser-0.0.3.tar.gz (393.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradio_browser-0.0.3-py3-none-any.whl (90.5 kB view details)

Uploaded Python 3

File details

Details for the file gradio_browser-0.0.3.tar.gz.

File metadata

  • Download URL: gradio_browser-0.0.3.tar.gz
  • Upload date:
  • Size: 393.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for gradio_browser-0.0.3.tar.gz
Algorithm Hash digest
SHA256 d66acf426077c1577695c5d191763da5b940aca35ecad6e2f29aa7dfc0bdd67a
MD5 5afffc039c512a244dde726e470e940b
BLAKE2b-256 7e7fe0e28b5397953fbd45980e25db0be2a120c8ed64c59eb1d71998863f148b

See more details on using hashes here.

File details

Details for the file gradio_browser-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: gradio_browser-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 90.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for gradio_browser-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d2984c61b59764f0e7751c0dc56ee89b7f2b6cfa7189b75902495878dab0bca7
MD5 ee24b6ba1e7e9e64f3de2bf7f59879c7
BLAKE2b-256 b08090cd4a7a88e6e60500926ea091408258a533e519468b6a2556330c73b46a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page