Bram Vanroy
commited on
Commit
•
f73827b
1
Parent(s):
d5db8f1
improve progressbar
Browse files
app.py
CHANGED
@@ -38,14 +38,15 @@ else:
|
|
38 |
|
39 |
|
40 |
def _get_increment_size(num_sents) -> int:
|
41 |
-
if
|
42 |
return 100
|
43 |
else:
|
44 |
-
return ceil(100 /
|
45 |
|
46 |
|
47 |
btn_col, results_col = st.columns(2)
|
48 |
btn_ct = btn_col.empty()
|
|
|
49 |
error_ct = st.empty()
|
50 |
simpl_ct = st.container()
|
51 |
if st.session_state["text_to_simplify"]:
|
@@ -56,7 +57,7 @@ if st.session_state["text_to_simplify"]:
|
|
56 |
]
|
57 |
num_sentences = len(lines)
|
58 |
|
59 |
-
pbar =
|
60 |
increment = _get_increment_size(num_sentences)
|
61 |
percent_done = 0
|
62 |
|
@@ -77,10 +78,11 @@ if st.session_state["text_to_simplify"]:
|
|
77 |
</li>"""
|
78 |
output_ct.markdown(html + "</ol>", unsafe_allow_html=True)
|
79 |
|
|
|
|
|
|
|
80 |
all_simplifications.extend(simplifications)
|
81 |
|
82 |
-
percent_done += increment
|
83 |
-
pbar.progress(min(percent_done, 100))
|
84 |
pbar.empty()
|
85 |
|
86 |
all_simplifications = "\n".join(all_simplifications) + "\n"
|
|
|
38 |
|
39 |
|
40 |
def _get_increment_size(num_sents) -> int:
|
41 |
+
if num_sents == 1:
|
42 |
return 100
|
43 |
else:
|
44 |
+
return ceil(100 / num_sents)
|
45 |
|
46 |
|
47 |
btn_col, results_col = st.columns(2)
|
48 |
btn_ct = btn_col.empty()
|
49 |
+
pbar_ct = st.empty()
|
50 |
error_ct = st.empty()
|
51 |
simpl_ct = st.container()
|
52 |
if st.session_state["text_to_simplify"]:
|
|
|
57 |
]
|
58 |
num_sentences = len(lines)
|
59 |
|
60 |
+
pbar = pbar_ct.progress(0, text=f"Simplifying sentences in batches of {BATCH_SIZE}...")
|
61 |
increment = _get_increment_size(num_sentences)
|
62 |
percent_done = 0
|
63 |
|
|
|
78 |
</li>"""
|
79 |
output_ct.markdown(html + "</ol>", unsafe_allow_html=True)
|
80 |
|
81 |
+
percent_done += increment
|
82 |
+
pbar.progress(min(percent_done, 100))
|
83 |
+
|
84 |
all_simplifications.extend(simplifications)
|
85 |
|
|
|
|
|
86 |
pbar.empty()
|
87 |
|
88 |
all_simplifications = "\n".join(all_simplifications) + "\n"
|
utils.py
CHANGED
@@ -48,7 +48,7 @@ def simplify(
|
|
48 |
"""
|
49 |
for batch_texts in batchify(texts, batch_size=batch_size):
|
50 |
nlg_batch_texts = ["[NLG] " + text for text in batch_texts]
|
51 |
-
encoded = tokenizer(nlg_batch_texts, return_tensors="pt", padding=True
|
52 |
encoded = {k: v.to(model.device) for k, v in encoded.items()}
|
53 |
gen_kwargs = {
|
54 |
"max_new_tokens": 128,
|
|
|
48 |
"""
|
49 |
for batch_texts in batchify(texts, batch_size=batch_size):
|
50 |
nlg_batch_texts = ["[NLG] " + text for text in batch_texts]
|
51 |
+
encoded = tokenizer(nlg_batch_texts, return_tensors="pt", padding=True)
|
52 |
encoded = {k: v.to(model.device) for k, v in encoded.items()}
|
53 |
gen_kwargs = {
|
54 |
"max_new_tokens": 128,
|