Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,7 @@ import requests
|
|
20 |
import asyncio
|
21 |
from io import BytesIO
|
22 |
import base64
|
|
|
23 |
|
24 |
# Configuration
|
25 |
st.set_page_config(page_title="Data Wizard Pro", layout="wide", page_icon="π§")
|
@@ -545,102 +546,221 @@ elif app_mode == "Advanced EDA":
|
|
545 |
if st.session_state.cleaned_data is not None:
|
546 |
df = st.session_state.cleaned_data
|
547 |
|
548 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
549 |
with st.expander("π Data Filtering", expanded=False):
|
550 |
-
filter_col = st.selectbox(
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
555 |
|
556 |
# Visualization Selection and Configuration
|
557 |
-
st.sidebar.header("π Plot Configuration")
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
"
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
"
|
568 |
-
|
569 |
-
|
570 |
-
x_col = None # Initialize x_col
|
571 |
-
y_col = None # Initialize y_col
|
572 |
-
z_col = None # Initialize z_col
|
573 |
-
color_col = "#FF6347" # Intialize color column
|
574 |
-
size_col = None # Initailize size column
|
575 |
-
time_col = None
|
576 |
-
value_col = None
|
577 |
-
scatter_matrix_cols = None
|
578 |
-
color_palette = ["#FF6347", "#4682B4", "#32CD32", "#FFD700"]
|
579 |
-
|
580 |
-
|
581 |
-
if plot_type != "Correlation Heatmap":
|
582 |
-
x_col = st.sidebar.selectbox("X Axis", df.columns, help="Select the column for the x-axis.")
|
583 |
-
|
584 |
-
if plot_type in ["Scatter Plot", "Box Plot", "Violin Plot", "Time Series", "3D Scatter", "Histogram"]:
|
585 |
-
y_col = st.sidebar.selectbox("Y Axis", df.columns, help="Select the column for the y-axis.")
|
586 |
-
|
587 |
-
if plot_type == "3D Scatter":
|
588 |
-
z_col = st.sidebar.selectbox("Z Axis", df.columns, help="Select the column for the z-axis.")
|
589 |
-
color_col = st.sidebar.selectbox("Color by", [None] + list(df.columns), help="Optional column to color the data points.")
|
590 |
-
|
591 |
-
# Add a parameter for Color Scales in Heatmap (and make palette choice for other plots)
|
592 |
-
if plot_type == "Correlation Heatmap":
|
593 |
-
color_continuous_scale = st.sidebar.selectbox("Color Scale", ['Viridis', 'Plasma', 'Magma', 'Cividis', 'RdBu'], help="Select the color scale for the heatmap.")
|
594 |
-
else:
|
595 |
-
color_palette = st.sidebar.selectbox("Color Palette", ['#00f7ff', '#ff00ff', '#f70000', '#0000f7'], help="Select the color for the plot.")
|
596 |
-
|
597 |
-
if plot_type == "Scatter Plot":
|
598 |
-
size_col = st.sidebar.selectbox("Size by", [None] + list(df.columns), help="Optional column to size the data points.")
|
599 |
-
hover_data_cols = st.sidebar.multiselect("Hover Data", df.columns, help="Optional columns to display on hover.")
|
600 |
-
|
601 |
-
if plot_type == "Time Series":
|
602 |
-
time_col = st.sidebar.selectbox("Time Column", df.columns, help="Column representing time.")
|
603 |
-
value_col = st.sidebar.selectbox("Value Column", df.columns, help="Column representing the value to plot over time.")
|
604 |
-
|
605 |
-
if plot_type == "Scatter Matrix":
|
606 |
-
scatter_matrix_cols = st.multiselect("Columns for Scatter Matrix", df.columns, default=df.columns.tolist()[:5], help="Select the columns to include in the scatter matrix.")
|
607 |
-
|
608 |
-
# Generate Plot
|
609 |
-
if st.button("Generate Visualization"):
|
610 |
-
try: # add try-except block for potential errors
|
611 |
-
fig = None # Initialize fig
|
612 |
-
if plot_type == "Histogram":
|
613 |
-
fig = px.histogram(df, x=x_col, y=y_col, nbins=30, template="plotly_dark", color_discrete_sequence=[color_palette])
|
614 |
-
elif plot_type == "Scatter Plot":
|
615 |
-
fig = px.scatter(df, x=x_col, y=y_col, color_discrete_sequence=[color_palette], size=size_col, hover_data=hover_data_cols)
|
616 |
-
elif plot_type == "3D Scatter":
|
617 |
-
fig = px.scatter_3d(df, x=x_col, y=y_col, z=z_col, color=color_col, color_discrete_sequence=[color_palette])
|
618 |
-
elif plot_type == "Correlation Heatmap":
|
619 |
-
corr = df.corr(numeric_only=True) #handle non-numeric cols
|
620 |
-
fig = px.imshow(corr, text_auto=True, color_continuous_scale=color_continuous_scale)
|
621 |
-
elif plot_type == "Box Plot":
|
622 |
-
fig = px.box(df,x=x_col, y=y_col, color_discrete_sequence=[color_palette])
|
623 |
-
elif plot_type == "Violin Plot":
|
624 |
-
fig = px.violin(df, x=x_col, y=y_col, color_discrete_sequence=[color_palette])
|
625 |
-
elif plot_type == "Time Series":
|
626 |
-
fig = px.line(df, x=time_col, y=value_col, color_discrete_sequence=[color_palette])
|
627 |
-
elif plot_type == "Scatter Matrix":
|
628 |
-
if len(scatter_matrix_cols) > 1:
|
629 |
-
fig = px.scatter_matrix(df[scatter_matrix_cols], color_discrete_sequence=[color_palette])
|
630 |
-
else:
|
631 |
-
st.error("Please select at least two columns for the scatter matrix.")
|
632 |
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
638 |
)
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
643 |
|
|
|
|
|
|
|
644 |
elif app_mode == "Model Training":
|
645 |
st.title("π€ Model Training Studio")
|
646 |
|
|
|
20 |
import asyncio
|
21 |
from io import BytesIO
|
22 |
import base64
|
23 |
+
import time
|
24 |
|
25 |
# Configuration
|
26 |
st.set_page_config(page_title="Data Wizard Pro", layout="wide", page_icon="π§")
|
|
|
546 |
if st.session_state.cleaned_data is not None:
|
547 |
df = st.session_state.cleaned_data
|
548 |
|
549 |
+
# Initialize session state for plot configuration
|
550 |
+
if 'plot_config' not in st.session_state:
|
551 |
+
st.session_state.plot_config = {
|
552 |
+
'plot_type': "Histogram",
|
553 |
+
'x_col': None,
|
554 |
+
'y_col': None,
|
555 |
+
'z_col': None,
|
556 |
+
'color_col': None,
|
557 |
+
'size_col': None,
|
558 |
+
'time_col': None,
|
559 |
+
'value_col': None,
|
560 |
+
'scatter_matrix_cols': None,
|
561 |
+
'color_palette': "#00f7ff",
|
562 |
+
'color_continuous_scale': "Viridis",
|
563 |
+
'hover_data_cols': [],
|
564 |
+
'filter_col': None,
|
565 |
+
'filter_options': []
|
566 |
+
}
|
567 |
+
|
568 |
+
# Data Filtering Section
|
569 |
with st.expander("π Data Filtering", expanded=False):
|
570 |
+
filter_col = st.selectbox(
|
571 |
+
"Filter Column",
|
572 |
+
[None] + list(df.columns),
|
573 |
+
key='filter_col',
|
574 |
+
help="Choose a column to filter the data."
|
575 |
+
)
|
576 |
+
if st.session_state.plot_config['filter_col']:
|
577 |
+
unique_values = df[st.session_state.plot_config['filter_col']].unique()
|
578 |
+
filter_options = st.multiselect(
|
579 |
+
"Filter Values",
|
580 |
+
unique_values,
|
581 |
+
default=unique_values,
|
582 |
+
key='filter_options',
|
583 |
+
help=f"Select the values to include from the '{st.session_state.plot_config['filter_col']}' column."
|
584 |
+
)
|
585 |
+
df = df[df[st.session_state.plot_config['filter_col']].isin(st.session_state.plot_config['filter_options'])]
|
586 |
|
587 |
# Visualization Selection and Configuration
|
588 |
+
st.sidebar.header("π Plot Configuration")
|
589 |
+
|
590 |
+
# Plot type selection
|
591 |
+
plot_type = st.sidebar.selectbox(
|
592 |
+
"Choose Visualization",
|
593 |
+
[
|
594 |
+
"Histogram", "Scatter Plot", "Box Plot", "Correlation Heatmap",
|
595 |
+
"3D Scatter", "Violin Plot", "Time Series", "Scatter Matrix"
|
596 |
+
],
|
597 |
+
key='plot_type',
|
598 |
+
help="Select the type of plot to generate."
|
599 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
|
601 |
+
# Dynamic axis and configuration options
|
602 |
+
if st.session_state.plot_config['plot_type'] != "Correlation Heatmap":
|
603 |
+
x_col = st.sidebar.selectbox(
|
604 |
+
"X Axis",
|
605 |
+
df.columns,
|
606 |
+
key='x_col',
|
607 |
+
help="Select the column for the x-axis."
|
608 |
+
)
|
609 |
+
|
610 |
+
if st.session_state.plot_config['plot_type'] in ["Scatter Plot", "Box Plot", "Violin Plot", "Time Series", "3D Scatter", "Histogram"]:
|
611 |
+
y_col = st.sidebar.selectbox(
|
612 |
+
"Y Axis",
|
613 |
+
df.columns,
|
614 |
+
key='y_col',
|
615 |
+
help="Select the column for the y-axis."
|
616 |
+
)
|
617 |
+
|
618 |
+
if st.session_state.plot_config['plot_type'] == "3D Scatter":
|
619 |
+
z_col = st.sidebar.selectbox(
|
620 |
+
"Z Axis",
|
621 |
+
df.columns,
|
622 |
+
key='z_col',
|
623 |
+
help="Select the column for the z-axis."
|
624 |
+
)
|
625 |
+
color_col = st.sidebar.selectbox(
|
626 |
+
"Color by",
|
627 |
+
[None] + list(df.columns),
|
628 |
+
key='color_col',
|
629 |
+
help="Optional column to color the data points."
|
630 |
+
)
|
631 |
+
|
632 |
+
# Color configuration
|
633 |
+
if st.session_state.plot_config['plot_type'] == "Correlation Heatmap":
|
634 |
+
color_continuous_scale = st.sidebar.selectbox(
|
635 |
+
"Color Scale",
|
636 |
+
['Viridis', 'Plasma', 'Magma', 'Cividis', 'RdBu'],
|
637 |
+
key='color_continuous_scale',
|
638 |
+
help="Select the color scale for the heatmap."
|
639 |
+
)
|
640 |
+
else:
|
641 |
+
color_palette = st.sidebar.selectbox(
|
642 |
+
"Color Palette",
|
643 |
+
['#00f7ff', '#ff00ff', '#f70000', '#0000f7'],
|
644 |
+
key='color_palette',
|
645 |
+
help="Select the color for the plot."
|
646 |
+
)
|
647 |
+
|
648 |
+
# Additional plot-specific configurations
|
649 |
+
if st.session_state.plot_config['plot_type'] == "Scatter Plot":
|
650 |
+
size_col = st.sidebar.selectbox(
|
651 |
+
"Size by",
|
652 |
+
[None] + list(df.columns),
|
653 |
+
key='size_col',
|
654 |
+
help="Optional column to size the data points."
|
655 |
+
)
|
656 |
+
hover_data_cols = st.sidebar.multiselect(
|
657 |
+
"Hover Data",
|
658 |
+
df.columns,
|
659 |
+
key='hover_data_cols',
|
660 |
+
help="Optional columns to display on hover."
|
661 |
+
)
|
662 |
+
|
663 |
+
if st.session_state.plot_config['plot_type'] == "Time Series":
|
664 |
+
time_col = st.sidebar.selectbox(
|
665 |
+
"Time Column",
|
666 |
+
df.columns,
|
667 |
+
key='time_col',
|
668 |
+
help="Column representing time."
|
669 |
+
)
|
670 |
+
value_col = st.sidebar.selectbox(
|
671 |
+
"Value Column",
|
672 |
+
df.columns,
|
673 |
+
key='value_col',
|
674 |
+
help="Column representing the value to plot over time."
|
675 |
+
)
|
676 |
+
|
677 |
+
if st.session_state.plot_config['plot_type'] == "Scatter Matrix":
|
678 |
+
scatter_matrix_cols = st.multiselect(
|
679 |
+
"Columns for Scatter Matrix",
|
680 |
+
df.columns,
|
681 |
+
default=df.columns.tolist()[:5],
|
682 |
+
key='scatter_matrix_cols',
|
683 |
+
help="Select the columns to include in the scatter matrix."
|
684 |
+
)
|
685 |
+
|
686 |
+
# Generate and update plot in real-time
|
687 |
+
try:
|
688 |
+
fig = None
|
689 |
+
if st.session_state.plot_config['plot_type'] == "Histogram":
|
690 |
+
fig = px.histogram(
|
691 |
+
df,
|
692 |
+
x=st.session_state.plot_config['x_col'],
|
693 |
+
y=st.session_state.plot_config['y_col'],
|
694 |
+
nbins=30,
|
695 |
+
template="plotly_dark",
|
696 |
+
color_discrete_sequence=[st.session_state.plot_config['color_palette']]
|
697 |
+
)
|
698 |
+
elif st.session_state.plot_config['plot_type'] == "Scatter Plot":
|
699 |
+
fig = px.scatter(
|
700 |
+
df,
|
701 |
+
x=st.session_state.plot_config['x_col'],
|
702 |
+
y=st.session_state.plot_config['y_col'],
|
703 |
+
color_discrete_sequence=[st.session_state.plot_config['color_palette']],
|
704 |
+
size=st.session_state.plot_config['size_col'],
|
705 |
+
hover_data=st.session_state.plot_config['hover_data_cols']
|
706 |
+
)
|
707 |
+
elif st.session_state.plot_config['plot_type'] == "3D Scatter":
|
708 |
+
fig = px.scatter_3d(
|
709 |
+
df,
|
710 |
+
x=st.session_state.plot_config['x_col'],
|
711 |
+
y=st.session_state.plot_config['y_col'],
|
712 |
+
z=st.session_state.plot_config['z_col'],
|
713 |
+
color=st.session_state.plot_config['color_col'],
|
714 |
+
color_discrete_sequence=[st.session_state.plot_config['color_palette']]
|
715 |
+
)
|
716 |
+
elif st.session_state.plot_config['plot_type'] == "Correlation Heatmap":
|
717 |
+
corr = df.corr(numeric_only=True)
|
718 |
+
fig = px.imshow(
|
719 |
+
corr,
|
720 |
+
text_auto=True,
|
721 |
+
color_continuous_scale=st.session_state.plot_config['color_continuous_scale']
|
722 |
+
)
|
723 |
+
elif st.session_state.plot_config['plot_type'] == "Box Plot":
|
724 |
+
fig = px.box(
|
725 |
+
df,
|
726 |
+
x=st.session_state.plot_config['x_col'],
|
727 |
+
y=st.session_state.plot_config['y_col'],
|
728 |
+
color_discrete_sequence=[st.session_state.plot_config['color_palette']]
|
729 |
+
)
|
730 |
+
elif st.session_state.plot_config['plot_type'] == "Violin Plot":
|
731 |
+
fig = px.violin(
|
732 |
+
df,
|
733 |
+
x=st.session_state.plot_config['x_col'],
|
734 |
+
y=st.session_state.plot_config['y_col'],
|
735 |
+
color_discrete_sequence=[st.session_state.plot_config['color_palette']]
|
736 |
+
)
|
737 |
+
elif st.session_state.plot_config['plot_type'] == "Time Series":
|
738 |
+
fig = px.line(
|
739 |
+
df,
|
740 |
+
x=st.session_state.plot_config['time_col'],
|
741 |
+
y=st.session_state.plot_config['value_col'],
|
742 |
+
color_discrete_sequence=[st.session_state.plot_config['color_palette']]
|
743 |
+
)
|
744 |
+
elif st.session_state.plot_config['plot_type'] == "Scatter Matrix":
|
745 |
+
if len(st.session_state.plot_config['scatter_matrix_cols']) > 1:
|
746 |
+
fig = px.scatter_matrix(
|
747 |
+
df[st.session_state.plot_config['scatter_matrix_cols']],
|
748 |
+
color_discrete_sequence=[st.session_state.plot_config['color_palette']]
|
749 |
)
|
750 |
+
else:
|
751 |
+
st.error("Please select at least two columns for the scatter matrix.")
|
752 |
+
|
753 |
+
if fig:
|
754 |
+
fig.update_layout(
|
755 |
+
plot_bgcolor="#1e1e30",
|
756 |
+
paper_bgcolor="#1e1e30",
|
757 |
+
font_color="#e0e0ff"
|
758 |
+
)
|
759 |
+
st.plotly_chart(fig, use_container_width=True)
|
760 |
|
761 |
+
except Exception as e:
|
762 |
+
st.error(f"Error generating plot: {e}")
|
763 |
+
|
764 |
elif app_mode == "Model Training":
|
765 |
st.title("π€ Model Training Studio")
|
766 |
|