Spaces:
Runtime error
Runtime error
Paula Leonova
commited on
Commit
•
d855e09
1
Parent(s):
6af2acc
Add multiple upload options for text input
Browse files
app.py
CHANGED
@@ -42,9 +42,14 @@ with st.form(key='my_form'):
|
|
42 |
|
43 |
text_csv_expander = st.expander(label=f'Want to upload multiple texts at once? Expand to upload your text files below.', expanded=False)
|
44 |
with text_csv_expander:
|
|
|
45 |
uploaded_text_files = st.file_uploader(label="Upload file(s) that end with the .txt suffix",
|
46 |
-
accept_multiple_files=True,
|
47 |
type = 'txt')
|
|
|
|
|
|
|
|
|
48 |
|
49 |
if text_input == display_text and display_text != '':
|
50 |
text_input = example_text
|
@@ -57,7 +62,7 @@ with st.form(key='my_form'):
|
|
57 |
|
58 |
labels_csv_expander = st.expander(label=f'Prefer to upload a list of labels instead? Click here to upload your CSV file.',expanded=False)
|
59 |
with labels_csv_expander:
|
60 |
-
uploaded_labels_file = st.file_uploader("Choose a CSV file with one column and no header, where each cell is a separate label",
|
61 |
key='labels_uploader')
|
62 |
|
63 |
gen_keywords = st.radio(
|
@@ -75,10 +80,10 @@ with st.form(key='my_form'):
|
|
75 |
with glabels_csv_expander:
|
76 |
st.write("Option A:")
|
77 |
uploaded_onetext_glabels_file = st.file_uploader("Choose a CSV file with one column and no header, where each cell is a separate label",
|
78 |
-
key = '
|
79 |
st.write("Option B:")
|
80 |
-
uploaded_multitext_glabels_file = st.file_uploader('Choose a CSV file with two columns "title" and "label", with the cells in the title column matching the name of the files uploaded in step #1.',
|
81 |
-
key = '
|
82 |
|
83 |
|
84 |
|
@@ -107,22 +112,28 @@ with st.spinner('Loading pretrained models...'):
|
|
107 |
|
108 |
|
109 |
if submit_button or example_button:
|
110 |
-
if len(text_input) == 0 and uploaded_text_files is None:
|
111 |
st.error("Enter some text to generate a summary")
|
112 |
else:
|
113 |
|
114 |
if uploaded_text_files is not None:
|
|
|
115 |
file_names = []
|
116 |
raw_texts = []
|
117 |
for uploaded_file in uploaded_text_files:
|
118 |
text = str(uploaded_file.read(), "utf-8")
|
119 |
raw_texts.append(text)
|
120 |
-
|
121 |
-
|
122 |
-
# st.write(raw_text)
|
123 |
text_data = pd.DataFrame({'title': file_names,
|
124 |
'text': raw_texts})
|
125 |
st.dataframe(text_data.head())
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
|
128 |
with st.spinner('Breaking up text into more reasonable chunks (transformers cannot exceed a 1024 token max)...'):
|
|
|
42 |
|
43 |
text_csv_expander = st.expander(label=f'Want to upload multiple texts at once? Expand to upload your text files below.', expanded=False)
|
44 |
with text_csv_expander:
|
45 |
+
st.write("Option A:")
|
46 |
uploaded_text_files = st.file_uploader(label="Upload file(s) that end with the .txt suffix",
|
47 |
+
accept_multiple_files=True, key = 'text_uploader',
|
48 |
type = 'txt')
|
49 |
+
st.write("Option B:")
|
50 |
+
uploaded_csv_text_files = st.file_uploader(label='Upload a CSV file with columns: "title" and "text"',
|
51 |
+
accept_multiple_files=False, key = 'csv_text_uploader',
|
52 |
+
type = 'csv')
|
53 |
|
54 |
if text_input == display_text and display_text != '':
|
55 |
text_input = example_text
|
|
|
62 |
|
63 |
labels_csv_expander = st.expander(label=f'Prefer to upload a list of labels instead? Click here to upload your CSV file.',expanded=False)
|
64 |
with labels_csv_expander:
|
65 |
+
uploaded_labels_file = st.file_uploader("Or Choose a CSV file with one column and no header, where each cell is a separate label",
|
66 |
key='labels_uploader')
|
67 |
|
68 |
gen_keywords = st.radio(
|
|
|
80 |
with glabels_csv_expander:
|
81 |
st.write("Option A:")
|
82 |
uploaded_onetext_glabels_file = st.file_uploader("Choose a CSV file with one column and no header, where each cell is a separate label",
|
83 |
+
key = 'onetext_glabels_uploader')
|
84 |
st.write("Option B:")
|
85 |
+
uploaded_multitext_glabels_file = st.file_uploader('Or Choose a CSV file with two columns "title" and "label", with the cells in the title column matching the name of the files uploaded in step #1.',
|
86 |
+
key = 'multitext_glabels_uploader')
|
87 |
|
88 |
|
89 |
|
|
|
112 |
|
113 |
|
114 |
if submit_button or example_button:
|
115 |
+
if len(text_input) == 0 and uploaded_text_files is None and uploaded_csv_text_files is None:
|
116 |
st.error("Enter some text to generate a summary")
|
117 |
else:
|
118 |
|
119 |
if uploaded_text_files is not None:
|
120 |
+
st.markdown("### Text Inputs")
|
121 |
file_names = []
|
122 |
raw_texts = []
|
123 |
for uploaded_file in uploaded_text_files:
|
124 |
text = str(uploaded_file.read(), "utf-8")
|
125 |
raw_texts.append(text)
|
126 |
+
title_file_name = uploaded_file.name.replace('.txt','')
|
127 |
+
file_names.append(title_file_name)
|
|
|
128 |
text_data = pd.DataFrame({'title': file_names,
|
129 |
'text': raw_texts})
|
130 |
st.dataframe(text_data.head())
|
131 |
+
st.download_button(
|
132 |
+
label="Download data as CSV",
|
133 |
+
data=text_data.to_csv().encode('utf-8'),
|
134 |
+
file_name='title_text_data.csv',
|
135 |
+
mime='title_text/csv',
|
136 |
+
)
|
137 |
|
138 |
|
139 |
with st.spinner('Breaking up text into more reasonable chunks (transformers cannot exceed a 1024 token max)...'):
|