import os import streamlit as st import pandas as pd from io import StringIO from util.evaluation import statistical_tests,calculate_correlations,calculate_divergences from util.plot import create_sector_plot import plotly.express as px def check_password(): def password_entered(): if password_input == os.getenv('PASSWORD'): st.session_state['password_correct'] = True else: st.error("Incorrect Password, please try again.") password_input = st.text_input("Enter Password:", type="password") submit_button = st.button("Submit", on_click=password_entered) if submit_button and not st.session_state.get('password_correct', False): st.error("Please enter a valid password to access the demo.") def app(): st.title('Result Evaluation') if not st.session_state.get('password_correct', False): check_password() else: st.sidebar.success("Password Verified. Proceed with the demo.") # Allow users to upload a CSV file with processed results uploaded_file = st.file_uploader("Upload your processed CSV file", type="csv") if uploaded_file is not None: data = StringIO(uploaded_file.getvalue().decode('utf-8')) df = pd.read_csv(data) st.write('Uploaded Data:', df) if st.button('Evaluate Data'): with st.spinner('Evaluating data...'): statistical_results = statistical_tests(df) correlation_results = calculate_correlations(df) #divergence_results = calculate_divergences(df) flat_statistical_results = {f"Statistical_{key1}": value1 for key1, value1 in statistical_results.items()} flat_correlation_results = {f"Correlation_{key1}": value1 for key1, value1 in correlation_results.items()} #flat_divergence_results = {f"Divergence_{key1}": value1 for key1, value1 in divergence_results.items()} results_combined = {**flat_statistical_results, **flat_correlation_results}#, **flat_divergence_results} results_df = pd.DataFrame(list(results_combined.items()), columns=['Metric', 'Value']) st.write('Combined Results:', results_df) fig_construction = create_sector_plot(df, df['Occupation'][0]) st.plotly_chart(fig_construction) # Additional plots st.subheader("Additional Plots") # Histogram of Scores st.write("Histogram of Scores") hist_fig = px.histogram(df.melt(id_vars=['Role'], value_vars=['Privilege_Avg_Score', 'Protect_Avg_Score', 'Neutral_Avg_Score']), x='value', color='variable', facet_col='variable', title='Distribution of Scores') st.plotly_chart(hist_fig) # Box Plot of Scores st.write("Box Plot of Scores") box_fig = px.box(df.melt(id_vars=['Role'], value_vars=['Privilege_Avg_Score', 'Protect_Avg_Score', 'Neutral_Avg_Score']), x='variable', y='value', color='variable', title='Spread of Scores') st.plotly_chart(box_fig) # Scatter Plot with Trend Line st.write("Scatter Plot with Trend Line") scatter_fig = px.scatter_matrix(df, dimensions=['Privilege_Avg_Score', 'Protect_Avg_Score', 'Neutral_Avg_Score'], title='Scatter Plot with Trend Line') st.plotly_chart(scatter_fig) # Heatmap of Correlations st.write("Heatmap of Correlations") corr_fig = px.imshow(df[['Privilege_Avg_Score', 'Protect_Avg_Score', 'Neutral_Avg_Score']].corr(), title='Correlation Heatmap') st.plotly_chart(corr_fig) st.download_button( label="Download Evaluation Results", data=results_df.to_csv(index=False).encode('utf-8'), file_name='evaluation_results.csv', mime='text/csv', ) if __name__ == "__main__": app()