HFswapnil commited on
Commit
1713300
ยท
verified ยท
1 Parent(s): 0418abf

Update src/main.py

Browse files
Files changed (1) hide show
  1. src/main.py +99 -40
src/main.py CHANGED
@@ -4,14 +4,7 @@ import sqlite3
4
  import hashlib
5
  from datetime import datetime
6
  from localization_eval import evaluate_submission
7
- import logging
8
-
9
- logging.basicConfig(level=logging.INFO) # Configure the root logger
10
-
11
- logging.basicConfig(
12
- format='%(asctime)s - %(levelname)s - %(message)s',
13
- level=logging.INFO
14
- )
15
 
16
  # --- CONFIGURATION & SETUP ---
17
  st.set_page_config(
@@ -24,6 +17,15 @@ st.set_page_config(
24
  DB_NAME = "./benchmark.db"
25
 
26
 
 
 
 
 
 
 
 
 
 
27
  def init_db():
28
  conn = sqlite3.connect(DB_NAME)
29
  c = conn.cursor()
@@ -33,7 +35,7 @@ def init_db():
33
  # Submissions Table
34
  c.execute('''CREATE TABLE IF NOT EXISTS submissions
35
  (id INTEGER PRIMARY KEY AUTOINCREMENT,
36
- username TEXT, score REAL, timestamp DATETIME)''')
37
  conn.commit()
38
  conn.close()
39
 
@@ -67,24 +69,44 @@ def login_user(username, password):
67
  conn.close()
68
  return data
69
 
70
- def save_submission(username, score):
71
  conn = sqlite3.connect(DB_NAME)
72
  c = conn.cursor()
73
- c.execute('INSERT INTO submissions(username, score, timestamp) VALUES (?,?,?)',
74
- (username, score, datetime.now()))
75
  conn.commit()
76
  conn.close()
77
 
 
 
 
78
  def get_leaderboard_data():
79
  conn = sqlite3.connect(DB_NAME)
80
  # Get the BEST score for each user
81
  query = """
82
- SELECT username, MAX(score) as best_accuracy, MAX(timestamp) as last_submission
83
- FROM submissions
84
- GROUP BY username
85
- ORDER BY best_accuracy DESC
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  """
87
  df = pd.read_sql_query(query, conn)
 
 
 
88
  conn.close()
89
  return df
90
 
@@ -131,16 +153,46 @@ def main_app():
131
  st.session_state['username'] = None
132
  st.rerun()
133
 
134
- # --- PAGE: SUBMIT MODEL ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  if choice == "Submit Model":
136
  st.header("๐Ÿš€ Submit your Predictions")
137
 
 
 
138
  col1, col2 = st.columns([2, 1])
139
 
140
  with col1:
141
  # st.info("Upload your CSV file. It must contain `id` and `prediction` columns.")
142
- uploaded_file = st.file_uploader("Choose a CSV file", type="json")
143
 
 
144
 
145
  if uploaded_file is not None:
146
  save_path = f"./{uploaded_file.name}"
@@ -149,28 +201,23 @@ def main_app():
149
  with open(save_path, "wb") as f:
150
  f.write(uploaded_file.getbuffer())
151
 
152
-
153
  if st.button("Evaluate"):
154
  with st.spinner('Calculating score against Ground Truth...'):
155
- logging.info("Calculating Score....")
156
- logging.info(f"File location : {save_path}")
157
- score = evaluate_submission("src/biv_query.json", save_path)
158
- logging.info(f"Score Calculation Complete : {score}")
159
- st.success(f"Score : {score}")
160
- if score is not None:
161
- save_submission(st.session_state['username'], score)
162
  st.balloons()
163
  st.success("Submission Successful!")
164
 
165
  # Display Metrics
166
- st.metric(label="Your Model Accuracy Score", value=f"{score}%")
167
 
168
- with col2:
169
- st.markdown("### Sample Format")
170
- st.dataframe(pd.DataFrame({'id': [1, 2], 'prediction': [100, 205]}), hide_index=True)
171
 
172
- # --- PAGE: LEADERBOARD ---
173
  elif choice == "Leaderboard":
 
174
 
175
  st.header("๐Ÿ† Leaderboard")
176
  st.write("Rankings based on the highest accuracy score achieved.")
@@ -178,19 +225,28 @@ def main_app():
178
  df_leaderboard = get_leaderboard_data()
179
 
180
  if not df_leaderboard.empty:
181
- # styling the leaderboard
 
 
 
182
  st.dataframe(
183
  df_leaderboard,
184
  column_config={
 
185
  "username": "Participant",
186
- "best_accuracy": st.column_config.ProgressColumn(
187
- "Accuracy Score",
188
- format="%.2f%%",
189
- min_value=0,
190
- max_value=100,
191
  ),
 
 
 
 
 
192
  "last_submission": st.column_config.DatetimeColumn(
193
- "Last Active",
194
  format="D MMM YYYY, h:mm a",
195
  ),
196
  },
@@ -198,11 +254,14 @@ def main_app():
198
  hide_index=True,
199
  )
200
  else:
201
- st.info("No submissions yet. Be the first!")
202
 
 
203
  if __name__ == '__main__':
204
  init_db()
205
-
 
 
206
  # Session State Initialization
207
  if 'logged_in' not in st.session_state:
208
  st.session_state['logged_in'] = False
 
4
  import hashlib
5
  from datetime import datetime
6
  from localization_eval import evaluate_submission
7
+ from PIL import Image
 
 
 
 
 
 
 
8
 
9
  # --- CONFIGURATION & SETUP ---
10
  st.set_page_config(
 
17
  DB_NAME = "./benchmark.db"
18
 
19
 
20
+ def see_entire_table():
21
+ conn = sqlite3.connect(DB_NAME)
22
+ c = conn.cursor()
23
+ c.execute('SELECT * FROM submissions')
24
+ conn.commit()
25
+ conn.close()
26
+
27
+
28
+
29
  def init_db():
30
  conn = sqlite3.connect(DB_NAME)
31
  c = conn.cursor()
 
35
  # Submissions Table
36
  c.execute('''CREATE TABLE IF NOT EXISTS submissions
37
  (id INTEGER PRIMARY KEY AUTOINCREMENT,
38
+ username TEXT, bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 , timestamp DATETIME)''')
39
  conn.commit()
40
  conn.close()
41
 
 
69
  conn.close()
70
  return data
71
 
72
+ def save_submission(username, bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 ):
73
  conn = sqlite3.connect(DB_NAME)
74
  c = conn.cursor()
75
+ c.execute('INSERT INTO submissions(username, bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 , timestamp) VALUES (?,?, ?, ? ,? ,?)',
76
+ (username, bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 , datetime.now()))
77
  conn.commit()
78
  conn.close()
79
 
80
+
81
+
82
+
83
  def get_leaderboard_data():
84
  conn = sqlite3.connect(DB_NAME)
85
  # Get the BEST score for each user
86
  query = """
87
+ WITH BestScores AS (
88
+ SELECT
89
+ username,
90
+ MAX(bbox_mAP) as max_bbox_mAP
91
+ FROM submissions
92
+ GROUP BY username
93
+ )
94
+ SELECT
95
+ s.username,
96
+ s.bbox_mAP,
97
+ s.bbox_AP50,
98
+ s.segm_mAP,
99
+ s.segm_AP50,
100
+ MAX(s.timestamp) as last_submission -- MAX(timestamp) to get the most recent best submission
101
+ FROM submissions s
102
+ INNER JOIN BestScores b ON s.username = b.username AND s.bbox_mAP = b.max_bbox_mAP
103
+ GROUP BY s.username
104
+ ORDER BY s.bbox_mAP DESC, s.timestamp ASC
105
  """
106
  df = pd.read_sql_query(query, conn)
107
+ # Rename the column for display clarity
108
+ df = df.rename(columns={'bbox_mAP': 'Best_bbox_mAP'})
109
+
110
  conn.close()
111
  return df
112
 
 
153
  st.session_state['username'] = None
154
  st.rerun()
155
 
156
+ # --- NEW: Overview Expander ---
157
+ with st.expander("โ„น๏ธ Overview of the AI Benchmark Arena"):
158
+ # Placeholder for an informative image
159
+ st.markdown(
160
+ """
161
+ A natural application of computer vision is to assist blind people, whether that may be to overcome their daily visual challenges or break down their social accessibility barriers. BIV-Priv is proposed to preserve a blind person's visual privacy to ensure they can access visual-related tools safely.
162
+
163
+ VizWiz Challenge 2025 is the 1th edition of the Few-Shot Private Object Localization Challenge on the BIV-Priv dataset. To participate in the challenge, you can find instructions on the Challenge website.
164
+
165
+ Note: All the timings on the EvalAI platform are local to your timezone.
166
+ """
167
+ )
168
+ overview_image = Image.open("./overview_image.png").resize((600, 600))
169
+ st.image(overview_image, caption="Example of an object localization task", )
170
+
171
+ # --- NEW: Evaluation Expander ---
172
+ with st.expander("๐Ÿ“ How is the Score Calculated?"):
173
+ st.markdown(
174
+ """
175
+ Terms and Conditions
176
+ The images and annotations in this dataset belong to the VizWiz team and are licensed under a Commons Attribution 4.0 International License.
177
+ Copyright ยฉ 2015, VizWiz team. All rights reserved. Redistribution and use software in source and binary form, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the VizWiz team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE AND ANNOTATIONS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
178
+ """
179
+ )
180
+
181
+ st.markdown("---") # Visual separator
182
+
183
+ # --- PAGE: SUBMIT MODEL (Existing Code) ---
184
  if choice == "Submit Model":
185
  st.header("๐Ÿš€ Submit your Predictions")
186
 
187
+ # ... (rest of the Submit Model code)
188
+
189
  col1, col2 = st.columns([2, 1])
190
 
191
  with col1:
192
  # st.info("Upload your CSV file. It must contain `id` and `prediction` columns.")
193
+ uploaded_file = st.file_uploader("Choose a JSON file", type="json") # Corrected type to 'json' based on localization_eval
194
 
195
+ # ... (rest of the submission logic)
196
 
197
  if uploaded_file is not None:
198
  save_path = f"./{uploaded_file.name}"
 
201
  with open(save_path, "wb") as f:
202
  f.write(uploaded_file.getbuffer())
203
 
 
204
  if st.button("Evaluate"):
205
  with st.spinner('Calculating score against Ground Truth...'):
206
+ # Ensure the ground truth path is correct
207
+ bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 = evaluate_submission("/src/biv_query.json", save_path)
208
+ st.success(f"bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 : {bbox_mAP, bbox_AP50, segm_mAP, segm_AP50}")
209
+ if bbox_mAP is not None and bbox_AP50 is not None and segm_mAP is not None and segm_AP50 is not None:
210
+ save_submission(st.session_state['username'], bbox_mAP, bbox_AP50, segm_mAP, segm_AP50 )
 
 
211
  st.balloons()
212
  st.success("Submission Successful!")
213
 
214
  # Display Metrics
215
+ st.metric(label="Result : ", value=f"{bbox_mAP, bbox_AP50, segm_mAP, segm_AP50}%")
216
 
 
 
 
217
 
218
+ # --- PAGE: LEADERBOARD (Existing Code) ---
219
  elif choice == "Leaderboard":
220
+ # ... (rest of the Leaderboard code)
221
 
222
  st.header("๐Ÿ† Leaderboard")
223
  st.write("Rankings based on the highest accuracy score achieved.")
 
225
  df_leaderboard = get_leaderboard_data()
226
 
227
  if not df_leaderboard.empty:
228
+ # Add a Rank column
229
+ df_leaderboard.insert(0, 'Rank', range(1, len(df_leaderboard) + 1))
230
+
231
+ # Apply formatting and configuration
232
  st.dataframe(
233
  df_leaderboard,
234
  column_config={
235
+ "Rank": st.column_config.Column("Rank", width="small"),
236
  "username": "Participant",
237
+ # The main ranking metric (bbox_mAP), formatted to 4 decimal places
238
+ "Best_bbox_mAP": st.column_config.NumberColumn(
239
+ "bbox_mAP (Primary)",
240
+ format="%.4f",
241
+ help="Best Bounding Box Mean Average Precision achieved."
242
  ),
243
+ # Other metrics, formatted as numbers without a progress bar
244
+ "bbox_AP50": st.column_config.NumberColumn("bbox_AP50", format="%.4f"),
245
+ "segm_mAP": st.column_config.NumberColumn("segm_mAP", format="%.4f"),
246
+ "segm_AP50": st.column_config.NumberColumn("segm_AP50", format="%.4f"),
247
+ # Datetime column configuration remains the same
248
  "last_submission": st.column_config.DatetimeColumn(
249
+ "Last Active Submission",
250
  format="D MMM YYYY, h:mm a",
251
  ),
252
  },
 
254
  hide_index=True,
255
  )
256
  else:
257
+ st.info("No submissions yet. Be the first to submit your model!")
258
 
259
+
260
  if __name__ == '__main__':
261
  init_db()
262
+ print("see entire table")
263
+ see_entire_table()
264
+ print("---------------------------")
265
  # Session State Initialization
266
  if 'logged_in' not in st.session_state:
267
  st.session_state['logged_in'] = False