BlendMMM commited on
Commit
23b7e72
·
verified ·
1 Parent(s): 89eaeae

Update Home.py

Browse files
Files changed (1) hide show
  1. Home.py +114 -114
Home.py CHANGED
@@ -1,114 +1,114 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import os
4
- import base64
5
- from pathlib import Path
6
- import streamlit as st
7
- import os
8
- from PIL import Image
9
-
10
-
11
- # path = os.path.dirname(__file__)
12
- # file_ = open(f"{path}/logo.png", "rb")
13
- # contents = file_.read()
14
- # data_url = base64.b64encode(contents).decode("utf-8")
15
- # file_.close()
16
-
17
- # def load_local_css(file_name):
18
- # with open(file_name) as f:
19
- # st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
20
-
21
- # def set_header():
22
- # return st.markdown(
23
- # f"""<div class='main-header'>
24
- # <h1>Synthetic Control</h1>
25
- # <img src="data:image;base64,{data_url}", alt="Logo">
26
- # </div>""",
27
- # unsafe_allow_html=True,
28
- # )
29
-
30
-
31
- st.set_page_config()
32
- # load_local_css("styles.css")
33
- # set_header()
34
-
35
- st.title("The Art of Words: Vachana's Collection")
36
-
37
-
38
- def load_images_from_folder(folder_path):
39
- """
40
- Load all images from the specified folder and store them in a dictionary.
41
-
42
- Args:
43
- folder_path (str): Path to the folder containing images.
44
-
45
- Returns:
46
- dict: A dictionary with image filenames as keys and PIL Image objects as values.
47
- """
48
- images_dict = {}
49
- try:
50
- for filename in os.listdir(folder_path):
51
- if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
52
- img_path = os.path.join(folder_path, filename)
53
- images_dict[filename] = Image.open(img_path)
54
- except Exception as e:
55
- st.error(f"Error loading images: {e}")
56
- return images_dict
57
-
58
-
59
- # Folder selection
60
- with st.expander("Click to Discover the Masterpiece"):
61
- folder_path = 'Photos'
62
- def load_images_from_folder(folder_path, target_size=(200, 200)):
63
- """
64
- Load all images from the specified folder, resize them to a uniform size, and store them in a dictionary.
65
-
66
- Args:
67
- folder_path (str): Path to the folder containing images.
68
- target_size (tuple): Desired size for all images (width, height).
69
-
70
- Returns:
71
- dict: A dictionary with image filenames as keys and resized PIL Image objects as values.
72
- """
73
- images_dict = {}
74
- try:
75
- for filename in os.listdir(folder_path):
76
- if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
77
- img_path = os.path.join(folder_path, filename)
78
- img = Image.open(img_path).convert("RGB") # Convert to RGB for consistency
79
- img = img.resize(target_size) # Resize image
80
- images_dict[filename] = img
81
- except Exception as e:
82
- st.error(f"Error loading images: {e}")
83
- return images_dict
84
-
85
- # Streamlit UI
86
- if folder_path:
87
- if not os.path.exists(folder_path):
88
- st.error("The specified folder path does not exist. Please enter a valid path.")
89
- else:
90
- # Load images
91
- images = load_images_from_folder(folder_path, target_size=(300, 400)) # Set desired size
92
-
93
- if images:
94
-
95
- # Display images side by side with a row break
96
- cols_per_row = 3 # Adjust the number of images displayed per row
97
- images_list = list(images.items())
98
-
99
- for i in range(0, len(images_list), cols_per_row):
100
- cols = st.columns(cols_per_row)
101
- for col, (img_name, img) in zip(cols, images_list[i:i + cols_per_row]):
102
- with col:
103
-
104
- st.image(img, use_column_width=True)
105
-
106
- # Add a break after each row
107
- st.divider() # Simple divider
108
- else:
109
- st.warning("No images found in the specified folder.")
110
- else:
111
- st.info("Please enter a folder path to load and display images.")
112
-
113
-
114
-
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import os
4
+ import base64
5
+ from pathlib import Path
6
+ import streamlit as st
7
+ import os
8
+ from PIL import Image
9
+
10
+
11
+ # path = os.path.dirname(__file__)
12
+ # file_ = open(f"{path}/logo.png", "rb")
13
+ # contents = file_.read()
14
+ # data_url = base64.b64encode(contents).decode("utf-8")
15
+ # file_.close()
16
+
17
+ # def load_local_css(file_name):
18
+ # with open(file_name) as f:
19
+ # st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
20
+
21
+ # def set_header():
22
+ # return st.markdown(
23
+ # f"""<div class='main-header'>
24
+ # <h1>Synthetic Control</h1>
25
+ # <img src="data:image;base64,{data_url}", alt="Logo">
26
+ # </div>""",
27
+ # unsafe_allow_html=True,
28
+ # )
29
+
30
+
31
+ st.set_page_config()
32
+ # load_local_css("styles.css")
33
+ # set_header()
34
+
35
+ st.title("The Art of Words: Vachana's Collection")
36
+
37
+
38
+ def load_images_from_folder(folder_path):
39
+ """
40
+ Load all images from the specified folder and store them in a dictionary.
41
+
42
+ Args:
43
+ folder_path (str): Path to the folder containing images.
44
+
45
+ Returns:
46
+ dict: A dictionary with image filenames as keys and PIL Image objects as values.
47
+ """
48
+ images_dict = {}
49
+ try:
50
+ for filename in os.listdir(folder_path):
51
+ if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
52
+ img_path = os.path.join(folder_path, filename)
53
+ images_dict[filename] = Image.open(img_path)
54
+ except Exception as e:
55
+ st.error(f"Error loading images: {e}")
56
+ return images_dict
57
+
58
+
59
+ # Folder selection
60
+ with st.expander("Click to Discover the Masterpiece"):
61
+ folder_path = 'Photos'
62
+ def load_images_from_folder(folder_path, target_size=(200, 200)):
63
+ """
64
+ Load all images from the specified folder, resize them to a uniform size, and store them in a dictionary.
65
+
66
+ Args:
67
+ folder_path (str): Path to the folder containing images.
68
+ target_size (tuple): Desired size for all images (width, height).
69
+
70
+ Returns:
71
+ dict: A dictionary with image filenames as keys and resized PIL Image objects as values.
72
+ """
73
+ images_dict = {}
74
+ try:
75
+ for filename in os.listdir(folder_path):
76
+ if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
77
+ img_path = os.path.join(folder_path, filename)
78
+ img = Image.open(img_path).convert("RGB") # Convert to RGB for consistency
79
+ img = img.resize(target_size) # Resize image
80
+ images_dict[filename] = img
81
+ except Exception as e:
82
+ st.error(f"Error loading images: {e}")
83
+ return images_dict
84
+
85
+ # Streamlit UI
86
+ if folder_path:
87
+ if not os.path.exists(folder_path):
88
+ st.error("The specified folder path does not exist. Please enter a valid path.")
89
+ else:
90
+ # Load images
91
+ images = load_images_from_folder(folder_path, target_size=(300, 400)) # Set desired size
92
+
93
+ if images:
94
+
95
+ # Display images side by side with a row break
96
+ cols_per_row = 3 # Adjust the number of images displayed per row
97
+ images_list = list(images.items())
98
+
99
+ for i in range(0, len(images_list), cols_per_row):
100
+ cols = st.columns(cols_per_row)
101
+ for col, (img_name, img) in zip(cols, images_list[i:i + cols_per_row]):
102
+ with col:
103
+
104
+ st.image(img, use_container_width=True)
105
+
106
+ # Add a break after each row
107
+ st.divider() # Simple divider
108
+ else:
109
+ st.warning("No images found in the specified folder.")
110
+ else:
111
+ st.info("Please enter a folder path to load and display images.")
112
+
113
+
114
+