Jack-ki1 commited on
Commit
721021e
Β·
verified Β·
1 Parent(s): 36523ad

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +92 -161
README.md CHANGED
@@ -7,214 +7,145 @@ colorFrom: green
7
  colorTo: gray
8
  sdk_version: 1.51.0
9
  ---
10
- # Python β†’ Streamlit Converter Pro
11
 
12
- A powerful, production-ready tool that converts Python scripts and Jupyter Notebooks into fully functional Streamlit applications. Handles large files, preserves comments and markdown, and provides multiple conversion strategies.
13
 
14
- ## ✨ Features
15
-
16
- ### Core Capabilities
17
- - **Multi-Format Support**: Convert `.py` files and `.ipynb` notebooks
18
- - **Large File Handling**: Efficiently processes files up to 5MB+ with optimized algorithms
19
- - **Comment Preservation**: All comments, docstrings, and inline documentation are preserved
20
- - **Markdown Support**: Notebook markdown cells are converted to commented Python code
21
- - **Batch Processing**: Upload ZIP archives to convert multiple files at once
22
-
23
- ### Conversion Strategies
24
 
25
- 1. **Hybrid Mode (Recommended)**: Combines AST parsing with regex patterns
26
- - Best balance of accuracy and performance
27
- - Handles complex code structures
28
- - Preserves formatting and comments
29
 
30
- 2. **AST Mode (Precise)**: Pure abstract syntax tree transformation
31
- - Deep understanding of code structure
32
- - Best for complex transformations
33
- - Preserves all code semantics
34
 
35
- 3. **Regex Mode (Fast)**: Pattern-based matching
36
- - Fastest for very large files
37
- - Good for simple conversions
38
- - Efficient memory usage
 
 
 
 
 
 
 
 
39
 
40
- 4. **Auto Mode**: Automatically selects the best strategy based on file size
41
 
42
- ### What Gets Converted?
43
 
44
- | Original Code | Streamlit Equivalent |
45
- |--------------|---------------------|
46
  | `print(x)` | `st.write(x)` |
47
  | `display(df)` | `st.dataframe(df)` |
48
- | `df.head()` / `df.tail()` | `st.dataframe(df.head())` |
 
49
  | `plt.show()` | `st.pyplot(plt.gcf())` |
50
- | `fig.show()` (Plotly) | `st.plotly_chart(fig)` |
51
- | Markdown cells | Commented markdown |
52
- | All comments | Preserved |
 
 
 
 
53
 
54
- ## πŸš€ Installation
55
 
56
- 1. Clone or download this repository
57
- 2. Install dependencies:
58
 
59
  ```bash
60
- pip install -r Requirements.txt
 
 
61
  ```
62
 
63
- ## πŸ“– Usage
64
-
65
- ### Running the Application
66
 
67
  ```bash
68
  streamlit run app.py
69
  ```
70
 
71
- The application will open in your default web browser.
72
-
73
- ### Basic Workflow
74
-
75
- 1. **Upload Files**: Use the sidebar to upload Python files or Jupyter notebooks
76
- - Individual files: Upload one or more files directly
77
- - ZIP archive: Upload a ZIP containing multiple files
78
-
79
- 2. **Configure Settings** (Optional):
80
- - Choose conversion strategy (Hybrid recommended)
81
- - Set large file threshold
82
- - Enable/disable main guard
83
- - Toggle comment preservation
84
-
85
- 3. **Review & Download**:
86
- - View original and converted code side-by-side
87
- - Check conversion report for details
88
- - Download the converted Streamlit app
89
-
90
- ### Advanced Settings
91
-
92
- - **Conversion Strategy**: Choose how the code is analyzed and converted
93
- - **Large File Threshold**: Files above this size (in KB) use optimized processing
94
- - **Main Guard**: Adds `if __name__ == '__main__':` wrapper for safer execution
95
- - **Preserve Comments**: Keep all comments and docstrings in the output
96
-
97
- ## 🎯 Use Cases
98
-
99
- - **Data Science Projects**: Convert Jupyter notebooks with visualizations to interactive Streamlit dashboards
100
- - **Script Migration**: Transform existing Python scripts into web applications
101
- - **Batch Conversion**: Process entire project folders at once
102
- - **Prototyping**: Quickly create Streamlit apps from existing code
103
-
104
- ## πŸ”§ Technical Details
105
 
106
- ### Architecture
 
 
 
107
 
108
- - **AST-Based Transformation**: Uses Python's `ast` module for structural analysis
109
- - **Regex Fallback**: Pattern matching for edge cases and large files
110
- - **Hybrid Approach**: Combines both methods for optimal results
111
- - **Error Recovery**: Graceful fallbacks when parsing fails
112
-
113
- ### Performance
114
-
115
- - Handles files up to 5MB+ efficiently
116
- - Chunked processing for large files
117
- - Caching for repeated conversions
118
- - Memory-efficient algorithms
119
-
120
- ### Limitations
121
 
