Davide Fiocco commited on
Commit
38f2cf5
·
1 Parent(s): 6c9e3d2

Reintroduce error handing and UI hints

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -7,27 +7,31 @@ st.set_page_config(page_title="Zero-shot classification from tabular data", page
7
  classifier = pipeline("zero-shot-classification", model="typeform/distilbert-base-uncased-mnli")
8
 
9
  st.title("Zero-shot classification from tabular data")
10
- st.text("Upload a table and perform zero-shot classification on a set of custom labels")
11
 
12
- data = st.file_uploader("Upload Excel file:")
13
  labels = st.text_input("Enter comma-separated labels:")
14
 
15
  if st.button("Calculate labels"):
16
 
17
- labels_list = labels.split(",")
18
- table = pd.read_excel(data)
19
- table = table.loc[table["text"].apply(len) > 10].reset_index(drop=True).head(50)
 
20
 
21
- prog_bar = st.progress(0)
22
- preds = []
23
 
24
- for i in range(len(table)):
25
- preds.append(classifier(table.loc[i, "text"], labels)["labels"][0])
26
- prog_bar.progress((i + 1)/len(table))
27
 
28
- table["label"] = preds
29
 
30
- st.table(table[["text", "label"]])
 
 
 
31
 
32
 
33
 
 
7
  classifier = pipeline("zero-shot-classification", model="typeform/distilbert-base-uncased-mnli")
8
 
9
  st.title("Zero-shot classification from tabular data")
10
+ st.text("Upload an Excel table and perform zero-shot classification on a set of custom labels")
11
 
12
+ data = st.file_uploader("Upload Excel file (it should contain a `text` column):")
13
  labels = st.text_input("Enter comma-separated labels:")
14
 
15
  if st.button("Calculate labels"):
16
 
17
+ try:
18
+ labels_list = labels.split(",")
19
+ table = pd.read_excel(data)
20
+ table = table.loc[table["text"].apply(len) > 10].reset_index(drop=True).head(50)
21
 
22
+ prog_bar = st.progress(0)
23
+ preds = []
24
 
25
+ for i in range(len(table)):
26
+ preds.append(classifier(table.loc[i, "text"], labels)["labels"][0])
27
+ prog_bar.progress((i + 1)/len(table))
28
 
29
+ table["label"] = preds
30
 
31
+ st.table(table[["text", "label"]])
32
+
33
+ except:
34
+ st.error("File load didn't work. Make sure you upload a file containing a `text` column and a set of comma-separated labels is provided")
35
 
36
 
37