Skip to content

Commit 847091d

Browse files
authored
Merge pull request #100 from LukeAFullard/update-example0-readme-4805387239960699286
Update Example 1 README with detailed legacy instructions and live de…
2 parents b8ee8cc + a543cfb commit 847091d

1 file changed

Lines changed: 104 additions & 2 deletions

File tree

  • example/Example_1_multi_page_image_editor

example/Example_1_multi_page_image_editor/README.md

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
# Example 1: Multi-Page Image Editor
22

3-
This example demonstrates how to convert a multi-page Streamlit application with image processing capabilities (using Pillow) into a standalone HTML file.
3+
This example demonstrates how to use `script2stlite` to convert a multi-page Streamlit application, specifically an image editor, into a single self-contained HTML file. This application includes multiple Python files organized in a `pages/` directory, an `assets/` folder, and specific package requirements (like `Pillow`).
4+
5+
`script2stlite` is a tool that packages your Streamlit application, along with its dependencies, into an HTML file that can be run in a web browser using [stlite](https://github.com/whitphx/stlite), without needing a Python backend server.
6+
7+
## Live Demo
8+
9+
You can view the output of this specific example hosted on GitHub Pages here: [https://lukeafullard.github.io/script2stlite/example/Example_1_multi_page_image_editor/Image_Editor.html](https://lukeafullard.github.io/script2stlite/example/Example_1_multi_page_image_editor/Image_Editor.html)
10+
11+
---
412

513
## One-Step Conversion (Recommended)
614

15+
As of version 0.3.0, you can convert your app in a single step using the top-level `convert_app` function.
16+
17+
### 1. Prerequisites
18+
719
Ensure you have your `requirements.txt` ready:
820
```text
921
streamlit
1022
Pillow
1123
```
1224

25+
### 2. Run the Conversion
26+
1327
Create a build script (e.g., `build.py`):
1428

1529
```python
@@ -24,7 +38,95 @@ script2stlite.convert_app(
2438

2539
Run it to generate `Image_Editor.html`.
2640

27-
## Features
41+
### Features
2842
- **Multi-page support**: Demonstrates how `pages/` directory is automatically handled.
2943
- **External libraries**: Uses `Pillow` for image manipulation.
3044
- **Asset embedding**: Includes `assets/image.png` automatically.
45+
46+
---
47+
48+
## Legacy Instructions (Manual Configuration)
49+
50+
If you prefer explicit control over every file included, or are using an older version of `script2stlite`, you can use the original process with `settings.yaml`.
51+
52+
### Application Structure
53+
54+
The Image Editor application has the following structure:
55+
* `app.py`: The main entry point for the Streamlit application. It sets up the overall page configuration.
56+
* `pages/`: This directory contains the different pages of the application:
57+
* `01_Home.py`: The landing page.
58+
* `02_Upload_Image.py`: Page for uploading images.
59+
* `03_Adjust_Image.py`: Page for performing image adjustments like brightness, contrast, rotation, and grayscale.
60+
* `assets/`: Contains static assets, like a sample image (`image.png`).
61+
* `settings.yaml`: The configuration file for `script2stlite`.
62+
63+
### 1. Install script2stlite
64+
65+
Ensure you have `script2stlite` installed. If not, you can typically install it using pip:
66+
67+
```bash
68+
pip install script2stlite
69+
```
70+
*(Note: Refer to the main project README for the most up-to-date installation instructions.)*
71+
72+
### 2. Prepare Your Project Folder
73+
74+
If you were starting from scratch, you would use `converter.prepare_folder()`. This command creates a `settings.yaml` file (if one doesn't exist) and a `pages` directory. For this example, these are already provided.
75+
76+
```python
77+
from script2stlite import Script2StliteConverter
78+
79+
# Initialize the converter for this example's directory
80+
converter = Script2StliteConverter("example/Example_1_multi_page_image_editor")
81+
82+
# Prepare the folder (optional if settings.yaml and pages/ already exist)
83+
# converter.prepare_folder()
84+
```
85+
86+
### 3. Review and Modify `settings.yaml`
87+
88+
The `settings.yaml` file is key to correctly packaging the multi-page application. Here's the content for this Example 1:
89+
90+
```yaml
91+
APP_NAME: "Image Editor"
92+
APP_REQUIREMENTS:
93+
- streamlit
94+
- Pillow # For image manipulation
95+
APP_ENTRYPOINT: app.py # Main app file that sets page config
96+
CONFIG: false
97+
APP_FILES:
98+
- pages/01_Home.py
99+
- pages/02_Upload_Image.py
100+
- pages/03_Adjust_Image.py
101+
- assets/image.png
102+
```
103+
104+
Key aspects for a multi-page app:
105+
* **APP_NAME**: Defines the application's title and the output HTML filename (e.g., `Image_Editor.html`).
106+
* **APP_REQUIREMENTS**: Lists necessary Python packages. `Pillow` is crucial for the image processing features. Remember, these must be Pyodide-compatible.
107+
* **APP_ENTRYPOINT**: This should be your main script, typically the one that might contain `st.set_page_config()` and acts as the primary entry point. For multi-page apps, this is often a small `app.py` or similar, while individual pages reside in the `pages/` directory.
108+
* **APP_FILES**: This is where you list all the Python files for each page within the `pages` directory. You also include any assets like images or data files.
109+
* *Note: `script2stlite` automatically recognizes and processes the `pages/` directory convention for Streamlit multi-page apps if your entry point and page files are structured correctly. Listing them explicitly ensures they are included.*
110+
111+
### 4. Convert the Application to HTML
112+
113+
With `settings.yaml` configured, convert the application:
114+
115+
```python
116+
from script2stlite import Script2StliteConverter
117+
118+
# Initialize the converter
119+
converter = Script2StliteConverter("example/Example_1_multi_page_image_editor")
120+
121+
# Convert the application
122+
converter.convert()
123+
124+
print(f"Conversion complete! Check for '{converter.directory}/Image_Editor.html'.")
125+
```
126+
This command bundles `app.py`, all files in `pages/`, the assets, and the specified requirements into `Image_Editor.html`.
127+
128+
### 5. View Your Application
129+
130+
Open the generated `Image_Editor.html` in a web browser. You should see the multi-page image editor application, allowing you to navigate between home, upload, and adjust pages.
131+
132+
This example showcases how `script2stlite` handles multi-page applications and dependencies, making it easy to share complex Streamlit projects as single HTML files.

0 commit comments

Comments
 (0)