import base64 import pandas as pd # Function to check if the uploaded file has the expected columns def check_columns(df): if set(df.columns) == set(["text", "label"]): return True else: return False # Function to calculate the number of instances of each label class def count_labels(df): counts = df["label"].value_counts() return counts.to_dict() def get_download_link(df): """Generates a link allowing the data in a pandas dataframe to be downloaded""" csv = df.to_csv(index=False) b64 = base64.b64encode(csv.encode()).decode() # encoding the data href = f'Download CSV file (sample)' return href