Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import icc # Importing ICC computation functions
|
4 |
+
|
5 |
+
# Set up Streamlit page layout (Full Width)
|
6 |
+
st.set_page_config(layout="wide", page_title="ICC Computation App", page_icon="π")
|
7 |
+
|
8 |
+
# Title and instructions
|
9 |
+
st.title("π ICC Computation App")
|
10 |
+
st.markdown("Upload a **CSV file** containing LLM evaluation scores and compute **Intraclass Correlation Coefficients (ICC)**.")
|
11 |
+
|
12 |
+
# **Two Side-by-Side Containers**
|
13 |
+
container_left, container_right = st.columns([1, 2]) # Left (Filters) | Right (ICC Results + Heatmaps)
|
14 |
+
|
15 |
+
# **LEFT: File Upload & Selection Filters**
|
16 |
+
with container_left:
|
17 |
+
st.header("π Upload & Selection")
|
18 |
+
|
19 |
+
# File uploader
|
20 |
+
uploaded_file = st.file_uploader("Upload Your CSV", type=["csv"])
|
21 |
+
|
22 |
+
if uploaded_file is not None:
|
23 |
+
df = pd.read_csv(uploaded_file, delimiter=",", dtype=str) # Read as string first
|
24 |
+
|
25 |
+
required_columns = ["assessor", "respondent"]
|
26 |
+
criterion_columns = [col for col in df.columns if col.startswith("criterion")]
|
27 |
+
|
28 |
+
if not all(col in df.columns for col in required_columns) or len(criterion_columns) < 1:
|
29 |
+
st.error("β Invalid CSV format.")
|
30 |
+
else:
|
31 |
+
st.success("β
CSV format is valid!")
|
32 |
+
|
33 |
+
# Sidebar filters
|
34 |
+
st.subheader("π Select Filters")
|
35 |
+
|
36 |
+
# Extract Unique Options
|
37 |
+
all_assessors = sorted(df["assessor"].unique())
|
38 |
+
all_respondents = sorted(df["respondent"].unique())
|
39 |
+
all_criteria = criterion_columns
|
40 |
+
|
41 |
+
# **Assessors Selection with 'Select All'**
|
42 |
+
select_all_assessors = st.checkbox("Select All Assessors", value=True)
|
43 |
+
selected_assessors = st.multiselect(
|
44 |
+
"Select Assessors", all_assessors, default=all_assessors if select_all_assessors else []
|
45 |
+
)
|
46 |
+
|
47 |
+
# **Respondents Selection with 'Select All'**
|
48 |
+
select_all_respondents = st.checkbox("Select All Respondents", value=True)
|
49 |
+
selected_respondents = st.multiselect(
|
50 |
+
"Select Respondents", all_respondents, default=all_respondents if select_all_respondents else []
|
51 |
+
)
|
52 |
+
|
53 |
+
# **Criteria Selection with 'Select All'**
|
54 |
+
select_all_criteria = st.checkbox("Select All Criteria", value=True)
|
55 |
+
selected_criteria = st.multiselect(
|
56 |
+
"Select Criteria", all_criteria, default=all_criteria if select_all_criteria else []
|
57 |
+
)
|
58 |
+
|
59 |
+
def reset_filters():
|
60 |
+
"""Resets selections to all available options."""
|
61 |
+
st.session_state["selected_assessors"] = all_assessors
|
62 |
+
st.session_state["selected_respondents"] = all_respondents
|
63 |
+
st.session_state["selected_criteria"] = all_criteria
|
64 |
+
|
65 |
+
# Reset All Button
|
66 |
+
if st.button("π Reset All Selections"):
|
67 |
+
reset_filters()
|
68 |
+
|
69 |
+
# Filter data based on user selection
|
70 |
+
df = icc.preprocess_data(df, selected_assessors, selected_respondents, selected_criteria)
|
71 |
+
|
72 |
+
if df.empty:
|
73 |
+
st.error("β οΈ No data available with selected filters.")
|
74 |
+
|
75 |
+
# **RIGHT: Display ICC Results + Heatmaps**
|
76 |
+
with container_right:
|
77 |
+
st.header("π ICC Results & Heatmaps")
|
78 |
+
|
79 |
+
if uploaded_file is not None and not df.empty:
|
80 |
+
with st.spinner("β³ Computing ICC... Please wait."):
|
81 |
+
icc_results = icc.compute_icc(df)
|
82 |
+
|
83 |
+
if icc_results is not None:
|
84 |
+
st.subheader("π Overall ICC Results")
|
85 |
+
st.dataframe(icc_results, use_container_width=True) # Display ICC table
|
86 |
+
else:
|
87 |
+
st.warning("β οΈ Not enough respondents to compute ICC.")
|
88 |
+
|
89 |
+
# **HEATMAPS: Display Below in 3 Columns**
|
90 |
+
st.subheader("π₯ ICC Heatmaps (Assessor Agreement)")
|
91 |
+
heatmap_cols = st.columns(3) # 3-column layout for heatmaps
|
92 |
+
|
93 |
+
# Compute assessor ICC
|
94 |
+
icc_matrix_types = icc.compute_assessor_icc(df)
|
95 |
+
|
96 |
+
# Generate heatmaps and display
|
97 |
+
heatmap_files = icc.generate_heatmaps(icc_matrix_types)
|
98 |
+
|
99 |
+
for i, (icc_type, heatmap_file) in enumerate(heatmap_files.items()):
|
100 |
+
heatmap_cols[i].image(heatmap_file, caption=f"ICC Heatmap ({icc_type})", use_container_width=True)
|
101 |
+
|