File size: 1,628 Bytes
a63811d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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()