Anustup commited on
Commit
94273fe
·
verified ·
1 Parent(s): aaf361a

Delete a.py

Browse files
Files changed (1) hide show
  1. a.py +0 -63
a.py DELETED
@@ -1,63 +0,0 @@
1
- import streamlit as st
2
- import os
3
- from PIL import Image
4
- from collections import Counter
5
-
6
- # Function to list files with given extensions
7
- def list_files(folder_path, extensions):
8
- files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
9
- return [f for f in files if f.split('.')[-1] in extensions]
10
-
11
- # Function to get tag frequencies from text files
12
- def get_tag_frequencies(text_files):
13
- tag_counter = Counter()
14
- for text_file in text_files:
15
- with open(text_file, 'r') as file:
16
- tags = file.read().split()
17
- tag_counter.update(tags)
18
- return tag_counter
19
-
20
- # Set up Streamlit app
21
- st.title("Display Images and Corresponding Text Files")
22
-
23
- # Define the folder path
24
- folder_path = "/home/caimera-prod/kohya_new_dataset"
25
-
26
- # List of allowed image and text extensions
27
- image_extensions = ['jpg', 'jpeg', 'png']
28
- text_extensions = ['txt']
29
-
30
- # Get the list of image and text files
31
- files = list_files(folder_path, image_extensions + text_extensions)
32
-
33
- # Filter files into images and texts
34
- images = [f for f in files if f.split('.')[-1] in image_extensions]
35
- texts = [f for f in files if f.split('.')[-1] in text_extensions]
36
-
37
- # Create a dictionary to map image files to their corresponding text files
38
- file_map = {}
39
- for image in images:
40
- base_name = os.path.splitext(image)[0]
41
- corresponding_text = base_name + '.txt'
42
- if corresponding_text in texts:
43
- file_map[image] = corresponding_text
44
-
45
- # Get tag frequencies
46
- text_files_paths = [os.path.join(folder_path, text) for text in texts]
47
- tag_frequencies = get_tag_frequencies(text_files_paths)
48
-
49
- # Display tag frequencies
50
- st.subheader("Tag Frequencies")
51
- for tag, freq in tag_frequencies.most_common():
52
- st.write(f"{tag}: {freq}")
53
-
54
- # Display images and text files side by side
55
- for image_file, text_file in file_map.items():
56
- col1, col2 = st.columns(2)
57
-
58
- with col1:
59
- st.image(os.path.join(folder_path, image_file), caption=image_file, use_column_width=True)
60
-
61
- with col2:
62
- with open(os.path.join(folder_path, text_file), 'r') as file:
63
- st.text_area(text_file, file.read(), height=300)