-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_components.py
More file actions
138 lines (110 loc) Β· 4.77 KB
/
Copy pathui_components.py
File metadata and controls
138 lines (110 loc) Β· 4.77 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""
UI component functions for the Autonomous ML Agent.
This module contains all functions responsible for creating and managing UI components.
"""
import streamlit as st
import pandas as pd
import numpy as np
import io
from typing import Dict, Any, Optional
def create_leaderboard_ui(model_results_df: pd.DataFrame, analysis_results: Optional[Dict[str, Any]] = None) -> None:
"""
Create a leaderboard UI showing model performance metrics.
Args:
model_results_df (pd.DataFrame): The model results dataframe
analysis_results (dict): LLM analysis results
"""
st.markdown("### π Model Leaderboard")
# Create columns for layout
col1, col2 = st.columns([2, 1])
with col1:
# Display model results as a formatted table
if not model_results_df.empty:
# Sort by best metric (assuming first numeric column is the main metric)
numeric_cols = model_results_df.select_dtypes(include=[np.number]).columns
if len(numeric_cols) > 0:
main_metric = numeric_cols[0]
model_results_df_sorted = model_results_df.sort_values(main_metric, ascending=False)
# Highlight the best model
st.dataframe(
model_results_df_sorted.style.highlight_max(axis=0, color='lightgreen'),
use_container_width=True
)
else:
st.dataframe(model_results_df, use_container_width=True)
else:
st.warning("No model results available")
with col2:
# Display best model info
if analysis_results and 'best_model' in analysis_results:
st.markdown("#### π₯ Best Model")
st.success(f"**{analysis_results['best_model']}**")
if 'best_score' in analysis_results:
st.metric("Best Score", f"{analysis_results['best_score']:.4f}")
# Display key metrics
if not model_results_df.empty:
st.markdown("#### π Key Metrics")
numeric_cols = model_results_df.select_dtypes(include=[np.number]).columns
for col in numeric_cols[:3]: # Show top 3 metrics
best_val = model_results_df[col].max()
best_model = model_results_df.loc[model_results_df[col].idxmax(), 'Model']
st.metric(f"Best {col}", f"{best_val:.4f}", f"({best_model})")
def display_model_analysis(analysis_results: Optional[Dict[str, Any]]) -> None:
"""
Display LLM-generated model analysis and insights.
Args:
analysis_results (dict): LLM analysis results
"""
if not analysis_results:
return
st.markdown("### π Model Analysis & Insights")
# Create tabs for different analysis sections
tab1, tab2, tab3, tab4 = st.tabs(["π Analysis", "π‘ Insights", "π Recommendations", "π Summary"])
with tab1:
if 'analysis' in analysis_results:
st.markdown("#### Detailed Performance Analysis")
st.write(analysis_results['analysis'])
with tab2:
if 'insights' in analysis_results:
st.markdown("#### Key Insights")
st.write(analysis_results['insights'])
with tab3:
if 'recommendations' in analysis_results:
st.markdown("#### Improvement Recommendations")
st.write(analysis_results['recommendations'])
with tab4:
if 'summary' in analysis_results:
st.markdown("#### Executive Summary")
st.info(analysis_results['summary'])
def display_cleaned_data(cleaned_bytes: bytes) -> pd.DataFrame:
"""
Display cleaned data and return as DataFrame.
Args:
cleaned_bytes (bytes): The cleaned CSV data as bytes
Returns:
pd.DataFrame: The cleaned dataframe
"""
# Handle both string and bytes from E2B files.read()
if isinstance(cleaned_bytes, str):
cleaned_df = pd.read_csv(io.StringIO(cleaned_bytes))
else:
cleaned_df = pd.read_csv(io.BytesIO(cleaned_bytes))
# Display the cleaned dataframe
st.write(cleaned_df)
return cleaned_df
def display_model_results(model_results_bytes: bytes) -> pd.DataFrame:
"""
Display model results and return as DataFrame.
Args:
model_results_bytes (bytes): The model results CSV data as bytes
Returns:
pd.DataFrame: The model results dataframe
"""
# Handle both string and bytes from E2B files.read()
if isinstance(model_results_bytes, str):
model_results_df = pd.read_csv(io.StringIO(model_results_bytes))
else:
model_results_df = pd.read_csv(io.BytesIO(model_results_bytes))
# Display the model results dataframe
st.write(model_results_df)
return model_results_df