Spaces:
Sleeping
Sleeping
Davide Fiocco
commited on
Commit
·
c0c5b72
1
Parent(s):
2b07bf2
Revert code and add openpyxl requirement
Browse files- app.py +21 -15
- 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 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 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
|