Upload 2 files
Browse files- app.py +50 -0
- data_set_content_checker.py +29 -0
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# Function to delete the image and its caption
|
| 7 |
+
def delete_file(image_path):
|
| 8 |
+
txt_path = os.path.splitext(image_path)[0] + '.txt'
|
| 9 |
+
if os.path.exists(image_path):
|
| 10 |
+
os.remove(image_path)
|
| 11 |
+
if os.path.exists(txt_path):
|
| 12 |
+
os.remove(txt_path)
|
| 13 |
+
st.success(f"Deleted: {os.path.basename(image_path)} and {os.path.basename(txt_path)}")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Streamlit app
|
| 17 |
+
def main():
|
| 18 |
+
st.title("Image and Caption Viewer")
|
| 19 |
+
|
| 20 |
+
# Input for folder path
|
| 21 |
+
folder_path = st.text_input("Enter the path to your folder:", "")
|
| 22 |
+
|
| 23 |
+
if folder_path:
|
| 24 |
+
# Check if the folder exists
|
| 25 |
+
if os.path.exists(folder_path):
|
| 26 |
+
# List all image files in the folder
|
| 27 |
+
image_files = [f for f in os.listdir(folder_path) if f.endswith(('.png', '.jpg', '.jpeg'))]
|
| 28 |
+
|
| 29 |
+
if image_files:
|
| 30 |
+
for image_file in image_files:
|
| 31 |
+
image_path = os.path.join(folder_path, image_file)
|
| 32 |
+
|
| 33 |
+
# Display the image
|
| 34 |
+
image = Image.open(image_path)
|
| 35 |
+
st.image(image, caption=image_file)
|
| 36 |
+
|
| 37 |
+
# Display image resolution
|
| 38 |
+
st.write(f"Resolution: {image.size}")
|
| 39 |
+
|
| 40 |
+
# Delete button
|
| 41 |
+
if st.button(f"Delete {image_file}", key=image_file):
|
| 42 |
+
delete_file(image_path)
|
| 43 |
+
else:
|
| 44 |
+
st.warning("No image files found in the folder.")
|
| 45 |
+
else:
|
| 46 |
+
st.error("Folder path does not exist.")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
if __name__ == "__main__":
|
| 50 |
+
main()
|
data_set_content_checker.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
# Path to the folder containing the images and text files
|
| 4 |
+
folder_path = "kohya_finetune_data"
|
| 5 |
+
|
| 6 |
+
# List of valid image extensions
|
| 7 |
+
image_extensions = ('.png', '.jpg', '.jpeg')
|
| 8 |
+
|
| 9 |
+
# Get lists of image and text files in the folder
|
| 10 |
+
image_files = [f for f in os.listdir(folder_path) if f.lower().endswith(image_extensions)]
|
| 11 |
+
text_files = [f for f in os.listdir(folder_path) if f.endswith('.txt')]
|
| 12 |
+
|
| 13 |
+
# Create sets of base filenames without extensions
|
| 14 |
+
image_basenames = {os.path.splitext(f)[0] for f in image_files}
|
| 15 |
+
text_basenames = {os.path.splitext(f)[0] for f in text_files}
|
| 16 |
+
|
| 17 |
+
# Check for image files without corresponding text files
|
| 18 |
+
for image_file in image_files:
|
| 19 |
+
base_name = os.path.splitext(image_file)[0]
|
| 20 |
+
if base_name not in text_basenames:
|
| 21 |
+
os.remove(os.path.join(folder_path, image_file))
|
| 22 |
+
print(f'Removed image file without corresponding text file: {image_file}')
|
| 23 |
+
|
| 24 |
+
# Check for text files without corresponding image files
|
| 25 |
+
for text_file in text_files:
|
| 26 |
+
base_name = os.path.splitext(text_file)[0]
|
| 27 |
+
if base_name not in image_basenames:
|
| 28 |
+
os.remove(os.path.join(folder_path, text_file))
|
| 29 |
+
print(f'Removed text file without corresponding image file: {text_file}')
|