Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import pandas as pd | |
| import seaborn as sns | |
| import matplotlib.pyplot as plt | |
| from io import StringIO | |
| def upload_csv(csv_file): | |
| data = pd.read_csv(csv_file.name) | |
| analysis_results = analyze_data(data) | |
| return analysis_results | |
| def create_histogram(data, column, ax): | |
| sorted_data = data[column].value_counts().sort_index() | |
| sorted_data.plot(kind='bar', color='#007ACC', ax=ax) | |
| ax.set_title(f"{column} Distribution") | |
| ax.set_xlabel(column) | |
| ax.set_ylabel("Frequency") | |
| def calculate_points(data): | |
| points = data.copy() | |
| points.iloc[:, ::2] -= 1 | |
| points.iloc[:, 1::2] = 5 - points.iloc[:, 1::2] | |
| return points | |
| def calculate_sus_score(points): | |
| total_points = points.sum(axis=1) | |
| user_scores = total_points * 2.5 | |
| sus_score = user_scores.mean() | |
| return sus_score, user_scores | |
| def analyze_data(data): | |
| # Remove timestamp column | |
| data = data.drop(columns=['Timestamp']) | |
| # Calculate points | |
| points = calculate_points(data) | |
| # Calculate SUS score and individual user scores | |
| sus_score, user_scores = calculate_sus_score(points) | |
| user_scores_table = pd.DataFrame(user_scores, columns=["User Score"]) | |
| # Histograms for each question | |
| fig, axes = plt.subplots(len(data.columns), figsize=(6, 6 * len(data.columns))) | |
| for idx, column in enumerate(data.columns): | |
| create_histogram(data, column, axes[idx]) | |
| plt.tight_layout() | |
| plt.savefig("histograms.png") | |
| # Correlation matrix | |
| corr_matrix = data.corr() | |
| # Clustermap | |
| sns.set(font_scale=0.8) | |
| shortened_columns = [f"Q{idx + 1}" for idx in range(len(data.columns))] | |
| cluster_map = sns.clustermap(corr_matrix, annot=True, cmap="coolwarm", figsize=(10, 10), xticklabels=shortened_columns, yticklabels=shortened_columns) | |
| plt.setp(cluster_map.ax_heatmap.get_xticklabels(), rotation=45) | |
| plt.savefig("cluster_map.png") | |
| return sus_score, "histograms.png", "cluster_map.png", data.describe().T, user_scores_table | |
| iface = gr.Interface( | |
| upload_csv, | |
| [gr.inputs.File(label="Upload CSV file")], | |
| [ | |
| gr.outputs.Textbox(label="SUS Score"), | |
| gr.outputs.Image(label="Histograms", type='numpy'), | |
| gr.outputs.Image(label="Cluster Map", type='numpy'), | |
| gr.outputs.Dataframe(label="Descriptive Statistics", type='pandas'), | |
| gr.outputs.Dataframe(label="Individual User Scores", type='pandas') | |
| ], | |
| title="Survey Analysis", | |
| description="Upload a survey CSV file to get the System Usability Scale (SUS) score, histograms, cluster map, and individual user scores.", | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch(debug=True) | |