Update README.md
Browse files
README.md
CHANGED
|
@@ -7,214 +7,145 @@ colorFrom: green
|
|
| 7 |
colorTo: gray
|
| 8 |
sdk_version: 1.51.0
|
| 9 |
---
|
| 10 |
-
#
|
| 11 |
|
| 12 |
-
|
| 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 |
-
|
| 26 |
-
- Best balance of accuracy and performance
|
| 27 |
-
- Handles complex code structures
|
| 28 |
-
- Preserves formatting and comments
|
| 29 |
|
| 30 |
-
|
| 31 |
-
- Deep understanding of code structure
|
| 32 |
-
- Best for complex transformations
|
| 33 |
-
- Preserves all code semantics
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
|
| 42 |
-
##
|
| 43 |
|
| 44 |
-
| Original
|
| 45 |
-
|---
|
| 46 |
| `print(x)` | `st.write(x)` |
|
| 47 |
| `display(df)` | `st.dataframe(df)` |
|
| 48 |
-
| `df.head()`
|
|
|
|
| 49 |
| `plt.show()` | `st.pyplot(plt.gcf())` |
|
| 50 |
-
| `fig.show()`
|
| 51 |
-
|
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
## π
|
| 55 |
|
| 56 |
-
1. Clone
|
| 57 |
-
2. Install dependencies:
|
| 58 |
|
| 59 |
```bash
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
```
|
| 62 |
|
| 63 |
-
##
|
| 64 |
-
|
| 65 |
-
### Running the Application
|
| 66 |
|
| 67 |
```bash
|
| 68 |
streamlit run app.py
|
| 69 |
```
|
| 70 |
|
| 71 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
-
|
| 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 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
-
```python
|
| 131 |
-
import pandas as pd
|
| 132 |
-
import matplotlib.pyplot as plt
|
| 133 |
|
| 134 |
-
|
| 135 |
-
print(f"Dataset has {len(df)} rows")
|
| 136 |
-
display(df.head())
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
| 141 |
```
|
| 142 |
|
| 143 |
-
|
| 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 |
-
|
| 155 |
|
| 156 |
-
|
| 157 |
-
st.write(f"Dataset has {len(df)} rows")
|
| 158 |
-
st.dataframe(df.head())
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
|
| 166 |
|
| 167 |
-
##
|
| 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 |
-
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
|
| 182 |
-
|
| 183 |
|
| 184 |
-
|
| 185 |
-
- Additional conversion patterns
|
| 186 |
-
- Performance optimizations
|
| 187 |
-
- Edge case handling
|
| 188 |
-
- UI/UX enhancements
|
| 189 |
|
| 190 |
-
|
| 191 |
|
| 192 |
-
|
| 193 |
|
| 194 |
## π‘ Tips
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
- Test the generated Streamlit app with sample data
|
| 201 |
-
|
| 202 |
-
## π Troubleshooting
|
| 203 |
|
| 204 |
-
|
| 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 |
-
|
| 210 |
-
- **Solution**: Enable "Preserve Comments" in advanced settings
|
| 211 |
-
- Use AST or Hybrid mode instead of Regex
|
| 212 |
|
| 213 |
-
|
| 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 |
-
|
|
|
|
|
|
| 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 |
+

|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
+
#### πΊοΈ image 2
|
| 148 |
+

|
| 149 |
|
| 150 |
+
#### πΊοΈ image 3
|
| 151 |
+

|