Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
def save_uploaded_files(files, folder_path): | |
# Create the folder if it doesn't exist | |
if not os.path.exists(folder_path): | |
os.makedirs(folder_path) | |
saved_file_paths = [] | |
for file in files: | |
# Save each uploaded file to the folder | |
file_path = os.path.join(folder_path, file.name) | |
with open(file_path, "wb") as f: | |
f.write(file.getbuffer()) | |
saved_file_paths.append(file_path) | |
return saved_file_paths | |
# Streamlit app | |
def show_predict_page(): | |
st.title("Multi-image Uploader") | |
# File uploader | |
uploaded_files = st.file_uploader("Upload four images", type=["jpg", "jpeg", "png"], accept_multiple_files=True, key="file_uploader") | |
if uploaded_files is not None: | |
# Save the uploaded files to a folder | |
folder_path = "image_folder" | |
saved_file_paths = save_uploaded_files(uploaded_files, folder_path) | |
# Display the uploaded images | |
for file_path in saved_file_paths: | |
st.image(file_path, caption="Uploaded Image", use_column_width=True) | |
# Display the file paths | |
st.write("Files saved at:") | |
for file_path in saved_file_paths: | |
st.write(file_path) |