Spaces:
Sleeping
Sleeping
d142111015
commited on
Commit
•
833d304
1
Parent(s):
c4772f0
predict_page.py
Browse files- predict_page.py +38 -0
predict_page.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
|
4 |
+
def save_uploaded_files(files, folder_path):
|
5 |
+
# Create the folder if it doesn't exist
|
6 |
+
if not os.path.exists(folder_path):
|
7 |
+
os.makedirs(folder_path)
|
8 |
+
|
9 |
+
saved_file_paths = []
|
10 |
+
for file in files:
|
11 |
+
# Save each uploaded file to the folder
|
12 |
+
file_path = os.path.join(folder_path, file.name)
|
13 |
+
with open(file_path, "wb") as f:
|
14 |
+
f.write(file.getbuffer())
|
15 |
+
saved_file_paths.append(file_path)
|
16 |
+
|
17 |
+
return saved_file_paths
|
18 |
+
|
19 |
+
# Streamlit app
|
20 |
+
def show_predict_page():
|
21 |
+
st.title("Multi-image Uploader")
|
22 |
+
|
23 |
+
# File uploader
|
24 |
+
uploaded_files = st.file_uploader("Upload four images", type=["jpg", "jpeg", "png"], accept_multiple_files=True, key="file_uploader")
|
25 |
+
|
26 |
+
if uploaded_files is not None:
|
27 |
+
# Save the uploaded files to a folder
|
28 |
+
folder_path = "image_folder"
|
29 |
+
saved_file_paths = save_uploaded_files(uploaded_files, folder_path)
|
30 |
+
|
31 |
+
# Display the uploaded images
|
32 |
+
for file_path in saved_file_paths:
|
33 |
+
st.image(file_path, caption="Uploaded Image", use_column_width=True)
|
34 |
+
|
35 |
+
# Display the file paths
|
36 |
+
st.write("Files saved at:")
|
37 |
+
for file_path in saved_file_paths:
|
38 |
+
st.write(file_path)
|