Skip to main content

A lightweight async alternative to gradio_client without heavy dependencies.

Project description

noob-gradio

A lightweight, async, dependency-free alternative to the official python gradio_client — written for speed, simplicity, and control.

PyPI Python Version License


Features

  • Fast & Async – built on top of aiohttp and aiofiles, thats all
  • Smart Parameter Checking – validates types, min/max/step before sending
  • Tiny Dependency Footprint – no heavy huggingface_hub and it's reqiurements (a lot)
  • Drop-in familiar syntax – like the official client, but simpler and async

Installation

pip install noob-gradio

Details

This project was inspired by the official gradio_client but rewritten to:

remove unnecessary dependencies,

run fully async,

and perform parameter validation before sending data to the server.

  • gradio_client is ok, but it installs a ton of stuff, so this is a noob remake of it.
  • Available functions: "handle_file", "client.predict" and "client.view_api".
  • Client functions are async and must be awaited.
  • The syntax is exacly the same as in official gradio_client.

New in 1.0.1

You can pass existing session to Client, to reuse it.

import aiohttp
from noob_gradio import Client

async def main():
    session = aiohttp.ClientSession()
    client = Client("url", session=session)
    result = await client.predict(kwargs)
    print(result)
    # in on_close or similar event/function, at exit
    await session.close()

Example

import asyncio
from noob_gradio import Client, handle_file

async def main():
    async with Client("black-forest-labs/FLUX.1-schnell") as client:
        result = await client.predict(
            prompt="a cat sitting on a chair",
            width=512,
            height=512,
            api_name="/infer",
        )
        print(result)
        # you should get a path to downloaded image and image seed - (Result, Seed) or whatever the space returns
        # to not download you can add download_files=False in Client

asyncio.run(main())

Also this supports the hf_token and other methods of creating a Client and session, here is example of everything

client = Client("black-forest-labs/FLUX.1-schnell", hf_token="secret", download_files=False, headers={"User-Agent": "gradio_real/1.0"})

async def main():
    async with client:
        # args and kwargs are suported
        res = await client.predict("a white cat", width=512, api_name="/infer")
        print(res)
    
    # "async with" alternative
    await client.connect()
    await client.view_api()
    # example file
    file = handle_file("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png")
    # also you can choose different space for each predict or view_api, with src
    res = await client.predict(src="some space with file support", file=file, api_name="/predict")
    print(res)

    await client.close()
    # "async with" or "connect+close" is required because its async

handle_file is needed for input of image or any file, local or from url - predict(image=handle_file("local_path_or_url"), ...)

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

noob_gradio-1.0.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

noob_gradio-1.0.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file noob_gradio-1.0.1.tar.gz.

File metadata

  • Download URL: noob_gradio-1.0.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for noob_gradio-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a0d8d8ebdd46cfde846227924234bed80f0cde64aabac1fbbfaf530e81b4b0ff
MD5 6d4c4be57ef33ade0c76cb539c26c60e
BLAKE2b-256 42168d94b5757c2920995944efbd19d9b57e61b832849c9d897d9f25d4c7a9cd

See more details on using hashes here.

File details

Details for the file noob_gradio-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: noob_gradio-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for noob_gradio-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 20dada342680197d1a1682372df75c47f72913d6f30eb4840b83510d609efc09
MD5 bb953a7d66627edeb5b588b0e38d10a7
BLAKE2b-256 743d0eb5a18c759fff6430ccc10518bf132502e02e8b061963bfe3cfe19109c8

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