File size: 1,837 Bytes
aa5cda2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Data analysis page"""
import streamlit as st
from components import render_sidebar, display_analysis_results
from utils import client, get_analysis_types

st.set_page_config(page_title="Analysis", page_icon="πŸ“Š")
render_sidebar()

st.title("πŸ“Š Data Analysis")

if "uploaded_data" not in st.session_state or not st.session_state.uploaded_data:
    st.warning("⚠️ Please upload data first on the 'Upload Data' page")
    st.stop()

data = st.session_state.uploaded_data
columns = st.session_state.get("all_columns", [])

st.subheader("Analysis Settings")

col1, col2 = st.columns(2)
with col1:
    analysis_type = st.selectbox(
        "Analysis Type",
        get_analysis_types(),
        help="Choose the type of analysis to perform"
    )

with col2:
    selected_columns = st.multiselect(
        "Columns to Analyze",
        columns,
        default=columns[:3] if len(columns) > 3 else columns,
        help="Select which columns to analyze"
    )

st.divider()

if st.button("πŸ” Run Analysis", use_container_width=True):
    with st.spinner("πŸ“Š Analyzing data..."):
        result = client.analyze(data, analysis_type, selected_columns)
        
        if "error" in result:
            st.error(f"Analysis failed: {result['error']}")
        else:
            display_analysis_results(result)
            
            # Show suggestions
            if st.checkbox("πŸ’‘ Get AI Suggestions"):
                with st.spinner("πŸ€– Generating suggestions..."):
                    suggestions = client.get_suggestions(data, f"Analysis type: {analysis_type}")
                    if "suggestions" in suggestions:
                        st.subheader("πŸ’‘ Suggestions")
                        for i, suggestion in enumerate(suggestions["suggestions"], 1):
                            st.write(f"{i}. {suggestion}")