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

Delete b.py

Browse files
Files changed (1) hide show
  1. b.py +0 -66
b.py DELETED
@@ -1,66 +0,0 @@
1
- import streamlit as st
2
- import os
3
- from PIL import Image
4
- from collections import Counter
5
- import pandas as pd
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
- # Prepare tag frequencies for display
50
- tag_frequencies_data = [{'Tag': tag, 'Frequency': freq} for tag, freq in tag_frequencies.items()]
51
- tag_frequencies_df = pd.DataFrame(tag_frequencies_data)
52
-
53
- # Display tag frequencies in a table
54
- st.subheader("Tag Frequencies")
55
- st.table(tag_frequencies_df)
56
-
57
- # Display images and text files side by side
58
- for image_file, text_file in file_map.items():
59
- col1, col2 = st.columns(2)
60
-
61
- with col1:
62
- st.image(os.path.join(folder_path, image_file), caption=image_file, use_column_width=True)
63
-
64
- with col2:
65
- with open(os.path.join(folder_path, text_file), 'r') as file:
66
- st.text_area(text_file, file.read(), height=300)