Skip to main content

FnGradio

This is an experimental library that allows you to define Gradio apps using type hints.

Install

pip install fngradio

Simple Example

Instead of (where type hints are not used for the interface):

import gradio as gr


def add_int_numbers(a: int, b: int) -> int:
    """
    Add two int numbers
    """
    return a + b


demo = gr.Interface(
    fn=add_int_numbers,
    api_name="add_int_numbers",
    inputs=[
        gr.Number(precision=0),
        gr.Number(precision=0)
    ],
    outputs=[gr.Number(precision=0)],
)

if __name__ == '__main__':
    demo.launch(share=False)

You can define the Gradio interface around by just adding the fngr.interface annotation which will create inputs and outputs based on the type hints:

import fngradio as fngr


@fngr.interface()
def add_int_numbers(a: int, b: int) -> int:
    """
    Add two int numbers
    """
    return a + b


if __name__ == '__main__':
    add_int_numbers.launch(share=False)

Slider for Integer With Range

You can use pydantic's Field annotation to provide additional information. If ge and le are defined for an integer, then it will use the Gradio's Slider component.

from typing import Annotated
from pydantic import Field
import fngradio as fngr


@fngr.interface()
def add_int_numbers_with_sliders(
    a: Annotated[int, Field(title="First value", ge=0, le=100)] = 50,
    b: Annotated[int, Field(title="Second value", ge=0, le=100)] = 50
) -> int:
    """
    Add two int numbers
    """
    return a + b

Dropdown for Literal

from typing import Literal
from pydantic import Field
import fngradio as fngr


@fngr.interface
def say(what: Literal["hi", "bye"]) -> str:
    """
    Says Hi! or Bye!
    """
    return "Hi!" if what == "hi" else "Bye!"

Image for PIL.Image.Image

from typing import Literal
import PIL.Image
from pydantic import Field
import fngradio as fngr


@fngr.interface
def generate_image(
    width: Annotated[int, Field(ge=10, le=200)] = 100,
    height: Annotated[int, Field(ge=10, le=200)] = 100
) -> PIL.Image.Image:
    """
    Generates sample image
    """
    image = PIL.Image.new(
        mode="RGB",
        size=(width, height),
        color="lightblue"
    )
    return image

Specify Component in Type Annotation

You can also specify the Gradio Component to use by adding it to the type annotation:

from typing import Annotated
import gradio as gr
import fngradio as fngr


@fngr.interface()
def to_upper_case(
    s: Annotated[str, gr.TextArea(label="text", value="Hello")]
) -> Annotated[str, gr.TextArea()]:
    """
    Converts text to upper case
    """
    return s.upper()

Tabbed Interface

A tabbed interface can be useful when you have multiple tools (e.g. multiple MCP tools).

Instead of:

demo = gr.TabbedInterface(
    interface_list=[
        add_int_numbers,
        to_upper_case
    ],
    tab_names=["add_int_numbers", "to_upper_case"]
)

You could use the fngr.tabbed_interface:

demo = fngr.tabbed_interface([
    add_int_numbers,
    to_upper_case
])

The main advantage is that it will try to infer the names from the interface.

Or even simpler use FnGradioApp for defining interfaces:

from fngradio import FnGradioApp


app = FnGradioApp()

@app.interface()
def add_int_numbers(a: int, b: int) -> int:
    """
    Add two int numbers
    """
    return a + b


@app.interface()
def to_upper_case(s: str) -> str:
    """
    Converts text to upper case
    """
    return s.upper()


demo = app.tabbed()

if __name__ == '__main__':
    demo.launch(share=False)

Combine Apps

In order to support apps across modules, you can combine apps:

from fngradio import FnGradioApp


app_1 = FnGradioApp()
app_2 = FnGradioApp()

@app_1.interface()
def upper(s: str) -> str:
    return s.upper()


@app_2.interface()
def lower(s: str) -> str:
    return s.lower()


app = FnGradioApp(apps=[app_1, app_2])

Example Apps

Example Gradio apps demonstrating use:

Metadata

Release files for fngradio 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fngradio 0.0.9
File Size Uploaded
fngradio-0.0.9.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fngradio 0.0.9
File Interpreter ABI Platform
fngradio-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / fngradio-0.0.9.tar.gz

Download URL fngradio-0.0.9.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
80acb6cf5923ddf7289c3f2bb66a7a288f912c6523baaecc7c226c984c8e455f
BLAKE2b-256 checksum
How to use checksums
0eaf3c81fb3f41c50463705eafa76c4c51aa2993548a61d0d68269c1863cf78a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 19, 2025.

Transparency log

Release files / fngradio-0.0.9-py3-none-any.whl

Download URL fngradio-0.0.9-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
114fda3f5a4ae9c6425d0dc5c4311ecf1bc824ee3c38e3c64cd994307c8628cd
BLAKE2b-256 checksum
How to use checksums
34436703c29f43cee93f8969980c39af2d6934b59e48adba76b7203d0865f02d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 19, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page