Spaces:
Sleeping
Sleeping
Download utils.py from ethanresek/Robots_2_Data: direct link, hf CLI and curl.
- Browser
- Download file 2.6 kB
-
https://huggingface.co/spaces/ethanresek/Robots_2_Data/resolve/main/utils.py
- Command line
-
hf download hf://spaces/ethanresek/Robots_2_Data/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/ethanresek/Robots_2_Data/resolve/main/utils.py
2.6 kB
| import re | |
| import gradio as gr | |
| import pandas as pd | |
| OG_DF = pd.read_csv("All_Robots_Combined_Labeled.csv") | |
| FILTER_DF = pd.read_csv("All_Robots_Combined_Labeled.csv") | |
| MODEL_NAMES = ['deepseek','gpt4o','gpt-3.5','gpt5.2','claude'] | |
| def get_related_columns(df, col_name): | |
| """ | |
| Get columns with names that include the given LLM model name and return an | |
| array with the column names | |
| """ | |
| rel_col = [] | |
| for col in df.columns: | |
| if re.search(rf'(?<![a-zA-Z]){col_name}(?![a-zA-Z])', col, re.IGNORECASE): | |
| rel_col.append(col) | |
| return rel_col | |
| def build_rel_col_dict(df, arr): | |
| """ | |
| Build a dictionary with model names as keys and related column names as values | |
| """ | |
| rel_col_dict = {} | |
| for model in arr: | |
| rel_col = get_related_columns(df, model) | |
| rel_col_dict[model] = rel_col | |
| return rel_col_dict | |
| RELATED_COLUMNS = build_rel_col_dict(OG_DF, MODEL_NAMES) | |
| print(RELATED_COLUMNS) | |
| def robot(show, df, col_name): | |
| """ | |
| Determines whether robot 1 should be shown in the data frame | |
| args: | |
| show - Boolean | |
| Determines whether robot 1 should be shown in the CSV file or not | |
| robot_num - int | |
| The number of the robot the filter is applying to | |
| returns: | |
| nothing | |
| """ | |
| if not show and col_name in df.columns: | |
| df = df.drop(columns=[col_name]) | |
| elif show and col_name not in df.columns: | |
| df.insert(len(df.columns), col_name, OG_DF[col_name]) | |
| return df | |
| def model(show, df, model_name): | |
| """ | |
| Determines whether the given should be shown in the data frame | |
| """ | |
| model_columns = RELATED_COLUMNS[model_name] | |
| for col_name in model_columns: | |
| df = robot(show, df, col_name) | |
| return df | |
| def row_filter(show, val, col, df): | |
| "Filter out values in specified column" | |
| "TODO: Add rest of func definition" | |
| if show: | |
| b = OG_DF[OG_DF[col] == val] | |
| df = pd.concat([df, b]) | |
| elif not show: | |
| df = df[df[col] != val] | |
| return df | |
| def select_all(): | |
| "Select all options in the filter and restore the dataframe" | |
| return OG_DF, *[gr.update(value=True)] * 21 | |
| def clear_all(): | |
| "Deselect all options in the filter and remove all rows in the dataframe" | |
| return pd.DataFrame, *[gr.update(value=True)] * 21 | |
| def apply(): | |
| """ | |
| Applies the filter dataframe to the dataframe in the frontend | |
| Returns: | |
| Filter dataframe | |
| """ | |
| return FILTER_DF | |