35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
import requests
|
|
import streamlit as st
|
|
|
|
|
|
def app_tab4():
|
|
st.header("Images")
|
|
http_headers = {"Authorization": f"Bearer {st.session_state['bearer_token']}"}
|
|
|
|
st.write("Images disponibles")
|
|
# list uploaded files with a request to the GET /images endpoint
|
|
response = requests.get(f"{st.session_state['fabriquedoc_endpoint']}/images/", headers=http_headers)
|
|
images = response.json()["images"]
|
|
selected_image = st.selectbox("Choisis une image:", images)
|
|
image_response = requests.get(f"{st.session_state['fabriquedoc_endpoint']}/images/{selected_image}", headers=http_headers)
|
|
image_data = image_response.content
|
|
st.image(image_data)
|
|
|
|
st.write("Envoyer une image")
|
|
uploaded_files = st.file_uploader("Choisis un fichier image",
|
|
type=["jpg", "jpeg"],
|
|
accept_multiple_files=True)
|
|
if uploaded_files is not None:
|
|
for uploaded_file in uploaded_files:
|
|
url = f"{st.session_state['fabriquedoc_endpoint']}/images/"
|
|
# Create a FormData object
|
|
files = {"file": uploaded_file}
|
|
|
|
# Submit the file to the endpoint
|
|
response = requests.post(url, files=files, headers=http_headers)
|
|
|
|
# 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.")
|