File size: 722 Bytes
f0ad92c
 
 
333cd19
 
 
 
 
 
 
 
 
 
 
 
f0ad92c
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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'<a href="data:file/csv;base64,{b64}" download="sample.csv">Download CSV file (sample)</a>'
    return href