added clear old dataset before loading new one
Browse files
app.py
CHANGED
@@ -61,13 +61,17 @@ def main():
|
|
61 |
st.session_state.dataset_number = st.selectbox("Select Subset of Data", list(range(1, selection[dataset_name][0] + 1)))
|
62 |
st.text(f"You have selected Main Dataset {st.session_state.dataset_number}")
|
63 |
|
64 |
-
|
65 |
dataset_limit = st.slider("Size of Dataset to be searched from", min_value=1000, max_value=20000, value=10000)
|
66 |
-
st.text(f'The smaller the dataset the faster the search will work.')
|
67 |
-
|
68 |
# Load dataset with limit only if not already loaded
|
69 |
if st.button("Load Dataset"):
|
70 |
try:
|
|
|
|
|
|
|
|
|
|
|
71 |
loading_dataset_text = st.empty()
|
72 |
loading_dataset_text.text("Loading Dataset...")
|
73 |
loading_dataset_bar = st.progress(0)
|
@@ -75,17 +79,18 @@ def main():
|
|
75 |
for i in range(0, 100, 25):
|
76 |
time.sleep(0.2) # Simulate work being done
|
77 |
loading_dataset_bar.progress(i + 25)
|
|
|
|
|
78 |
df, total_rows = load_dataset_with_limit(dataset_name, st.session_state.dataset_number, st.session_state.search_in_small_objects, limit=dataset_limit)
|
79 |
# Store loaded dataset in session state
|
80 |
st.session_state.df = df
|
81 |
loading_dataset_bar.progress(100)
|
82 |
loading_dataset_text.text("Dataset loaded successfully!")
|
83 |
st.success(f"Dataset loaded successfully with {len(df)} rows.")
|
84 |
-
|
85 |
except Exception as e:
|
86 |
st.error(f"Failed to load dataset: {e}")
|
87 |
-
|
88 |
-
|
89 |
# Input search query
|
90 |
query = st.text_input("Enter your search query")
|
91 |
|
@@ -125,7 +130,6 @@ def main():
|
|
125 |
elif not st.session_state.search_in_small_objects and top_k_paths:
|
126 |
st.write(f"Displaying top {len(top_k_paths)} results for query '{query}':")
|
127 |
get_images_from_s3_to_display(bucket_name, top_k_paths, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
|
128 |
-
|
129 |
else:
|
130 |
st.write("No results found.")
|
131 |
|
|
|
61 |
st.session_state.dataset_number = st.selectbox("Select Subset of Data", list(range(1, selection[dataset_name][0] + 1)))
|
62 |
st.text(f"You have selected Main Dataset {st.session_state.dataset_number}")
|
63 |
|
|
|
64 |
dataset_limit = st.slider("Size of Dataset to be searched from", min_value=1000, max_value=20000, value=10000)
|
65 |
+
st.text(f'The smaller the dataset, the faster the search will work.')
|
66 |
+
|
67 |
# Load dataset with limit only if not already loaded
|
68 |
if st.button("Load Dataset"):
|
69 |
try:
|
70 |
+
# Clear old dataset from memory
|
71 |
+
if st.session_state.df is not None:
|
72 |
+
st.session_state.df = None # Clear the old dataset
|
73 |
+
st.info("Previous dataset cleared from memory.")
|
74 |
+
|
75 |
loading_dataset_text = st.empty()
|
76 |
loading_dataset_text.text("Loading Dataset...")
|
77 |
loading_dataset_bar = st.progress(0)
|
|
|
79 |
for i in range(0, 100, 25):
|
80 |
time.sleep(0.2) # Simulate work being done
|
81 |
loading_dataset_bar.progress(i + 25)
|
82 |
+
|
83 |
+
# Load new dataset
|
84 |
df, total_rows = load_dataset_with_limit(dataset_name, st.session_state.dataset_number, st.session_state.search_in_small_objects, limit=dataset_limit)
|
85 |
# Store loaded dataset in session state
|
86 |
st.session_state.df = df
|
87 |
loading_dataset_bar.progress(100)
|
88 |
loading_dataset_text.text("Dataset loaded successfully!")
|
89 |
st.success(f"Dataset loaded successfully with {len(df)} rows.")
|
90 |
+
|
91 |
except Exception as e:
|
92 |
st.error(f"Failed to load dataset: {e}")
|
93 |
+
|
|
|
94 |
# Input search query
|
95 |
query = st.text_input("Enter your search query")
|
96 |
|
|
|
130 |
elif not st.session_state.search_in_small_objects and top_k_paths:
|
131 |
st.write(f"Displaying top {len(top_k_paths)} results for query '{query}':")
|
132 |
get_images_from_s3_to_display(bucket_name, top_k_paths, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
|
|
|
133 |
else:
|
134 |
st.write("No results found.")
|
135 |
|