Jack-ki1 commited on
Commit
4cbfa17
Β·
verified Β·
1 Parent(s): 34ac52a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +219 -212
README.md CHANGED
@@ -1,212 +1,219 @@
1
- # Python β†’ Streamlit Converter Pro
2
-
3
- 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.
4
-
5
- ## ✨ Features
6
-
7
- ### Core Capabilities
8
- - **Multi-Format Support**: Convert `.py` files and `.ipynb` notebooks
9
- - **Large File Handling**: Efficiently processes files up to 5MB+ with optimized algorithms
10
- - **Comment Preservation**: All comments, docstrings, and inline documentation are preserved
11
- - **Markdown Support**: Notebook markdown cells are converted to commented Python code
12
- - **Batch Processing**: Upload ZIP archives to convert multiple files at once
13
-
14
- ### Conversion Strategies
15
-
16
- 1. **Hybrid Mode (Recommended)**: Combines AST parsing with regex patterns
17
- - Best balance of accuracy and performance
18
- - Handles complex code structures
19
- - Preserves formatting and comments
20
-
21
- 2. **AST Mode (Precise)**: Pure abstract syntax tree transformation
22
- - Deep understanding of code structure
23
- - Best for complex transformations
24
- - Preserves all code semantics
25
-
26
- 3. **Regex Mode (Fast)**: Pattern-based matching
27
- - Fastest for very large files
28
- - Good for simple conversions
29
- - Efficient memory usage
30
-
31
- 4. **Auto Mode**: Automatically selects the best strategy based on file size
32
-
33
- ### What Gets Converted?
34
-
35
- | Original Code | Streamlit Equivalent |
36
- |--------------|---------------------|
37
- | `print(x)` | `st.write(x)` |
38
- | `display(df)` | `st.dataframe(df)` |
39
- | `df.head()` / `df.tail()` | `st.dataframe(df.head())` |
40
- | `plt.show()` | `st.pyplot(plt.gcf())` |
41
- | `fig.show()` (Plotly) | `st.plotly_chart(fig)` |
42
- | Markdown cells | Commented markdown |
43
- | All comments | Preserved |
44
-
45
- ## πŸš€ Installation
46
-
47
- 1. Clone or download this repository
48
- 2. Install dependencies:
49
-
50
- ```bash
51
- pip install -r Requirements.txt
52
- ```
53
-
54
- ## πŸ“– Usage
55
-
56
- ### Running the Application
57
-
58
- ```bash
59
- streamlit run app.py
60
- ```
61
-
62
- The application will open in your default web browser.
63
-
64
- ### Basic Workflow
65
-
66
- 1. **Upload Files**: Use the sidebar to upload Python files or Jupyter notebooks
67
- - Individual files: Upload one or more files directly
68
- - ZIP archive: Upload a ZIP containing multiple files
69
-
70
- 2. **Configure Settings** (Optional):
71
- - Choose conversion strategy (Hybrid recommended)
72
- - Set large file threshold
73
- - Enable/disable main guard
74
- - Toggle comment preservation
75
-
76
- 3. **Review & Download**:
77
- - View original and converted code side-by-side
78
- - Check conversion report for details
79
- - Download the converted Streamlit app
80
-
81
- ### Advanced Settings
82
-
83
- - **Conversion Strategy**: Choose how the code is analyzed and converted
84
- - **Large File Threshold**: Files above this size (in KB) use optimized processing
85
- - **Main Guard**: Adds `if __name__ == '__main__':` wrapper for safer execution
86
- - **Preserve Comments**: Keep all comments and docstrings in the output
87
-
88
- ## 🎯 Use Cases
89
-
90
- - **Data Science Projects**: Convert Jupyter notebooks with visualizations to interactive Streamlit dashboards
91
- - **Script Migration**: Transform existing Python scripts into web applications
92
- - **Batch Conversion**: Process entire project folders at once
93
- - **Prototyping**: Quickly create Streamlit apps from existing code
94
-
95
- ## πŸ”§ Technical Details
96
-
97
- ### Architecture
98
-
99
- - **AST-Based Transformation**: Uses Python's `ast` module for structural analysis
100
- - **Regex Fallback**: Pattern matching for edge cases and large files
101
- - **Hybrid Approach**: Combines both methods for optimal results
102
- - **Error Recovery**: Graceful fallbacks when parsing fails
103
-
104
- ### Performance
105
-
106
- - Handles files up to 5MB+ efficiently
107
- - Chunked processing for large files
108
- - Caching for repeated conversions
109
- - Memory-efficient algorithms
110
-
111
- ### Limitations
112
-
113
- - Does not execute code (safe conversion only)
114
- - Complex interactive widgets (e.g., `ipywidgets`) require manual conversion
115
- - Some edge cases in very complex code may need manual adjustment
116
- - Manual review recommended before production deployment
117
-
118
- ## πŸ“ Example
119
-
120
- ### Input (Jupyter Notebook Cell):
121
- ```python
122
- import pandas as pd
123
- import matplotlib.pyplot as plt
124
-
125
- df = pd.read_csv('data.csv')
126
- print(f"Dataset has {len(df)} rows")
127
- display(df.head())
128
-
129
- plt.figure(figsize=(10, 6))
130
- plt.plot(df['x'], df['y'])
131
- plt.show()
132
- ```
133
-
134
- ### Output (Streamlit App):
135
- ```python
136
- import streamlit as st
137
- import pandas as pd
138
- import matplotlib.pyplot as plt
139
-
140
- st.set_page_config(
141
- page_title='Converted App',
142
- layout='wide'
143
- )
144
-
145
- st.title(' Converted Streamlit App')
146
-
147
- df = pd.read_csv('data.csv')
148
- st.write(f"Dataset has {len(df)} rows")
149
- st.dataframe(df.head())
150
-
151
- plt.figure(figsize=(10, 6))
152
- plt.plot(df['x'], df['y'])
153
- st.pyplot(plt.gcf())
154
- ```
155
-
156
- ## πŸ› οΈ Development
157
-
158
- ### Project Structure
159
- ```
160
- python_to_full_streamlit/
161
- β”œβ”€β”€ app.py # Main Streamlit application
162
- β”œβ”€β”€ Requirements.txt # Python dependencies
163
- └── README.md # This file
164
- ```
165
-
166
- ### Key Components
167
-
168
- 1. **HybridConverter**: Main conversion engine with multiple strategies
169
- 2. **CommentPreservingTransformer**: AST transformer that preserves code structure
170
- 3. **extract_code_from_notebook**: Enhanced notebook processing with markdown support
171
- 4. **File Processing**: Cached, efficient file handling with error recovery
172
-
173
- ## 🀝 Contributing
174
-
175
- This is a production-ready converter. Improvements welcome for:
176
- - Additional conversion patterns
177
- - Performance optimizations
178
- - Edge case handling
179
- - UI/UX enhancements
180
-
181
- ## πŸ“„ License
182
-
183
- This project is provided as-is for converting Python code to Streamlit applications.
184
-
185
- ## πŸ’‘ Tips
186
-
187
- - Use **Hybrid mode** for best results on most files
188
- - Enable **comment preservation** to maintain documentation
189
- - For very large files (>1MB), consider using **Regex mode**
190
- - Always review converted code before deployment
191
- - Test the generated Streamlit app with sample data
192
-
193
- ## πŸ› Troubleshooting
194
-
195
- **Issue**: Conversion fails on a file
196
- - **Solution**: Try a different conversion mode (AST vs Regex)
197
- - Check if the file has syntax errors
198
- - Verify the file is valid Python/Jupyter format
199
-
200
- **Issue**: Comments are missing
201
- - **Solution**: Enable "Preserve Comments" in advanced settings
202
- - Use AST or Hybrid mode instead of Regex
203
-
204
- **Issue**: Large file processing is slow
205
- - **Solution**: Increase the large file threshold
206
- - Use Regex mode for very large files
207
- - Process files individually instead of in ZIP
208
-
209
- ---
210
-
211
- **Made with ❀️ for the Streamlit community**
212
-
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ title: python_to_streamlit_convertor
4
+ sdk: streamlit
5
+ emoji: πŸ“Š
6
+ colorFrom: green
7
+ colorTo: gray
8
+ ---
9
+ # Python β†’ Streamlit Converter Pro
10
+
11
+ 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.
12
+
13
+ ## ✨ Features
14
+
15
+ ### Core Capabilities
16
+ - **Multi-Format Support**: Convert `.py` files and `.ipynb` notebooks
17
+ - **Large File Handling**: Efficiently processes files up to 5MB+ with optimized algorithms
18
+ - **Comment Preservation**: All comments, docstrings, and inline documentation are preserved
19
+ - **Markdown Support**: Notebook markdown cells are converted to commented Python code
20
+ - **Batch Processing**: Upload ZIP archives to convert multiple files at once
21
+
22
+ ### Conversion Strategies
23
+
24
+ 1. **Hybrid Mode (Recommended)**: Combines AST parsing with regex patterns
25
+ - Best balance of accuracy and performance
26
+ - Handles complex code structures
27
+ - Preserves formatting and comments
28
+
29
+ 2. **AST Mode (Precise)**: Pure abstract syntax tree transformation
30
+ - Deep understanding of code structure
31
+ - Best for complex transformations
32
+ - Preserves all code semantics
33
+
34
+ 3. **Regex Mode (Fast)**: Pattern-based matching
35
+ - Fastest for very large files
36
+ - Good for simple conversions
37
+ - Efficient memory usage
38
+
39
+ 4. **Auto Mode**: Automatically selects the best strategy based on file size
40
+
41
+ ### What Gets Converted?
42
+
43
+ | Original Code | Streamlit Equivalent |
44
+ |--------------|---------------------|
45
+ | `print(x)` | `st.write(x)` |
46
+ | `display(df)` | `st.dataframe(df)` |
47
+ | `df.head()` / `df.tail()` | `st.dataframe(df.head())` |
48
+ | `plt.show()` | `st.pyplot(plt.gcf())` |
49
+ | `fig.show()` (Plotly) | `st.plotly_chart(fig)` |
50
+ | Markdown cells | Commented markdown |
51
+ | All comments | Preserved |
52
+
53
+ ## πŸš€ Installation
54
+
55
+ 1. Clone or download this repository
56
+ 2. Install dependencies:
57
+
58
+ ```bash
59
+ pip install -r Requirements.txt
60
+ ```
61
+
62
+ ## πŸ“– Usage
63
+
64
+ ### Running the Application
65
+
66
+ ```bash
67
+ streamlit run app.py
68
+ ```
69
+
70
+ The application will open in your default web browser.
71
+
72
+ ### Basic Workflow
73
+
74
+ 1. **Upload Files**: Use the sidebar to upload Python files or Jupyter notebooks
75
+ - Individual files: Upload one or more files directly
76
+ - ZIP archive: Upload a ZIP containing multiple files
77
+
78
+ 2. **Configure Settings** (Optional):
79
+ - Choose conversion strategy (Hybrid recommended)
80
+ - Set large file threshold
81
+ - Enable/disable main guard
82
+ - Toggle comment preservation
83
+
84
+ 3. **Review & Download**:
85
+ - View original and converted code side-by-side
86
+ - Check conversion report for details
87
+ - Download the converted Streamlit app
88
+
89
+ ### Advanced Settings
90
+
91
+ - **Conversion Strategy**: Choose how the code is analyzed and converted
92
+ - **Large File Threshold**: Files above this size (in KB) use optimized processing
93
+ - **Main Guard**: Adds `if __name__ == '__main__':` wrapper for safer execution
94
+ - **Preserve Comments**: Keep all comments and docstrings in the output
95
+
96
+ ## 🎯 Use Cases
97
+
98
+ - **Data Science Projects**: Convert Jupyter notebooks with visualizations to interactive Streamlit dashboards
99
+ - **Script Migration**: Transform existing Python scripts into web applications
100
+ - **Batch Conversion**: Process entire project folders at once
101
+ - **Prototyping**: Quickly create Streamlit apps from existing code
102
+
103
+ ## πŸ”§ Technical Details
104
+
105
+ ### Architecture
106
+
107
+ - **AST-Based Transformation**: Uses Python's `ast` module for structural analysis
108
+ - **Regex Fallback**: Pattern matching for edge cases and large files
109
+ - **Hybrid Approach**: Combines both methods for optimal results
110
+ - **Error Recovery**: Graceful fallbacks when parsing fails
111
+
112
+ ### Performance
113
+
114
+ - Handles files up to 5MB+ efficiently
115
+ - Chunked processing for large files
116
+ - Caching for repeated conversions
117
+ - Memory-efficient algorithms
118
+
119
+ ### Limitations
120
+
121
+ - Does not execute code (safe conversion only)
122
+ - Complex interactive widgets (e.g., `ipywidgets`) require manual conversion
123
+ - Some edge cases in very complex code may need manual adjustment
124
+ - Manual review recommended before production deployment
125
+
126
+ ## πŸ“ Example
127
+
128
+ ### Input (Jupyter Notebook Cell):
129
+ ```python
130
+ import pandas as pd
131
+ import matplotlib.pyplot as plt
132
+
133
+ df = pd.read_csv('data.csv')
134
+ print(f"Dataset has {len(df)} rows")
135
+ display(df.head())
136
+
137
+ plt.figure(figsize=(10, 6))
138
+ plt.plot(df['x'], df['y'])
139
+ plt.show()
140
+ ```
141
+
142
+ ### Output (Streamlit App):
143
+ ```python
144
+ import streamlit as st
145
+ import pandas as pd
146
+ import matplotlib.pyplot as plt
147
+
148
+ st.set_page_config(
149
+ page_title='Converted App',
150
+ layout='wide'
151
+ )
152
+
153
+ st.title(' Converted Streamlit App')
154
+
155
+ df = pd.read_csv('data.csv')
156
+ st.write(f"Dataset has {len(df)} rows")
157
+ st.dataframe(df.head())
158
+
159
+ plt.figure(figsize=(10, 6))
160
+ plt.plot(df['x'], df['y'])
161
+ st.pyplot(plt.gcf())
162
+ ```
163
+
164
+ ## πŸ› οΈ Development
165
+
166
+ ### Project Structure
167
+ ```
168
+ python_to_full_streamlit/
169
+ β”œβ”€β”€ app.py # Main Streamlit application
170
+ β”œβ”€β”€ Requirements.txt # Python dependencies
171
+ └── README.md # This file
172
+ ```
173
+
174
+ ### Key Components
175
+
176
+ 1. **HybridConverter**: Main conversion engine with multiple strategies
177
+ 2. **CommentPreservingTransformer**: AST transformer that preserves code structure
178
+ 3. **extract_code_from_notebook**: Enhanced notebook processing with markdown support
179
+ 4. **File Processing**: Cached, efficient file handling with error recovery
180
+
181
+ ## 🀝 Contributing
182
+
183
+ This is a production-ready converter. Improvements welcome for:
184
+ - Additional conversion patterns
185
+ - Performance optimizations
186
+ - Edge case handling
187
+ - UI/UX enhancements
188
+
189
+ ## πŸ“„ License
190
+
191
+ This project is provided as-is for converting Python code to Streamlit applications.
192
+
193
+ ## πŸ’‘ Tips
194
+
195
+ - Use **Hybrid mode** for best results on most files
196
+ - Enable **comment preservation** to maintain documentation
197
+ - For very large files (>1MB), consider using **Regex mode**
198
+ - Always review converted code before deployment
199
+ - Test the generated Streamlit app with sample data
200
+
201
+ ## πŸ› Troubleshooting
202
+
203
+ **Issue**: Conversion fails on a file
204
+ - **Solution**: Try a different conversion mode (AST vs Regex)
205
+ - Check if the file has syntax errors
206
+ - Verify the file is valid Python/Jupyter format
207
+
208
+ **Issue**: Comments are missing
209
+ - **Solution**: Enable "Preserve Comments" in advanced settings
210
+ - Use AST or Hybrid mode instead of Regex
211
+
212
+ **Issue**: Large file processing is slow
213
+ - **Solution**: Increase the large file threshold
214
+ - Use Regex mode for very large files
215
+ - Process files individually instead of in ZIP
216
+
217
+ ---
218
+
219
+ **Made with ❀️ for the Streamlit community**