import os import streamlit as st from PIL import Image # Function to delete the image and its caption def delete_file(image_path): txt_path = os.path.splitext(image_path)[0] + '.txt' if os.path.exists(image_path): os.remove(image_path) if os.path.exists(txt_path): os.remove(txt_path) st.success(f"Deleted: {os.path.basename(image_path)} and {os.path.basename(txt_path)}") # Streamlit app def main(): st.title("Image and Caption Viewer") # Input for folder path folder_path = st.text_input("Enter the path to your folder:", "") if folder_path: # Check if the folder exists if os.path.exists(folder_path): # List all image files in the folder image_files = [f for f in os.listdir(folder_path) if f.endswith(('.png', '.jpg', '.jpeg'))] if image_files: for image_file in image_files: image_path = os.path.join(folder_path, image_file) # Display the image image = Image.open(image_path) st.image(image, caption=image_file) # Display image resolution st.write(f"Resolution: {image.size}") # Delete button if st.button(f"Delete {image_file}", key=image_file): delete_file(image_path) else: st.warning("No image files found in the folder.") else: st.error("Folder path does not exist.") if __name__ == "__main__": main()