Spaces:
Runtime error
Runtime error
Commit Β·
c3b2831
1
Parent(s): 7ee670b
Fix Gradio schema error - simplify to Interface API to avoid complex schema generation
Browse files173 unmodified lines1741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112126 unmodified lines219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341173 unmodified linesanalysis = preprocessor.analysissummary = f"""## β **Processing Complete!**### π **Dataset Information**- **Original Shape**: {df.shape}- **Processed Shape**: {processed_df.shape}- **Training Set**: {train_df.shape}- **Test Set**: {test_df.shape}### π **Column Analysis**- **π― Identifiers Removed**: {len(analysis['identifiers'])} columns- **π Text Features Removed**: {len(analysis['text_features'])} columns- **π Date Columns Processed**: {len(analysis['dates'])} columns- **π·οΈ Low Cardinality Encoded**: {len(analysis['categorical_low_cardinality'])} columns- **π² High Cardinality Dropped**: {len(analysis['categorical_high_cardinality'])} columns- **π’ Numeric Features**: {len(analysis['numeric'])} columns### ποΈ **Dropped Columns**{', '.join(analysis['identifiers'] + analysis['text_features'] + analysis['categorical_high_cardinality']) if analysis['identifiers'] + analysis['text_features'] + analysis['categorical_high_cardinality'] else 'None'}### π **Processing Steps Applied**1. β Identifier column detection and removal2. β Text feature detection and removal3. β Date feature extraction (year, month, day, weekday)4. β Missing value imputation5. β Categorical encoding (one-hot)6. β Numeric feature scaling7. β Low-variance feature removal8. β Train/test split (80/20)### π **Files Ready for Download**- Processed dataset (clean, ML-ready)- Training set (80% of data)- Test set (20% of data)"""# Convert DataFrames to CSV for download6 unmodified linesexcept Exception as e:return f"β Error: {str(e)}", None, None, None, None, f"β Processing failed: {str(e)}"# Create Gradio interfacewith gr.Blocks(title="PromptPrepML", theme=gr.themes.Base(), css=""".gradio-container {max-width: 1200px !important;margin: auto !important;}.gr-button {background: linear-gradient(45deg, #667eea 0%, #764ba2 100%) !important;border: none !important;color: white !important;font-weight: bold !important;padding: 12px 24px !important;border-radius: 8px !important;transition: all 0.3s ease !important;}.gr-button:hover {transform: translateY(-2px) !important;box-shadow: 0 8px 25px rgba(0,0,0,0.15) !important;}.gr-file {border: 2px dashed #667eea !important;border-radius: 12px !important;background: #f8f9ff !important;transition: all 0.3s ease !important;}.gr-file:hover {border-color: #764ba2 !important;background: #f0f2ff !important;}.gr-textbox {border-radius: 8px !important;border: 1px solid #e1e5e9 !important;}.gr-textbox:focus {border-color: #667eea !important;box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;}.gr-markdown {text-align: center !important;}.gr-dataframe {border-radius: 8px !important;overflow: hidden !important;}""") as demo:gr.Markdown("# π€ PromptPrepML")gr.Markdown("**AI-Powered Machine Learning Data Preprocessing Assistant**")gr.Markdown("Upload your dataset and get ML-ready results in seconds! π")with gr.Row():with gr.Column(scale=1):gr.Markdown("### π Upload Dataset")file_input = gr.File(label="Choose CSV file", file_types=[".csv"])gr.Markdown("### π¬ Processing Instructions")prompt_input = gr.Textbox(label="Describe your needs",value="Prepare this dataset for machine learning. Handle missing values, remove identifier columns, extract date features, encode categorical variables, and scale numeric features.",lines=4)process_btn = gr.Button("π Process Dataset", variant="primary", size="lg")with gr.Column(scale=2):gr.Markdown("### π Results")output_summary = gr.Markdown(label="Processing Summary")status_output = gr.Textbox(label="π Status", interactive=False)gr.Markdown("---")gr.Markdown("### π Dataset Preview")preview_output = gr.Dataframe(label="First 10 rows of processed dataset")gr.Markdown("---")gr.Markdown("### π₯ Download Files")with gr.Row():with gr.Column():processed_download = gr.File(label="π Processed Dataset")with gr.Column():train_download = gr.File(label="π Training Set")with gr.Column():test_download = gr.File(label="π§ͺ Test Set")# Event handlersprocess_btn.click(fn=process_dataset,inputs=[file_input, prompt_input],outputs=[output_summary, processed_download, train_download, test_download, preview_output, status_output])gr.Markdown("---")gr.Markdown("### π How to Use")with gr.Accordion("π Instructions", open=False):gr.Markdown("""1. **Upload your CSV dataset** (any size)2. **Describe your preprocessing needs** (or use default)3. **Click "Process Dataset"**4. **Download your ML-ready results**5. **Use for machine learning!**### π§ **Intelligent Features**- **Automatic identifier detection** and removal- **Smart date feature extraction**- **Text feature handling**- **Categorical encoding** for low-cardinality features- **High cardinality handling**- **Missing value imputation**- **Feature scaling**- **Train/test splitting**""")gr.Markdown("---")gr.Markdown("""<div style='text-align: center; color: #6b7280; margin-top: 2rem;'><p><strong>π€ PromptPrepML</strong> - Automated ML Data Preprocessing</p><p><small>Convert natural language prompts into ML-ready datasets</small></p></div>""")# Launch the appif __name__ == "__main__":demo.launch()173 unmodified lines1741751761771781791801811821831841851861871881891901911921931946 unmodified lines201202203204205206207208209210211212213214215216217218219220221222223224225226227228173 unmodified linesanalysis = preprocessor.analysissummary = f"""**β Processing Complete!****π Dataset Information**- Original Shape: {df.shape}- Processed Shape: {processed_df.shape}- Training Set: {train_df.shape}- Test Set: {test_df.shape}**π Column Analysis**- Identifiers Removed: {len(analysis['identifiers'])} columns- Text Features Removed: {len(analysis['text_features'])} columns- Date Columns Processed: {len(analysis['dates'])} columns- Low Cardinality Encoded: {len(analysis['categorical_low_cardinality'])} columns- High Cardinality Dropped: {len(analysis['categorical_high_cardinality'])} columns- Numeric Features: {len(analysis['numeric'])} columns"""# Convert DataFrames to CSV for download6 unmodified linesexcept Exception as e:return f"β Error: {str(e)}", None, None, None, None, f"β Processing failed: {str(e)}"# Create simple Gradio interfaceiface = gr.Interface(fn=process_dataset,inputs=[gr.File(label="Upload CSV Dataset", file_types=[".csv"]),gr.Textbox(label="Processing Instructions",value="Prepare this dataset for machine learning. Handle missing values, remove identifier columns, extract date features, encode categorical variables, and scale numeric features.",lines=3)],outputs=[gr.Markdown(label="Results Summary"),gr.File(label="Processed Dataset"),gr.File(label="Training Set"),gr.File(label="Test Set"),gr.Dataframe(label="Dataset Preview"),gr.Textbox(label="Status")],title="π€ PromptPrepML",description="AI-Powered Machine Learning Data Preprocessing Assistant",allow_flagging="never")# Launch the appif __name__ == "__main__":iface.launch()
app.py+37-150