You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: example/Example_1_multi_page_image_editor/README.md
+104-2Lines changed: 104 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,29 @@
1
1
# Example 1: Multi-Page Image Editor
2
2
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
+
---
4
12
5
13
## One-Step Conversion (Recommended)
6
14
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
+
7
19
Ensure you have your `requirements.txt` ready:
8
20
```text
9
21
streamlit
10
22
Pillow
11
23
```
12
24
25
+
### 2. Run the Conversion
26
+
13
27
Create a build script (e.g., `build.py`):
14
28
15
29
```python
@@ -24,7 +38,95 @@ script2stlite.convert_app(
24
38
25
39
Run it to generate `Image_Editor.html`.
26
40
27
-
## Features
41
+
###Features
28
42
-**Multi-page support**: Demonstrates how `pages/` directory is automatically handled.
29
43
-**External libraries**: Uses `Pillow` for image manipulation.
30
44
-**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
# 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:
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