version qui gère plusieurs fichiers images en upload en même temps
This commit is contained in:
parent
aff029777d
commit
f7d65d7485
1 changed files with 29 additions and 25 deletions
54
main.py
54
main.py
|
@ -25,6 +25,16 @@ class DocumentSpecs(BaseModel):
|
|||
stilltime: int
|
||||
|
||||
|
||||
demo_text = """
|
||||
# Ceci est un titre\n
|
||||
## Ceci est un sous-titre\n\n
|
||||
Ceci est un paragraphe\n\n
|
||||
## Ceci est un autre sous-titre\n\n
|
||||
> Ceci est du code\n\n
|
||||
Ceci est un emoji :heart_eyes:\n\n
|
||||
::: {.center}\nCeci est centré\n:::
|
||||
"""
|
||||
|
||||
if 'options' not in st.session_state:
|
||||
st.session_state['options'] = ""
|
||||
|
||||
|
@ -40,16 +50,7 @@ with tab1:
|
|||
options={"number": True})
|
||||
|
||||
|
||||
content = st.text_area("Enter Markdown text to send:",
|
||||
"""
|
||||
# Ceci est un titre\n
|
||||
## Ceci est un sous-titre\n\n
|
||||
Ceci est un paragraphe\n\n
|
||||
## Ceci est un autre sous-titre\n\n
|
||||
> Ceci est du code\n\n
|
||||
Ceci est un emoji :heart_eyes:\n\n
|
||||
::: {.center}\nCeci est centré\n:::
|
||||
""",
|
||||
content = st.text_area("Entre ton texte ici. Les images sont dans ./images/", demo_text,
|
||||
height=450,
|
||||
key='markdown')
|
||||
st.button("Formater le texte", on_click=button1_callback)
|
||||
|
@ -151,7 +152,7 @@ with tab3:
|
|||
|
||||
file_name = f"{document_specs.style}-{document_specs.format}-{datef}-output.{extn}"
|
||||
|
||||
st.download_button('Download File', file_data, file_name=file_name)
|
||||
st.download_button('Télécharger', file_data, file_name=file_name)
|
||||
else:
|
||||
# If the request is unsuccessful, display the error status code and message
|
||||
st.error(f"Request failed with status code {response.status_code}: {response.text}")
|
||||
|
@ -159,27 +160,30 @@ with tab3:
|
|||
with tab4:
|
||||
st.header("Images")
|
||||
|
||||
st.write("Uploaded image")
|
||||
st.write("Images disponibles")
|
||||
# list uploaded files with a request to the GET /images endpoint
|
||||
response = requests.get(f"{fabriquedoc_endpoint}/images/")
|
||||
images = response.json()["images"]
|
||||
selected_image = st.selectbox("Select an image:", images)
|
||||
selected_image = st.selectbox("Choisis une image:", images)
|
||||
image_response = requests.get(f"{fabriquedoc_endpoint}/images/{selected_image}")
|
||||
image_data = image_response.content
|
||||
st.image(image_data)
|
||||
|
||||
st.write("Upload image")
|
||||
uploaded_files = st.file_uploader("Choose an image file", type=["png", "jpg", "jpeg"])
|
||||
st.write("Envoyer une image")
|
||||
uploaded_files = st.file_uploader("Choisis un fichier image",
|
||||
type=["png", "jpg", "jpeg"],
|
||||
accept_multiple_files=True)
|
||||
if uploaded_files is not None:
|
||||
url = f"{fabriquedoc_endpoint}/images/"
|
||||
# Create a FormData object
|
||||
files = {"file": uploaded_files}
|
||||
for uploaded_file in uploaded_files:
|
||||
url = f"{fabriquedoc_endpoint}/images/"
|
||||
# Create a FormData object
|
||||
files = {"file": uploaded_file}
|
||||
|
||||
# Submit the file to the endpoint
|
||||
response = requests.post(url, files=files)
|
||||
# Submit the file to the endpoint
|
||||
response = requests.post(url, files=files)
|
||||
|
||||
# Check the response status
|
||||
if response.status_code < 300:
|
||||
st.write("File sent successfully!")
|
||||
else:
|
||||
st.write("File upload failed.")
|
||||
# Check the response status
|
||||
if response.status_code < 300:
|
||||
st.write(f"File {uploaded_file.name} sent successfully!")
|
||||
else:
|
||||
st.write(f"File {uploaded_file.name} upload failed.")
|
||||
|
|
Loading…
Reference in a new issue