File size: 1,531 Bytes
4b0a67f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
from PIL import Image

# Function to list files with given extensions
def list_files(folder_path, extensions):
    files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
    return [f for f in files if f.split('.')[-1] in extensions]

# Set up Streamlit app
st.title("Display Images and Corresponding Text Files")

# Define the folder path
folder_path = "/home/caimera-prod/kohya_new_dataset"

# List of allowed image and text extensions
image_extensions = ['jpg', 'jpeg', 'png']
text_extensions = ['txt']

# Get the list of image and text files
files = list_files(folder_path, image_extensions + text_extensions)

# Filter files into images and texts
images = [f for f in files if f.split('.')[-1] in image_extensions]
texts = [f for f in files if f.split('.')[-1] in text_extensions]

# Create a dictionary to map image files to their corresponding text files
file_map = {}
for image in images:
    base_name = os.path.splitext(image)[0]
    corresponding_text = base_name + '.txt'
    if corresponding_text in texts:
        file_map[image] = corresponding_text

# Display images and text files side by side
for image_file, text_file in file_map.items():
    col1, col2 = st.columns(2)
    
    with col1:
        st.image(os.path.join(folder_path, image_file), caption=image_file, use_column_width=True)
    
    with col2:
        with open(os.path.join(folder_path, text_file), 'r') as file:
            st.text_area(text_file, file.read(), height=300)