Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -78,26 +78,33 @@ st.title("Image Gallery with Captioning and Search")
|
|
78 |
with st.sidebar:
|
79 |
query = st.text_input("Search images by caption:")
|
80 |
|
81 |
-
#
|
82 |
-
|
83 |
|
84 |
-
uploaded_files = st.file_uploader("Upload images or a zip file containing images:", type=['png', 'jpg', 'jpeg', 'zip'], accept_multiple_files=True)
|
85 |
image_files = []
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1])
|
98 |
temp_file.write(uploaded_file.read())
|
99 |
image_files.append(temp_file.name)
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
captions = {}
|
102 |
if st.button("Generate Captions", key='generate_captions'):
|
103 |
for image_file in image_files:
|
|
|
78 |
with st.sidebar:
|
79 |
query = st.text_input("Search images by caption:")
|
80 |
|
81 |
+
# Options for input strategy
|
82 |
+
input_option = st.selectbox("Select input method:", ["Folder Path", "Upload Images", "Upload ZIP"])
|
83 |
|
|
|
84 |
image_files = []
|
85 |
+
|
86 |
+
if input_option == "Folder Path":
|
87 |
+
folder_path = st.text_input("Enter the folder path containing images:")
|
88 |
+
if folder_path and os.path.isdir(folder_path):
|
89 |
+
image_files = [os.path.join(folder_path, f) for f in os.listdir(folder_path) if f.lower().endswith(('png', 'jpg', 'jpeg'))]
|
90 |
+
|
91 |
+
elif input_option == "Upload Images":
|
92 |
+
uploaded_files = st.file_uploader("Upload image files", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
|
93 |
+
if uploaded_files:
|
94 |
+
for uploaded_file in uploaded_files:
|
95 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as temp_file:
|
|
|
96 |
temp_file.write(uploaded_file.read())
|
97 |
image_files.append(temp_file.name)
|
98 |
|
99 |
+
elif input_option == "Upload ZIP":
|
100 |
+
uploaded_zip = st.file_uploader("Upload a ZIP file containing images", type=["zip"])
|
101 |
+
if uploaded_zip:
|
102 |
+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
103 |
+
temp_file.write(uploaded_zip.read())
|
104 |
+
with zipfile.ZipFile(temp_file.name, 'r') as zip_ref:
|
105 |
+
zip_ref.extractall("/tmp/images")
|
106 |
+
image_files = [os.path.join("/tmp/images", f) for f in zip_ref.namelist() if f.lower().endswith(('png', 'jpg', 'jpeg'))]
|
107 |
+
|
108 |
captions = {}
|
109 |
if st.button("Generate Captions", key='generate_captions'):
|
110 |
for image_file in image_files:
|