From c09e94c6db26e89fdc575f9714a3cfa8d564f55a Mon Sep 17 00:00:00 2001 From: Francois Pelletier Date: Mon, 17 Apr 2023 18:19:21 -0400 Subject: [PATCH] correction demi-mot --- main.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index c801f8b..cb7739d 100644 --- a/main.py +++ b/main.py @@ -27,17 +27,18 @@ def remove_space_before_punctuation(text): return text -def make_bold_part(token, num): +def make_bold_part(token): """ Makes bold text. """ if len(token) <= 2: return token else: - return f"**{token[0:num]}**{token[num:]}" + mid_token = round(len(token)/2) + return f"**{token[0:mid_token]}**{token[mid_token:]}" -def split_tokens(text, num, lang): +def split_tokens(text, lang): """ Splits a text into tokens. """ @@ -45,7 +46,7 @@ def split_tokens(text, num, lang): new_paragraphs = [] for paragraph in paragraphs: tokens = nltk.word_tokenize(paragraph, language=lang) - tokens = [make_bold_part(token, num) for token in tokens] + tokens = [make_bold_part(token) for token in tokens] par = remove_space_before_punctuation(" ".join(tokens)) new_paragraphs.append(par) return "\n\n".join(new_paragraphs) @@ -57,16 +58,12 @@ def write_app(): :return: """ st.title("Texte Rapide") - st.sidebar.title("Choisis le niveau de gras") - num = st.sidebar.slider("Number", 1, 10, 5) - st.sidebar.text(f"Niveau de gras: {num}") - # choose a language lang = st.sidebar.selectbox(label="Langue", options=["french", "english"], index=0) st.sidebar.text(f"Langue: {lang}") text = st.text_area("Text", "Entre ton texte ici") bouton = st.button("Envoyer") if bouton: - st.markdown(f"{split_tokens(text, num, lang)}") + st.markdown(f"{split_tokens(text, lang)}") st.markdown("Développé avec ❤ par [François Pelletier](https://linktr.ee/jevalideca)")