Skip to main content

Tesseract Streamlit automatically generates Streamlit apps from Tesseract APIs.

Project description

Tesseract Streamlit

A CLI tool that generates a Streamlit app from a running Tesseract instance. The generated app allows users to interactively submit input to the apply endpoint and optionally visualise results using custom plotting functions.

✨ Features

  • 🔍 Parses Tesseract's OpenAPI schema
  • ⚙️ Automatically builds input forms for the apply endpoint
  • 📊 Supports user-defined plotting of inputs and outputs
  • 🚀 Outputs a ready-to-run Streamlit app script
  • 🧩 Modular and customizable with minimal boilerplate

🛠 Requirements

  • Modern UNIX based OS (Linux or macOS), or Windows with WSL
  • Python >= 3.10
  • tesseract-core

📦 Installation

pip install tesseract-streamlit

🧰 Usage

tesseract-streamlit [OPTIONS] URL OUTPUT
  • URL: The address to the Tesseract instance you want to interface with.
  • OUTPUT: The file path to write the generated Streamlit app.

⚙️ Options

Option Description
--user-code, -u (Optional) Path to Python file with plotting functions
--help Show the help message and exit

📊 With Custom Plotting

You can optionally pass a Python file containing user-defined functions for plotting inputs and/or outputs.

tesseract-streamlit --user-code udf.py http://localhost:48819 app.py

The udf.py file should define functions like:

import plotly.graph_objects as go

def plot(inputs, outputs) -> go.Figure:
    """Title of the plot.

    Description of what the plot conveys. Will be displayed above the
    plot itself.
    """
    fig = go.Figure()
    # some plotly logic to visualise input_schema and output_schema
    return fig

Where we have chosen Plotly as our plotting back-end, but any supported library by Streamlit is allowed.

[!NOTE] Additionally, we support PyVista plots (thanks to edsaac/stpyvista)! Just annotate your function to return a pyvista.Plotter instance, and an interactive plot will be inserted.

⚙️ More info on defining custom plotting functions

Custom plotting is easy and flexible. Here’s how to make the most of it:

  • Function names don't matter, so name them however you like.
  • Define multiple functions to visualise more than one aspect of the data. Each one will generate a separate plot in the Streamlit app.
  • Add a docstring to each function to add descriptive text in the app:
    • First line of the docstring will appear as the plot title.
    • Remaining lines will be shown as a description below the title.
    • Omitting docstrings is allowed, but raises a UserDefinedFunctionWarning.
  • Public functions must include either inputs, outputs, or both as parameter names. Any public function that doesn't use these names will raise a UserDefinedFunctionError.
  • Private functions may be defined with a leading underscore in their name, eg. def _foo(x: float) -> float: ....
    • Arbitrary parameters and return types are allowed.
    • Will not produce plots directly in the Web UI.
    • Can be called from within your public plotting functions.

This setup gives you control over what to display and how to explain it, directly from your code.

📁 Example

See the example README for a basic example walk-through, or simply run the following script to see the end result!

bash examples/vectoradd_jax/run.sh

This will open a browser window with the Streamlit UI where users can input values and visualise the response.

⚠️ Current Limitations

While tesseract-streamlit supports Tesseracts with an InputSchema formed with arbitrary nesting of Pydantic models, it does not yet support nesting Pydantic models inside native Python collection types such as:

  • list[Model]
  • tuple[Model, ...]
  • dict[str, Model]

These types will raise an error or be ignored in the generated app.

You can however use these native collections with basic Python types, such as:

  • list[str]
  • dict[str, int]
  • tuple[float, float]

If you would like to request support for nested models within collections in a future release, please let us know.

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

tesseract_streamlit-0.1.0.tar.gz (243.8 kB view details)

Uploaded Source

Built Distribution

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

tesseract_streamlit-0.1.0-py3-none-any.whl (235.6 kB view details)

Uploaded Python 3

File details

Details for the file tesseract_streamlit-0.1.0.tar.gz.

File metadata

  • Download URL: tesseract_streamlit-0.1.0.tar.gz
  • Upload date:
  • Size: 243.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tesseract_streamlit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cd5bacafaf9a6ba34eefe5f09ad8c04b538b7adc5ba5ba3b1949d059a87d7ce9
MD5 f48cf593963720825b640a81a315fa33
BLAKE2b-256 19e1839ee367970761b3edfbb59e4ea6ea63b9a58e0ef1d2a7602d58423cb195

See more details on using hashes here.

Provenance

The following attestation bundles were made for tesseract_streamlit-0.1.0.tar.gz:

Publisher: publish.yml on pasteurlabs/tesseract-streamlit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tesseract_streamlit-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tesseract_streamlit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d24a507725ab2fd698144ac2750952f7a2435eddd8cf91bbc82bb6824693cb7
MD5 4644b9c115b354336edc4fe2a56dc657
BLAKE2b-256 afb477ee84168780dd7b42fe314b9a50838c7a22bc590f78c71fc0ef97beea82

See more details on using hashes here.

Provenance

The following attestation bundles were made for tesseract_streamlit-0.1.0-py3-none-any.whl:

Publisher: publish.yml on pasteurlabs/tesseract-streamlit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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