Davide Fiocco commited on
Commit
a452638
1 Parent(s): 2c92878

Add download button

Browse files
Files changed (2) hide show
  1. app.py +14 -4
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import pandas as pd
2
  import streamlit as st
3
  import tokenizers
@@ -20,7 +22,7 @@ st.set_page_config(
20
  tokenizers.AddedToken: lambda _: None,
21
  },
22
  allow_output_mutation=True,
23
- show_spinner=False
24
  )
25
  def load_classifier() -> Pipeline:
26
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
@@ -35,18 +37,19 @@ st.text(
35
  "Upload an Excel table and perform zero-shot classification on a set of custom labels"
36
  )
37
 
38
- data = st.file_uploader("Upload Excel file (it should contain a column named `text` in its header):")
 
 
39
  labels = st.text_input("Enter comma-separated labels:")
40
 
41
  # classify first N snippets only for faster inference
42
- N = 100
43
 
44
  if st.button("Calculate labels"):
45
 
46
  try:
47
  labels_list = labels.split(",")
48
  table = pd.read_excel(data)
49
- table = table.loc[table["text"].apply(len) > 10].reset_index(drop=True).head(N)
50
 
51
  prog_bar = st.progress(0)
52
  preds = []
@@ -59,6 +62,13 @@ if st.button("Calculate labels"):
59
 
60
  st.table(table[["text", "label"]])
61
 
 
 
 
 
 
 
 
62
  except:
63
  st.error(
64
  "Something went wrong. Make sure you upload an Excel file containing a column named `text` and a set of comma-separated labels is provided"
 
1
+ from io import BytesIO
2
+
3
  import pandas as pd
4
  import streamlit as st
5
  import tokenizers
 
22
  tokenizers.AddedToken: lambda _: None,
23
  },
24
  allow_output_mutation=True,
25
+ show_spinner=False,
26
  )
27
  def load_classifier() -> Pipeline:
28
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
 
37
  "Upload an Excel table and perform zero-shot classification on a set of custom labels"
38
  )
39
 
40
+ data = st.file_uploader(
41
+ "Upload Excel file (it should contain a column named `text` in its header):"
42
+ )
43
  labels = st.text_input("Enter comma-separated labels:")
44
 
45
  # classify first N snippets only for faster inference
 
46
 
47
  if st.button("Calculate labels"):
48
 
49
  try:
50
  labels_list = labels.split(",")
51
  table = pd.read_excel(data)
52
+ table = table.loc[table["text"].apply(len) > 10].reset_index(drop=True)
53
 
54
  prog_bar = st.progress(0)
55
  preds = []
 
62
 
63
  st.table(table[["text", "label"]])
64
 
65
+ buf = BytesIO()
66
+ table[["text", "label"]].to_excel(buf)
67
+
68
+ st.download_button(
69
+ label="Download table", data=buf.getvalue(), file_name="output.xlsx"
70
+ )
71
+
72
  except:
73
  st.error(
74
  "Something went wrong. Make sure you upload an Excel file containing a column named `text` and a set of comma-separated labels is provided"
requirements.txt CHANGED
@@ -4,4 +4,5 @@ protobuf
4
  sentencepiece
5
  xlrd
6
  -f https://download.pytorch.org/whl/torch_stable.html
7
- torch
 
 
4
  sentencepiece
5
  xlrd
6
  -f https://download.pytorch.org/whl/torch_stable.html
7
+ torch
8
+ appdirs