diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..1f80b25 --- /dev/null +++ b/.env.template @@ -0,0 +1 @@ +FABRIQUEDOC_ENDPOINT= diff --git a/.gitignore b/.gitignore index 85e7c1d..a8fba92 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.idea/ +/.env diff --git a/docker-run-macos.sh b/docker-run-macos.sh index 85647e7..a60f847 100644 --- a/docker-run-macos.sh +++ b/docker-run-macos.sh @@ -1,4 +1,4 @@ docker stop fabriquedoc-frontend docker rm fabriquedoc-frontend # Ce programme sert à lancer le job_dispatcher dans un docker localement pour tester -docker run -p 8051:8051 --name fabriquedoc-frontend --network fabriquedoc --env FABRIQUEDOC_ENDPOINT=http://fabriquedoc:8000 local/fabriquedoc-frontend \ No newline at end of file +docker run -p 8051:8051 --env-file=.env --name fabriquedoc-frontend --network fabriquedoc --env FABRIQUEDOC_ENDPOINT=http://fabriquedoc:8000 local/fabriquedoc-frontend \ No newline at end of file diff --git a/docker-run.sh b/docker-run.sh index b79d113..2572b12 100644 --- a/docker-run.sh +++ b/docker-run.sh @@ -1,4 +1,4 @@ docker stop fabriquedoc-frontend docker rm fabriquedoc-frontend # Ce programme sert à lancer le job_dispatcher dans un docker localement pour tester -docker run -p 8051:8051 --name fabriquedoc-frontend --network host local/fabriquedoc-frontend \ No newline at end of file +docker run -p 8051:8051 --env-file=.env --name fabriquedoc-frontend --network host local/fabriquedoc-frontend \ No newline at end of file diff --git a/main.py b/main.py index 40b1537..c7cb723 100644 --- a/main.py +++ b/main.py @@ -17,13 +17,15 @@ """ import datetime - +import dotenv import streamlit as st import requests from pydantic import BaseModel import mdformat import os +dotenv.load_dotenv() + class DocumentSpecs(BaseModel): format: str @@ -58,7 +60,9 @@ if 'options' not in st.session_state: st.title("Fabrique à documents") -fabriquedoc_endpoint = os.environ.get("FABRIQUEDOC_ENDPOINT", "http://0.0.0.0:8000") +fabriquedoc_endpoint = os.environ.get("FABRIQUEDOC_ENDPOINT", "http://127.0.0.1:8000") + +st.write(f"Endpoint : {fabriquedoc_endpoint}") tab1, tab2, tab3, tab4 = st.tabs(["Markdown", "Aperçu", "Paramètres", "Images"]) @@ -80,53 +84,51 @@ with tab2: with tab3: st.header("Paramètres") # Styles - response_styles = requests.get(f"{fabriquedoc_endpoint}/styles") - styles = response_styles.json()["styles"] + response_styles = requests.get(f"{fabriquedoc_endpoint}/styles/").json() + styles = response_styles.get("styles") selected_style = st.selectbox("Select a style:", styles) # Formats - response_formats = requests.get(f"{fabriquedoc_endpoint}/formats/{selected_style}/") - formats = response_formats.json()["formats"] + response_formats = requests.get(f"{fabriquedoc_endpoint}/formats/{selected_style}/").json() + formats = response_formats.get("formats") selected_format = st.selectbox("Select a format:", formats) # Autres paramètres response_format_parameters = requests.get( - f"{fabriquedoc_endpoint}/format_parameters/{selected_style}/{selected_format}") - format_parameters = response_format_parameters.json() - st.write(format_parameters) + f"{fabriquedoc_endpoint}/format_parameters/{selected_style}/{selected_format}/").json() linkcolor = st.text_input("Link color:", - value=format_parameters.get("linkcolor")) + value=response_format_parameters.get("linkcolor")) tocdepth = st.number_input("Table of Contents depth:", - value=int(format_parameters.get("tocdepth")), + value=int(response_format_parameters.get("tocdepth")), min_value=1, max_value=5, step=1) pdfengine = st.text_input("PDF engine:", - value=format_parameters.get("pdfengine")) + value=response_format_parameters.get("pdfengine")) fontsize = st.number_input("Font size:", - value=int(format_parameters.get("fontsize")), + value=int(response_format_parameters.get("fontsize")), step=1) paperwidth = st.number_input("Paper width:", - value=int(format_parameters.get("paperwidth")), + value=int(response_format_parameters.get("paperwidth")), step=30) paperheight = st.number_input("Paper height:", - value=int(format_parameters.get("paperheight")), + value=int(response_format_parameters.get("paperheight")), step=30) ratio = st.number_input("Ratio:", - value=int(format_parameters.get("ratio")), + value=int(response_format_parameters.get("ratio")), step=10) margin = st.number_input("Margin:", - value=int(format_parameters.get("margin")), + value=int(response_format_parameters.get("margin")), step=10) vmargin = st.number_input("Vertical margin:", - value=int(format_parameters.get("vmargin")), + value=int(response_format_parameters.get("vmargin")), step=10) - extension = st.selectbox("Extension:", ["png", "jpg", "pdf", "mp4"]) + extension = st.selectbox("Extension:", ["jpg", "pdf", "mp4"]) if extension == "mp4": fps = st.number_input("FPS:", - value=int(format_parameters.get("fps")), + value=int(response_format_parameters.get("fps")), step=1) stilltime = st.number_input("Still time:", - value=int(format_parameters.get("stilltime")), + value=int(response_format_parameters.get("stilltime")), step=1) else: fps = 0 @@ -163,7 +165,7 @@ with tab3: file_data = response.content datef = datetime.datetime.now().strftime("%m-%d-%Y") - if document_specs.extension in ["jpg", 'png']: + if document_specs.extension in ["jpg"]: extn = "zip" else: extn = document_specs.extension @@ -189,7 +191,7 @@ with tab4: st.write("Envoyer une image") uploaded_files = st.file_uploader("Choisis un fichier image", - type=["png", "jpg", "jpeg"], + type=["jpg", "jpeg"], accept_multiple_files=True) if uploaded_files is not None: for uploaded_file in uploaded_files: diff --git a/requirements.txt b/requirements.txt index 93e9fb5..944ac5d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -streamlit~=1.24.0 -requests~=2.28.2 +streamlit~=1.30.0 +requests~=2.31.0 pydantic~=2.0.1 -mdformat~=0.7.16 \ No newline at end of file +mdformat~=0.7.16 +python-dotenv~=1.0.1 \ No newline at end of file