Skip to content

Commit 8e0ba97

Browse files
doc: add examples section to docs (#13)
#### Relevant issue or PR <!-- If the changes resolve an issue or follow some other PR, link to them here. GitHub references are strongly preferred, but links to other resources, such as Jira or Confluence, can also be used. Only link something if it is directly relevant. --> Cherry picked from #9. #### Description of changes <!-- Add a high-level description of changes, focusing on the *what* and *why*. --> Adds examples section to Sphinx generated ReadTheDocs. Won't work until #12 is merged, since it relies on the new directory structure in the `examples/` folder. #### Testing done <!-- Describe how the changes were tested; e.g., "CI passes", "Tested manually in stagingrepo#123", screenshots of a terminal session that verify the changes, or any other evidence of testing the changes. -->
1 parent 03613a0 commit 8e0ba97

File tree

14 files changed

+113
-76
lines changed

14 files changed

+113
-76
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ This setup gives you control over what to display and how to explain it, directl
9797
See the example README for a basic example walk-through, or simply run the following script to see the end result!
9898

9999
```bash
100-
bash examples/run.sh
100+
bash examples/vectoradd_jax/run.sh
101101
```
102102

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

105-
| ![](examples/screenshots/header-vec-a.png) | ![](examples/screenshots/outputs.png) |
105+
| ![](examples/vectoradd_jax/screenshots/header-vec-a.png) | ![](examples/vectoradd_jax/screenshots/outputs.png) |
106106
| --------------------------------- | ---------------------------- |
107-
| ![](examples/screenshots/vec-b.png) | ![](examples/screenshots/plot.png) |
107+
| ![](examples/vectoradd_jax/screenshots/vec-b.png) | ![](examples/vectoradd_jax/screenshots/plot.png) |
108108

109109
## ⚠️ Current Limitations
110110

docs/conf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

99
import re
10+
import shutil
11+
from pathlib import Path
1012

1113
from tesseract_streamlit import __version__
1214

15+
PARENT_DIR = Path(__file__).parent.resolve()
16+
1317
project = "tesseract-streamlit"
1418
copyright = "2024, The tesseract-streamlit Team @ Pasteur Labs"
1519
author = "The tesseract-streamlit Team @ Pasteur Labs"
@@ -55,3 +59,10 @@
5559

5660
html_theme = "furo"
5761
html_static_path = ["static"]
62+
63+
# Copy example notebooks to docs/examples folder on every build
64+
for example_dir in Path("../examples").glob("*/"):
65+
# Copy the example directory to the docs folder
66+
shutil.copytree(
67+
example_dir, PARENT_DIR / "examples" / example_dir.name, dirs_exist_ok=True
68+
)

docs/examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*
2+
!.gitignore

docs/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@
1111
self
1212
api
1313
```
14+
15+
```{toctree}
16+
:caption: Examples
17+
:maxdepth: 2
18+
:hidden:
19+
20+
examples/vectoradd_jax/README.md
21+
```

examples/README.md

Lines changed: 0 additions & 72 deletions
This file was deleted.

examples/vectoradd_jax/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Visualising `vectoradd_jax` with Streamlit
2+
3+
This example shows how to quickly generate a Streamlit app to interact with the `vectoradd_jax` Tesseract.
4+
Using `tesseract-streamlit`, you'll get an app with autogenerated input controls and optional Python-defined visualisations — no UI code needed! 🚀
5+
6+
---
7+
8+
## 📥 Step 1: Download the Example Code
9+
10+
We'll use the `vectoradd_jax` example from `tesseract-core` version `v0.9.0`. Clone it with:
11+
12+
```shell
13+
git clone --depth 1 --branch v0.9.0 https://github.com/pasteurlabs/tesseract-core.git ~/Downloads/tesseract-core
14+
```
15+
16+
---
17+
18+
## 📦 Step 2: Install Requirements
19+
20+
Install the required packages for this example:
21+
22+
```bash
23+
pip install -r requirements.txt
24+
```
25+
26+
---
27+
28+
## 🛠️ Step 3: Build and Serve the Tesseract
29+
30+
Use the Tesseract CLI to build and serve `vectoradd_jax`:
31+
32+
```bash
33+
tesseract build ~/Downloads/tesseract-core/examples/vectoradd_jax
34+
tesseract serve vectoradd_jax
35+
```
36+
37+
> [!NOTE]
38+
> Make note of the `PORT` and `PROJECT ID` printed to stdout — you'll need them shortly.
39+
40+
---
41+
42+
## ⚡ Step 4: Generate the Streamlit App
43+
44+
With `tesseract-streamlit` installed, generate a ready-to-run Streamlit app:
45+
46+
```bash
47+
tesseract-streamlit --user-code udf.py "http://localhost:<PORT>" app.py
48+
```
49+
50+
`udf.py` can be found in under `tesseract-streamlit/examples/vectoradd_jax/`.
51+
It contains a custom function that takes the Tesseract's inputs and outputs and drops a Plotly-powered vector addition diagram straight into the web UI — automatically! 🎯
52+
[Check it out](https://github.com/pasteurlabs/tesseract-streamlit/blob/main/examples/vectoradd_jax/udf.py) to see how it works.
53+
54+
---
55+
56+
## ▶️ Step 5: Launch the App
57+
58+
Run your new app with:
59+
60+
```bash
61+
streamlit run app.py
62+
```
63+
64+
This will launch a web interface for submitting inputs, running the Tesseract, and visualising the results.
65+
66+
---
67+
68+
## 🖼️ Screenshots
69+
70+
| ![](screenshots/header-vec-a.png) | ![](screenshots/outputs.png) |
71+
| --------------------------------- | ---------------------------- |
72+
| ![](screenshots/vec-b.png) | ![](screenshots/plot.png) |
73+
74+
---
75+
76+
## 🧹 Step 6: Clean Up
77+
78+
When you're done, you can stop the Tesseract server with:
79+
80+
```bash
81+
tesseract teardown <PROJECT ID>
82+
```
83+
84+
---
85+
86+
🎉 That’s it — you've transformed a running Tesseract into a beautiful Streamlit web app with interactive plots, with minimal effort from the command line!
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)