122
- - Does not execute code (safe conversion only)
123
- - Complex interactive widgets (e.g., `ipywidgets`) require manual conversion
124
- - Some edge cases in very complex code may need manual adjustment
125
- - Manual review recommended before production deployment
126
 
127
- ## πŸ“ Example
 
 
 
 
128
 
129
- ### Input (Jupyter Notebook Cell):
130
- ```python
131
- import pandas as pd
132
- import matplotlib.pyplot as plt
133
 
134
- df = pd.read_csv('data.csv')
135
- print(f"Dataset has {len(df)} rows")
136
- display(df.head())
137
 
138
- plt.figure(figsize=(10, 6))
139
- plt.plot(df['x'], df['y'])
140
- plt.show()
 
 
141
  ```
142
 
143
- ### Output (Streamlit App):
144
- ```python
145
- import streamlit as st
146
- import pandas as pd
147
- import matplotlib.pyplot as plt
148
-
149
- st.set_page_config(
150
- page_title='Converted App',
151
- layout='wide'
152
- )
153
 
154
- st.title(' Converted Streamlit App')
155
 
156
- df = pd.read_csv('data.csv')
157
- st.write(f"Dataset has {len(df)} rows")
158
- st.dataframe(df.head())
159
 
160
- plt.figure(figsize=(10, 6))
161
- plt.plot(df['x'], df['y'])
162
- st.pyplot(plt.gcf())
163
- ```
 
 
 
 
 
 
 
 
 
164
 
165
- ## πŸ› οΈ Development
166
 
167
- ### Project Structure
168
- ```
169
- python_to_full_streamlit/
170
- β”œβ”€β”€ app.py # Main Streamlit application
171
- β”œβ”€β”€ Requirements.txt # Python dependencies
172
- └── README.md # This file
173
- ```
174
 
175
- ### Key Components
176
 
177
- 1. **HybridConverter**: Main conversion engine with multiple strategies
178
- 2. **CommentPreservingTransformer**: AST transformer that preserves code structure
179
- 3. **extract_code_from_notebook**: Enhanced notebook processing with markdown support
180
- 4. **File Processing**: Cached, efficient file handling with error recovery
181
 
182
- ## 🀝 Contributing
183
 
184
- This is a production-ready converter. Improvements welcome for:
185
- - Additional conversion patterns
186
- - Performance optimizations
187
- - Edge case handling
188
- - UI/UX enhancements
189
 
190
- ## πŸ“„ License
191
 
192
- This project is provided as-is for converting Python code to Streamlit applications.
193
 
194
  ## πŸ’‘ Tips
195
 
196
- - Use **Hybrid mode** for best results on most files
197
- - Enable **comment preservation** to maintain documentation
198
- - For very large files (>1MB), consider using **Regex mode**
199
- - Always review converted code before deployment
200
- - Test the generated Streamlit app with sample data
201
-
202
- ## πŸ› Troubleshooting
203
 
204
- **Issue**: Conversion fails on a file
205
- - **Solution**: Try a different conversion mode (AST vs Regex)
206
- - Check if the file has syntax errors
207
- - Verify the file is valid Python/Jupyter format
208
 
209
- **Issue**: Comments are missing
210
- - **Solution**: Enable "Preserve Comments" in advanced settings
211
- - Use AST or Hybrid mode instead of Regex
212
 
213
- **Issue**: Large file processing is slow
214
- - **Solution**: Increase the large file threshold
215
- - Use Regex mode for very large files
216
- - Process files individually instead of in ZIP
217
 
218
- ---
 
219
 
220
- **Made with ❀️ for the Streamlit community**
 
 
7
  colorTo: gray
8
  sdk_version: 1.51.0
9
  ---
10
+ # PyStreamlit Converter Pro
11
 
12
+ > Transform **Jupyter Notebooks** and **Python scripts** into polished, interactive **Streamlit apps** β€” in seconds.
13
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ ---
 
 
 
16
 
17
+ ## ✨ Features
 
 
 
18
 
19
+ | Feature | Description |
20
+ |---|---|
21
+ | **Hybrid Conversion Engine** | Three-pass AST + regex pipeline for accurate, reliable conversion |
22
+ | **Deep Code Analysis** | Complexity metrics, library detection, function/class inventory |
23
+ | **Widget Suggester** | Scans hard-coded literals and proposes sidebar sliders, checkboxes, inputs |
24
+ | **Diff Viewer** | Unified-diff comparison with configurable context lines |
25
+ | **Auto `@st.cache_data`** | Automatically decorates data-loading functions |
26
+ | **Auto Error Handling** | Wraps app body in `try/except` with `st.error()` + traceback expander |
27
+ | **Batch ZIP Processing** | Convert an entire folder; download all results as one ZIP |
28
+ | **Session History** | Timestamped timeline of all conversions this session |
29
+ | **Light / Dark Theme** | Toggle from the sidebar |
30
+ | **Two Built-in Samples** | Notebook and script for instant testing |
31
 
