|
import os
|
|
import streamlit as st
|
|
from PIL import Image
|
|
|
|
|
|
|
|
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)}")
|
|
|
|
|
|
|
|
def main():
|
|
st.title("Image and Caption Viewer")
|
|
|
|
|
|
folder_path = st.text_input("Enter the path to your folder:", "")
|
|
|
|
if folder_path:
|
|
|
|
if os.path.exists(folder_path):
|
|
|
|
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)
|
|
|
|
|
|
image = Image.open(image_path)
|
|
st.image(image, caption=image_file)
|
|
|
|
|
|
st.write(f"Resolution: {image.size}")
|
|
|
|
|
|
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()
|
|
|