correction demi-mot
This commit is contained in:
parent
875f14b119
commit
c09e94c6db
1 changed files with 6 additions and 9 deletions
15
main.py
15
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)")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue