Commit Β·
c3b2831
1
Parent(s): 7ee670b
Fix Gradio schema error - simplify to Interface API to avoid complex schema generation
Browse files
app.py
CHANGED
|
@@ -174,39 +174,21 @@ def process_dataset(file, prompt):
|
|
| 174 |
analysis = preprocessor.analysis
|
| 175 |
|
| 176 |
summary = f"""
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
-
|
| 181 |
-
-
|
| 182 |
-
-
|
| 183 |
-
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
-
|
| 187 |
-
-
|
| 188 |
-
-
|
| 189 |
-
-
|
| 190 |
-
-
|
| 191 |
-
-
|
| 192 |
-
|
| 193 |
-
### ποΈ **Dropped Columns**
|
| 194 |
-
{', '.join(analysis['identifiers'] + analysis['text_features'] + analysis['categorical_high_cardinality']) if analysis['identifiers'] + analysis['text_features'] + analysis['categorical_high_cardinality'] else 'None'}
|
| 195 |
-
|
| 196 |
-
### π **Processing Steps Applied**
|
| 197 |
-
1. β
Identifier column detection and removal
|
| 198 |
-
2. β
Text feature detection and removal
|
| 199 |
-
3. β
Date feature extraction (year, month, day, weekday)
|
| 200 |
-
4. β
Missing value imputation
|
| 201 |
-
5. β
Categorical encoding (one-hot)
|
| 202 |
-
6. β
Numeric feature scaling
|
| 203 |
-
7. β
Low-variance feature removal
|
| 204 |
-
8. β
Train/test split (80/20)
|
| 205 |
-
|
| 206 |
-
### π **Files Ready for Download**
|
| 207 |
-
- Processed dataset (clean, ML-ready)
|
| 208 |
-
- Training set (80% of data)
|
| 209 |
-
- Test set (20% of data)
|
| 210 |
"""
|
| 211 |
|
| 212 |
# Convert DataFrames to CSV for download
|
|
@@ -219,123 +201,28 @@ def process_dataset(file, prompt):
|
|
| 219 |
except Exception as e:
|
| 220 |
return f"β Error: {str(e)}", None, None, None, None, f"β Processing failed: {str(e)}"
|
| 221 |
|
| 222 |
-
# Create Gradio interface
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
border-radius: 12px !important;
|
| 244 |
-
background: #f8f9ff !important;
|
| 245 |
-
transition: all 0.3s ease !important;
|
| 246 |
-
}
|
| 247 |
-
.gr-file:hover {
|
| 248 |
-
border-color: #764ba2 !important;
|
| 249 |
-
background: #f0f2ff !important;
|
| 250 |
-
}
|
| 251 |
-
.gr-textbox {
|
| 252 |
-
border-radius: 8px !important;
|
| 253 |
-
border: 1px solid #e1e5e9 !important;
|
| 254 |
-
}
|
| 255 |
-
.gr-textbox:focus {
|
| 256 |
-
border-color: #667eea !important;
|
| 257 |
-
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
|
| 258 |
-
}
|
| 259 |
-
.gr-markdown {
|
| 260 |
-
text-align: center !important;
|
| 261 |
-
}
|
| 262 |
-
.gr-dataframe {
|
| 263 |
-
border-radius: 8px !important;
|
| 264 |
-
overflow: hidden !important;
|
| 265 |
-
}
|
| 266 |
-
""") as demo:
|
| 267 |
-
gr.Markdown("# π€ PromptPrepML")
|
| 268 |
-
gr.Markdown("**AI-Powered Machine Learning Data Preprocessing Assistant**")
|
| 269 |
-
gr.Markdown("Upload your dataset and get ML-ready results in seconds! π")
|
| 270 |
-
|
| 271 |
-
with gr.Row():
|
| 272 |
-
with gr.Column(scale=1):
|
| 273 |
-
gr.Markdown("### π Upload Dataset")
|
| 274 |
-
file_input = gr.File(label="Choose CSV file", file_types=[".csv"])
|
| 275 |
-
|
| 276 |
-
gr.Markdown("### π¬ Processing Instructions")
|
| 277 |
-
prompt_input = gr.Textbox(
|
| 278 |
-
label="Describe your needs",
|
| 279 |
-
value="Prepare this dataset for machine learning. Handle missing values, remove identifier columns, extract date features, encode categorical variables, and scale numeric features.",
|
| 280 |
-
lines=4
|
| 281 |
-
)
|
| 282 |
-
process_btn = gr.Button("π Process Dataset", variant="primary", size="lg")
|
| 283 |
-
|
| 284 |
-
with gr.Column(scale=2):
|
| 285 |
-
gr.Markdown("### π Results")
|
| 286 |
-
output_summary = gr.Markdown(label="Processing Summary")
|
| 287 |
-
status_output = gr.Textbox(label="π Status", interactive=False)
|
| 288 |
-
|
| 289 |
-
gr.Markdown("---")
|
| 290 |
-
gr.Markdown("### π Dataset Preview")
|
| 291 |
-
preview_output = gr.Dataframe(label="First 10 rows of processed dataset")
|
| 292 |
-
|
| 293 |
-
gr.Markdown("---")
|
| 294 |
-
gr.Markdown("### π₯ Download Files")
|
| 295 |
-
with gr.Row():
|
| 296 |
-
with gr.Column():
|
| 297 |
-
processed_download = gr.File(label="π Processed Dataset")
|
| 298 |
-
with gr.Column():
|
| 299 |
-
train_download = gr.File(label="π Training Set")
|
| 300 |
-
with gr.Column():
|
| 301 |
-
test_download = gr.File(label="π§ͺ Test Set")
|
| 302 |
-
|
| 303 |
-
# Event handlers
|
| 304 |
-
process_btn.click(
|
| 305 |
-
fn=process_dataset,
|
| 306 |
-
inputs=[file_input, prompt_input],
|
| 307 |
-
outputs=[output_summary, processed_download, train_download, test_download, preview_output, status_output]
|
| 308 |
-
)
|
| 309 |
-
|
| 310 |
-
gr.Markdown("---")
|
| 311 |
-
gr.Markdown("### π How to Use")
|
| 312 |
-
with gr.Accordion("π Instructions", open=False):
|
| 313 |
-
gr.Markdown("""
|
| 314 |
-
1. **Upload your CSV dataset** (any size)
|
| 315 |
-
2. **Describe your preprocessing needs** (or use default)
|
| 316 |
-
3. **Click "Process Dataset"**
|
| 317 |
-
4. **Download your ML-ready results**
|
| 318 |
-
5. **Use for machine learning!**
|
| 319 |
-
|
| 320 |
-
### π§ **Intelligent Features**
|
| 321 |
-
- **Automatic identifier detection** and removal
|
| 322 |
-
- **Smart date feature extraction**
|
| 323 |
-
- **Text feature handling**
|
| 324 |
-
- **Categorical encoding** for low-cardinality features
|
| 325 |
-
- **High cardinality handling**
|
| 326 |
-
- **Missing value imputation**
|
| 327 |
-
- **Feature scaling**
|
| 328 |
-
- **Train/test splitting**
|
| 329 |
-
""")
|
| 330 |
-
|
| 331 |
-
gr.Markdown("---")
|
| 332 |
-
gr.Markdown("""
|
| 333 |
-
<div style='text-align: center; color: #6b7280; margin-top: 2rem;'>
|
| 334 |
-
<p><strong>π€ PromptPrepML</strong> - Automated ML Data Preprocessing</p>
|
| 335 |
-
<p><small>Convert natural language prompts into ML-ready datasets</small></p>
|
| 336 |
-
</div>
|
| 337 |
-
""")
|
| 338 |
|
| 339 |
# Launch the app
|
| 340 |
if __name__ == "__main__":
|
| 341 |
-
|
|
|
|
| 174 |
analysis = preprocessor.analysis
|
| 175 |
|
| 176 |
summary = f"""
|
| 177 |
+
**β
Processing Complete!**
|
| 178 |
+
|
| 179 |
+
**π Dataset Information**
|
| 180 |
+
- Original Shape: {df.shape}
|
| 181 |
+
- Processed Shape: {processed_df.shape}
|
| 182 |
+
- Training Set: {train_df.shape}
|
| 183 |
+
- Test Set: {test_df.shape}
|
| 184 |
+
|
| 185 |
+
**π Column Analysis**
|
| 186 |
+
- Identifiers Removed: {len(analysis['identifiers'])} columns
|
| 187 |
+
- Text Features Removed: {len(analysis['text_features'])} columns
|
| 188 |
+
- Date Columns Processed: {len(analysis['dates'])} columns
|
| 189 |
+
- Low Cardinality Encoded: {len(analysis['categorical_low_cardinality'])} columns
|
| 190 |
+
- High Cardinality Dropped: {len(analysis['categorical_high_cardinality'])} columns
|
| 191 |
+
- Numeric Features: {len(analysis['numeric'])} columns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
"""
|
| 193 |
|
| 194 |
# Convert DataFrames to CSV for download
|
|
|
|
| 201 |
except Exception as e:
|
| 202 |
return f"β Error: {str(e)}", None, None, None, None, f"β Processing failed: {str(e)}"
|
| 203 |
|
| 204 |
+
# Create simple Gradio interface
|
| 205 |
+
iface = gr.Interface(
|
| 206 |
+
fn=process_dataset,
|
| 207 |
+
inputs=[
|
| 208 |
+
gr.File(label="Upload CSV Dataset", file_types=[".csv"]),
|
| 209 |
+
gr.Textbox(label="Processing Instructions",
|
| 210 |
+
value="Prepare this dataset for machine learning. Handle missing values, remove identifier columns, extract date features, encode categorical variables, and scale numeric features.",
|
| 211 |
+
lines=3)
|
| 212 |
+
],
|
| 213 |
+
outputs=[
|
| 214 |
+
gr.Markdown(label="Results Summary"),
|
| 215 |
+
gr.File(label="Processed Dataset"),
|
| 216 |
+
gr.File(label="Training Set"),
|
| 217 |
+
gr.File(label="Test Set"),
|
| 218 |
+
gr.Dataframe(label="Dataset Preview"),
|
| 219 |
+
gr.Textbox(label="Status")
|
| 220 |
+
],
|
| 221 |
+
title="π€ PromptPrepML",
|
| 222 |
+
description="AI-Powered Machine Learning Data Preprocessing Assistant",
|
| 223 |
+
allow_flagging="never"
|
| 224 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
# Launch the app
|
| 227 |
if __name__ == "__main__":
|
| 228 |
+
iface.launch()
|