Davide Fiocco commited on
Commit
c0c5b72
1 Parent(s): 2b07bf2

Revert code and add openpyxl requirement

Browse files
Files changed (2) hide show
  1. app.py +21 -15
  2. requirements.txt +2 -1
app.py CHANGED
@@ -46,24 +46,30 @@ labels = st.text_input("Enter comma-separated labels:")
46
 
47
  if st.button("Calculate labels"):
48
 
49
- labels_list = labels.split(",")
50
- table = pd.read_excel(data)
51
- table = table.loc[table["text"].apply(len) > 10].reset_index(drop=True)
 
52
 
53
- prog_bar = st.progress(0)
54
- preds = []
55
 
56
- for i in range(len(table)):
57
- preds.append(classifier(table.loc[i, "text"], labels)["labels"][0])
58
- prog_bar.progress((i + 1) / len(table))
59
 
60
- table["label"] = preds
61
 
62
- st.table(table[["text", "label"]])
63
 
64
- buf = BytesIO()
65
- table[["text", "label"]].to_excel(buf)
66
 
67
- st.download_button(
68
- label="Download table", data=buf.getvalue(), file_name="output.xlsx"
69
- )
 
 
 
 
 
 
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 = []
56
 
57
+ for i in range(len(table)):
58
+ preds.append(classifier(table.loc[i, "text"], labels)["labels"][0])
59
+ prog_bar.progress((i + 1) / len(table))
60
 
61
+ table["label"] = 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"
75
+ )
requirements.txt CHANGED
@@ -5,4 +5,5 @@ sentencepiece
5
  xlrd
6
  -f https://download.pytorch.org/whl/torch_stable.html
7
  torch
8
- appdirs
 
 
5
  xlrd
6
  -f https://download.pytorch.org/whl/torch_stable.html
7
  torch
8
+ appdirs
9
+ openpyxl