version corrigée de l'app

This commit is contained in:
francois 2024-06-26 00:07:04 -04:00
parent 4765b1dc9a
commit 2478d41729
6 changed files with 33 additions and 28 deletions

1
.env.template Normal file
View file

@ -0,0 +1 @@
FABRIQUEDOC_ENDPOINT=

1
.gitignore vendored
View file

@ -1 +1,2 @@
/.idea/
/.env

View file

@ -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
docker run -p 8051:8051 --env-file=.env --name fabriquedoc-frontend --network fabriquedoc --env FABRIQUEDOC_ENDPOINT=http://fabriquedoc:8000 local/fabriquedoc-frontend

View file

@ -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
docker run -p 8051:8051 --env-file=.env --name fabriquedoc-frontend --network host local/fabriquedoc-frontend

48
main.py
View file

@ -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:

View file

@ -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
mdformat~=0.7.16
python-dotenv~=1.0.1