Davide Fiocco commited on
Commit
dbf4eb2
·
1 Parent(s): b1f9764

Add application file

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from transformers import pipeline
4
+
5
+ st.set_page_config(page_title="Zero-shot classification from tabular data", page_icon=None, layout="wide", initial_sidebar_state="auto", menu_items=None)
6
+
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
+ 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
+