Version initiale

This commit is contained in:
Francois Pelletier 2023-03-16 00:20:38 -04:00
commit 4d5896b15f
10 changed files with 185 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/.idea/

38
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,38 @@
# .gitlab-ci.yml
stages:
- dockerize
- deployment
build-push-docker-image-job:
stage: dockerize
# Specify a Docker image to run the job in.
image: docker:20-dind
# Specify an additional image 'docker:dind' ("Docker-in-Docker") that
# will start up the Docker daemon when it is brought up by a runner.
before_script:
- docker login -u "$DOCKER_REGISTRY_USER" -p "$DOCKER_REGISTRY_PASSWORD" $DOCKER_REGISTRY_URL # Instructs GitLab to login to its registry
services:
- name: docker:20-dind
alias: docker
command: ["--tls=false"]
script:
- echo "Building..." # MAKE SURE NO SPACE ON EITHER SIDE OF = IN THE FOLLOWING LINE
- export CONTAINER_FULL_IMAGE_NAME_WITH_TAG=$IMAGE_NAME_WITH_REGISTRY_PREFIX/my-build-image:$COMMIT_HASH
- docker build -f ./Dockerfile --pull -t built-image-name .
- docker tag built-image-name "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
- docker push "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
- echo "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
- echo "Deploying on CapRover..."
- docker run caprover/cli-caprover:2.2.3 caprover deploy --caproverUrl "$CAPROVER_URL" --caproverPassword "$CAPROVER_PASSWORD" -a "$CAPROVER_APP" -i "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
only:
- main
variables:
DOCKER_REGISTRY_USER: ${CI_REGISTRY_USER}
DOCKER_REGISTRY_PASSWORD: ${CI_REGISTRY_PASSWORD}
DOCKER_REGISTRY_URL: ${CI_REGISTRY}
IMAGE_NAME_WITH_REGISTRY_PREFIX: ${CI_REGISTRY_IMAGE}
COMMIT_HASH: ${CI_COMMIT_SHA}
CAPROVER_URL: ${CAPROVER_URL}
CAPROVER_PASSWORD: ${CAPROVER_PASSWORD}
CAPROVER_APP: ${CAPROVER_APP}

19
Dockerfile Normal file
View file

@ -0,0 +1,19 @@
FROM python:3.10-slim
EXPOSE 8052
WORKDIR /app
# Install the app's dependencies
RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY install.py .
RUN python install.py
# Copy the app's code
COPY main.py .
# Set the entrypoint to run the app
ENTRYPOINT [ "streamlit", "run" ]
CMD [ "main.py", "--server.port=8052", "--server.headless", "true", "--server.fileWatcherType", "none", "--browser.gatherUsageStats", "false"]

1
build-local.sh Normal file
View file

@ -0,0 +1 @@
docker build -t local/split-reading-bold .

6
docker-run.sh Normal file
View file

@ -0,0 +1,6 @@
#!/usr/bin/zsh
docker stop split-reading-bold
docker rm split-reading-bold
# Ce programme sert à lancer le split-reading-bold dans un docker localement pour tester
docker run -p 8052:8052 --name split-reading-bold --network host local/split-reading-bold

2
install.py Normal file
View file

@ -0,0 +1,2 @@
import nltk
nltk.download('punkt')

62
main.py Normal file
View file

@ -0,0 +1,62 @@
import re
import streamlit as st
import nltk
def remove_space_before_punctuation(text):
"""
Removes space before punctuation.
"""
text = re.sub(r"\s+\*\*([.;,?!])\*\*", "\1", text)
return text
def make_bold_part(token, num):
"""
Makes bold text.
"""
if len(token) <= 2:
return token
else:
return f"**{token[0:num]}**{token[num:]}"
def split_tokens(text, num, lang):
"""
Splits a text into tokens.
"""
paragraphs = text.split("\n\n")
new_paragraphs = []
for paragraph in paragraphs:
tokens = nltk.word_tokenize(paragraph, language=lang)
tokens = [make_bold_part(token, num) for token in tokens]
par = remove_space_before_punctuation(" ".join(tokens))
new_paragraphs.append(par)
return "\n\n".join(new_paragraphs)
def write_app():
"""
Write a streamlit app with an input box, a numerical slider from 1 to 5 and an output box.
: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)}")
def main():
write_app()
if __name__ == "__main__":
main()

46
requirements.txt Normal file
View file

@ -0,0 +1,46 @@
Pillow~=9.4.0
gitdb~=4.0.10
pip~=23.0.1
attrs~=22.2.0
wheel~=0.38.4
tornado~=6.2
Jinja2~=3.1.2
toolz~=0.12.0
nltk~=3.8.1
numpy~=1.24.2
regex~=2022.10.31
click~=8.1.3
tqdm~=4.65.0
requests~=2.28.2
pytz~=2022.7.1
rich~=13.3.2
Pygments~=2.14.0
toml~=0.10.2
smmap~=5.0.0
mdurl~=0.1.2
setuptools~=67.3.3
altair~=4.2.2
pandas~=1.5.3
jsonschema~=4.17.3
entrypoints~=0.4
MarkupSafe~=2.1.2
joblib~=1.2.0
python-dateutil~=2.8.2
pyarrow~=11.0.0
pydeck~=0.8.0
blinker~=1.5
certifi~=2022.12.7
tzdata~=2022.7
Pympler~=1.0.1
tzlocal~=4.2
six~=1.16.0
idna~=3.4
urllib3~=1.26.15
watchdog~=2.3.1
streamlit~=1.20.0
cachetools~=5.3.0
validators~=0.20.0
packaging~=23.0
pyrsistent~=0.19.3
zipp~=3.15.0
decorator~=5.1.1

1
run_app.sh Normal file
View file

@ -0,0 +1 @@
streamlit run /home/francois/projets/split_reading_bold/main.py

9
split-reading-bold.iml Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.10 (split_reading_bold)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>