32
+ ---
33
 
34
+ ## πŸ”„ Transformation Map
35
 
36
+ | Original Python | Streamlit Equivalent |
37
+ |---|---|
38
  | `print(x)` | `st.write(x)` |
39
  | `display(df)` | `st.dataframe(df)` |
40
+ | `df.head()` | `st.dataframe(df.head())` |
41
+ | `df.describe()` | `st.dataframe(df.describe())` |
42
  | `plt.show()` | `st.pyplot(plt.gcf())` |
43
+ | `fig.show()` | `st.plotly_chart(fig)` |
44
+ | `show(bokeh_fig)` | `st.bokeh_chart(fig)` |
45
+ | Notebook markdown cells | `st.markdown(...)` |
46
+ | `%magic` / `!shell` commands | *(removed)* |
47
+ | `load_*()` / `fetch_*()` functions | `@st.cache_data` applied |
48
+
49
+ ---
50
 
51
+ ## πŸš€ Quick Start
52
 
53
+ ### 1. Clone and install
 
54
 
55
  ```bash
56
+ git clone https://github.com/your-username/pystreamlit-converter.git
57
+ cd pystreamlit-converter
58
+ pip install -r requirements.txt
59
  ```
60
 
61
+ ### 2. Run
 
 
62
 
63
  ```bash
64
  streamlit run app.py
65
  ```
66
 
67
+ ### 3. Convert your first file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ 1. Upload a `.py` or `.ipynb` file via the sidebar
70
+ 2. Adjust settings (or keep the defaults)
71
+ 3. Preview the output side-by-side
72
+ 4. Download the generated `*_streamlit.py`
73
 
74
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
+ ## 🧠 Conversion Strategies
 
 
 
77
 
78
+ | Strategy | Best For |
79
+ |---|---|
80
+ | **Hybrid** *(default)* | Any file β€” AST + regex fallback |
81
+ | **AST Precise** | Clean Python 3.9+ with valid syntax |
82
+ | **Regex Fast** | Large files or syntax-heavy / magic-heavy code |
83
 
84
+ ---
 
 
 
85
 
86
+ ## πŸ“ Project Structure
 
 
87
 
88
+ ```
89
+ pystreamlit-converter/
90
+ β”œβ”€β”€ app.py # Single-file Streamlit application
91
+ β”œβ”€β”€ requirements.txt # Python dependencies
92
+ └── README.md # Documentation
93
  ```
94
 
95
+ ---
 
 
 
 
 
 
 
 
 
96
 
97
+ ## βš™οΈ Configuration Options
98
 
99
+ All options are accessible from the sidebar:
 
 
100
 
101
+ | Option | Description | Default |
102
+ |---|---|---|
103
+ | Strategy | Conversion engine | Hybrid |
104
+ | Chart Library | Preferred target chart lib | Auto-Detect |
105
+ | App Layout | `wide` or `centered` | `wide` |
106
+ | @st.cache_data | Auto-cache data-loading fns | On |
107
+ | Error Handling | try/except wrapper | On |
108
+ | Auto Sidebar Widgets | Expose literals as controls | On |
109
+ | Download Button Stub | CSV export template | On |
110
+ | Session State Init | Add session_state init block | Off |
111
+ | if __name__ guard | Wrap in main guard | Off |
112
+ | Preserve Comments | Keep docstrings / comments | On |
113
+ | Large File Threshold | Strategy switch threshold | 200 KB |
114
 
115
+ ---
116
 
117
+ ## πŸ” Analyze Tab
 
 
 
 
 
 
118
 
119
+ Gives a full breakdown before you convert:
120
 
121
+ - **Complexity** β€” total/code/comment/blank lines, cyclomatic complexity
122
+ - **Library Detection** β€” chart, ML, and data libraries
123
+ - **Function Inventory** β€” name, args, line count, async flag
124
+ - **Widget Suggestions** β€” literals that could become interactive controls
125
 
126
+ ---
127
 
128
+ ## πŸ“¦ Batch ZIP Processing
 
 
 
 
129
 
130
+ Upload a ZIP containing `.py` / `.ipynb` files. The app converts each one and packages all outputs into a downloadable ZIP.
131
 
132
+ ---
133
 
134
  ## πŸ’‘ Tips
135
 
136
+ 1. Run **Analyze** first to understand what will change
137
+ 2. Enable **Auto Sidebar Widgets** to make parameters interactive
138
+ 3. Use the **Diff Viewer** to review changes before deploying
139
+ 4. **Hybrid** mode handles 99% of files reliably
 
 
 
140
 
141
+ ---
 
 
 
142
 
143
+ ## πŸ—ΊοΈ images of app
 
 
144
 
145
+ ![app image 1](img_1.png)
 
 
 
146
 
147
+ #### πŸ—ΊοΈ image 2
148
+ ![app image 2](img_2.png)
149
 
150
+ #### πŸ—ΊοΈ image 3
151
+ ![app image 3](img_3.png)