Skip to content

Commit 565c05d

Browse files
Dev (#7)
* Add FastAPI server and visualization for SimpleAudit results - Implemented a FastAPI server in `server.py` to serve visualization pages and handle API requests for JSON audit results. - Created HTML template `visualizer.html` for displaying audit results with a responsive design using Tailwind CSS. - Added a favicon image `thumbnail.png` for the web application. - Introduced API endpoints to retrieve the file tree of JSON files and serve individual JSON file contents. - Implemented validation for JSON files to ensure they contain valid audit results. * Clarify local web server instructions in README Updated wording for clarity regarding the local web server. * Fix path resolution for HTML and favicon files in FastAPI server * Add package data for visualization assets in setuptools configuration * Bump version to 0.1.3 and update README with live demo link for visualization * Bump version from 0.1.3 to 0.1.4 in pyproject.toml
1 parent a6b5ff3 commit 565c05d

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ uvx simpleaudit[visualize] serve --results_dir ./my_audit_results
8888
pip install simpleaudit[visualize]
8989
simpleaudit serve --results_dir ./my_audit_results
9090
```
91-
This will spin-up a local web server to explore results with scenario details. See [visualization/README.md](simpleaudit/visualization/README.md) for more options and features.
91+
This will spin-up a local web server to explore results with scenario details. 👉 [Check for live demo.](https://simulamet-simpleauditvisualization.hf.space)
92+
See [visualization/README.md](simpleaudit/visualization/README.md) for more options and features.
9293

9394
> **Note:** Option 1 requires [`uv`](https://pypi.org/project/uv/) to be installed ([install guide](https://docs.astral.sh/uv/getting-started/installation/)).
9495

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "simpleaudit"
7-
version = "0.1.2"
7+
version = "0.1.4"
88
description = "Lightweight AI Safety Auditing Framework"
99
readme = "README.md"
1010
license = {text = "MIT"}
@@ -58,6 +58,12 @@ PyPI = "https://pypi.org/project/simpleaudit/"
5858
where = ["."]
5959
include = ["simpleaudit*"]
6060

61+
[tool.setuptools.package-data]
62+
simpleaudit = [
63+
"visualization/*.html",
64+
"visualization/*.png",
65+
]
66+
6167
[tool.black]
6268
line-length = 100
6369
target-version = ["py39", "py310", "py311", "py312"]

simpleaudit/visualization/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ simpleaudit serve --results_dir ./my_audit_results
2121
# Custom port and host
2222
simpleaudit serve --results_dir ./results --port 8080 --host 0.0.0.0
2323
```
24+
👉 [Check for live demo](https://simulamet-simpleauditvisualization.hf.space)
25+
2426

2527
**Or run directly with uv (no installation needed):**
2628
```bash
@@ -170,18 +172,21 @@ Both visualization methods support these JSON structures:
170172
```bash
171173
# After running your audit
172174
simpleaudit serve --results_dir ./examples/local_audit_example_results
175+
<!-- 👉 [Check for demo](https://simulamet-simpleauditvisualization.hf.space) -->
173176
```
174177

175178
### Example 2: Multiple Audits
176179
```bash
177180
# Browse all audits in a directory
178181
simpleaudit serve --results_dir ./all_audits
182+
<!-- 👉 [Check for demo](https://simulamet-simpleauditvisualization.hf.space) -->
179183
```
180184

181185
### Example 3: Share with Team
182186
```bash
183187
# Start server on network-accessible host
184188
simpleaudit serve --results_dir ./results --host 0.0.0.0 --port 8080
189+
<!-- 👉 [Check for demo](https://simulamet-simpleauditvisualization.hf.space) -->
185190
```
186191

187192
Then share: `http://YOUR_IP:8080`
@@ -200,12 +205,14 @@ Then share: `http://YOUR_IP:8080`
200205
If port 8000 is in use:
201206
```bash
202207
simpleaudit serve --results_dir ./results --port 8001
208+
<!-- 👉 [Check for demo](https://simulamet-simpleauditvisualization.hf.space) -->
203209
```
204210

205211
### Allow External Access
206212
To access from other devices on your network:
207213
```bash
208214
simpleaudit serve --results_dir ./results --host 0.0.0.0
215+
<!-- 👉 [Check for demo](https://simulamet-simpleauditvisualization.hf.space) -->
209216
```
210217

211218
---

simpleaudit/visualization/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def get_file_tree(directory: str, base_path: str = "") -> List[Dict]:
9393
@app.get("/")
9494
async def root():
9595
"""Serve the main visualization page."""
96-
html_path = Path(__file__).parent / "visualizer.html"
96+
html_path = Path(__file__).resolve().parent / "visualizer.html"
9797

9898
if not html_path.exists():
9999
return HTMLResponse(
@@ -110,7 +110,7 @@ async def root():
110110
@app.get("/scenario_viewer.html")
111111
async def scenario_viewer():
112112
"""Serve the standalone scenario viewer page."""
113-
html_path = Path(__file__).parent / "scenario_viewer.html"
113+
html_path = Path(__file__).resolve().parent / "scenario_viewer.html"
114114

115115
if not html_path.exists():
116116
return HTMLResponse(
@@ -127,7 +127,7 @@ async def scenario_viewer():
127127
@app.get("/favicon.png")
128128
async def favicon():
129129
"""Serve the favicon."""
130-
favicon_path = Path(__file__).parent / "thumbnail.png"
130+
favicon_path = Path(__file__).resolve().parent / "thumbnail.png"
131131

132132
if not favicon_path.exists():
133133
raise HTTPException(status_code=404, detail="Favicon not found")

0 commit comments

Comments
 (0)