inie2003 commited on
Commit
022e3b7
·
verified ·
1 Parent(s): d936000

added console info

Browse files
Files changed (1) hide show
  1. app.py +25 -20
app.py CHANGED
@@ -1,11 +1,16 @@
1
  import streamlit as st
 
 
 
 
2
  from helper import (
3
  load_dataset, search, get_file_paths,
4
  get_cordinates, get_images_from_s3_to_display,
5
  get_images_with_bounding_boxes_from_s3, load_dataset_with_limit
6
  )
7
- import os
8
- import time
 
9
 
10
  # Load environment variables
11
  AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
@@ -15,8 +20,8 @@ AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
15
  datasets = ["WayveScenes", "MajorTom-Europe"]
16
  description = {
17
  "StopSign_test": "A test dataset for me",
18
- "WayveScenes": "A large-scale dataset featuring diverse urban driving scenes, captured from autonomous vehicles to advance AI perception and navigation in complex environments.",
19
- "MajorTom-Europe": "A geospatial dataset containing satellite imagery from across Europe, designed for tasks like land-use classification, environmental monitoring, and earth observation analytics."
20
  }
21
  selection = {
22
  'WayveScenes': [1, 8],
@@ -26,19 +31,24 @@ selection = {
26
  # AWS S3 bucket name
27
  bucket_name = "datasets-quasara-io"
28
 
 
 
 
 
 
 
29
  # Streamlit App
30
  def main():
31
  # Initialize session state variables if not already initialized
32
  if 'search_in_small_objects' not in st.session_state:
33
  st.session_state.search_in_small_objects = False
34
-
35
  if 'dataset_number' not in st.session_state:
36
  st.session_state.dataset_number = 1
37
-
38
  if 'df' not in st.session_state:
39
  st.session_state.df = None
40
 
41
  st.title("Semantic Search and Image Display")
 
42
 
43
  # Select dataset from dropdown
44
  dataset_name = st.selectbox("Select Dataset", datasets)
@@ -54,12 +64,10 @@ def main():
54
  st.session_state.search_in_small_objects = True
55
  st.text("Small Object Search Enabled")
56
  st.session_state.dataset_number = st.selectbox("Select Subset of Data", list(range(1, selection[dataset_name][1] + 1)))
57
- st.text(f"You have selected Split Dataset {st.session_state.dataset_number}")
58
  else:
59
  st.session_state.search_in_small_objects = False
60
  st.text("Small Object Search Disabled")
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.')
@@ -67,28 +75,26 @@ def main():
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)
 
78
  # Simulate dataset loading progress
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
@@ -104,25 +110,23 @@ def main():
104
  st.warning("Please enter a search query.")
105
  else:
106
  try:
107
- # Progress bar for search
108
  search_loading_text = st.empty()
109
  search_loading_text.text("Searching...")
110
  search_progress_bar = st.progress(0)
111
 
112
- # Perform search on the loaded dataset from session state
113
  df = st.session_state.df
114
  if st.session_state.search_in_small_objects:
115
  results = search(query, df, limit)
116
  top_k_paths = get_file_paths(df, results)
117
  top_k_cordinates = get_cordinates(df, results)
118
  else:
119
- # Normal Search
120
  results = search(query, df, limit)
121
  top_k_paths = get_file_paths(df, results)
122
 
123
- # Complete the search progress
124
  search_progress_bar.progress(100)
125
  search_loading_text.text("Search completed!")
 
126
 
127
  # Load Images with Bounding Boxes if applicable
128
  if st.session_state.search_in_small_objects and top_k_paths and top_k_cordinates:
@@ -134,6 +138,7 @@ def main():
134
  st.write("No results found.")
135
 
136
  except Exception as e:
 
137
  st.error(f"Search failed: {e}")
138
 
139
  if __name__ == "__main__":
 
1
  import streamlit as st
2
+ import logging
3
+ import os
4
+ import time
5
+ import psutil
6
  from helper import (
7
  load_dataset, search, get_file_paths,
8
  get_cordinates, get_images_from_s3_to_display,
9
  get_images_with_bounding_boxes_from_s3, load_dataset_with_limit
10
  )
11
+
12
+ # Configure logging
13
+ logging.basicConfig(level=logging.INFO)
14
 
15
  # Load environment variables
16
  AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
 
20
  datasets = ["WayveScenes", "MajorTom-Europe"]
21
  description = {
22
  "StopSign_test": "A test dataset for me",
23
+ "WayveScenes": "A large-scale dataset featuring diverse urban driving scenes.",
24
+ "MajorTom-Europe": "A geospatial dataset containing satellite imagery from across Europe."
25
  }
26
  selection = {
27
  'WayveScenes': [1, 8],
 
31
  # AWS S3 bucket name
32
  bucket_name = "datasets-quasara-io"
33
 
34
+ # Function to log CPU and memory usage
35
+ def log_resource_usage(stage):
36
+ cpu_usage = psutil.cpu_percent(interval=1)
37
+ memory_info = psutil.virtual_memory()
38
+ logging.info(f"{stage} - CPU Usage: {cpu_usage}%, Memory Usage: {memory_info.percent}%")
39
+
40
  # Streamlit App
41
  def main():
42
  # Initialize session state variables if not already initialized
43
  if 'search_in_small_objects' not in st.session_state:
44
  st.session_state.search_in_small_objects = False
 
45
  if 'dataset_number' not in st.session_state:
46
  st.session_state.dataset_number = 1
 
47
  if 'df' not in st.session_state:
48
  st.session_state.df = None
49
 
50
  st.title("Semantic Search and Image Display")
51
+ log_resource_usage("Initialization")
52
 
53
  # Select dataset from dropdown
54
  dataset_name = st.selectbox("Select Dataset", datasets)
 
64
  st.session_state.search_in_small_objects = True
65
  st.text("Small Object Search Enabled")
66
  st.session_state.dataset_number = st.selectbox("Select Subset of Data", list(range(1, selection[dataset_name][1] + 1)))
 
67
  else:
68
  st.session_state.search_in_small_objects = False
69
  st.text("Small Object Search Disabled")
70
  st.session_state.dataset_number = st.selectbox("Select Subset of Data", list(range(1, selection[dataset_name][0] + 1)))
 
71
 
72
  dataset_limit = st.slider("Size of Dataset to be searched from", min_value=1000, max_value=20000, value=10000)
73
  st.text(f'The smaller the dataset, the faster the search will work.')
 
75
  # Load dataset with limit only if not already loaded
76
  if st.button("Load Dataset"):
77
  try:
 
 
 
 
 
78
  loading_dataset_text = st.empty()
79
  loading_dataset_text.text("Loading Dataset...")
80
  loading_dataset_bar = st.progress(0)
81
+
82
  # Simulate dataset loading progress
83
  for i in range(0, 100, 25):
84
+ time.sleep(0.2)
85
  loading_dataset_bar.progress(i + 25)
86
 
87
+ log_resource_usage("Before Loading Dataset")
88
  df, total_rows = load_dataset_with_limit(dataset_name, st.session_state.dataset_number, st.session_state.search_in_small_objects, limit=dataset_limit)
 
89
  st.session_state.df = df
90
+
91
  loading_dataset_bar.progress(100)
92
  loading_dataset_text.text("Dataset loaded successfully!")
93
  st.success(f"Dataset loaded successfully with {len(df)} rows.")
94
+ log_resource_usage("After Loading Dataset")
95
 
96
  except Exception as e:
97
+ logging.error(f"Failed to load dataset: {e}")
98
  st.error(f"Failed to load dataset: {e}")
99
 
100
  # Input search query
 
110
  st.warning("Please enter a search query.")
111
  else:
112
  try:
 
113
  search_loading_text = st.empty()
114
  search_loading_text.text("Searching...")
115
  search_progress_bar = st.progress(0)
116
 
117
+ log_resource_usage("Before Search")
118
  df = st.session_state.df
119
  if st.session_state.search_in_small_objects:
120
  results = search(query, df, limit)
121
  top_k_paths = get_file_paths(df, results)
122
  top_k_cordinates = get_cordinates(df, results)
123
  else:
 
124
  results = search(query, df, limit)
125
  top_k_paths = get_file_paths(df, results)
126
 
 
127
  search_progress_bar.progress(100)
128
  search_loading_text.text("Search completed!")
129
+ log_resource_usage("After Search")
130
 
131
  # Load Images with Bounding Boxes if applicable
132
  if st.session_state.search_in_small_objects and top_k_paths and top_k_cordinates:
 
138
  st.write("No results found.")
139
 
140
  except Exception as e:
141
+ logging.error(f"Search failed: {e}")
142
  st.error(f"Search failed: {e}")
143
 
144
  if __name__ == "__main__":