gmmcleod commited on
Commit
1dcc2ae
·
verified ·
1 Parent(s): 82d18b3

revert back

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -42,7 +42,7 @@ def fetch_required_files(exp_config):
42
  return exp_config
43
 
44
 
45
- def call_flask_server(modelname):
46
  url = "https://saraht14-server.hf.space/"
47
 
48
  try:
@@ -148,7 +148,7 @@ def install_requirements(file_path):
148
  print(f"Error: {file_path} not found.")
149
  except subprocess.CalledProcessError as e:
150
  print(f"Installation failed: {e}")
151
- HEADERS = ["Model Name", "Group Name", "Execution Time (s)", "Accuracy", "TP", "FP", "FN", "TN"]
152
  BASE = {'ottawa':(45.30326753851309,-75.93640391349997),
153
  'ali_home':(37.88560412289598,-122.30218612514359),
154
  'josh_home':(37.8697406, -122.30218612514359),
@@ -173,11 +173,6 @@ def fetch_lb():
173
  try:
174
  leaderboard_dataset = load_dataset("saraht14/responses", split="train", token=HF_TOKEN)
175
  leaderboard_data = leaderboard_dataset.to_pandas()
176
-
177
- for col in HEADERS:
178
- if col not in leaderboard_data.columns:
179
- leaderboard_data[col] = "N/A"
180
-
181
  leaderboard_data = leaderboard_data[HEADERS] # keep it ordered
182
  leaderboard_data = leaderboard_data.sort_values(by=["Accuracy", "Execution Time (s)"], ascending=[False, True])
183
  except Exception as e:
@@ -246,15 +241,15 @@ def read_configuration(filename):
246
 
247
 
248
 
249
- def evaluate_model(modelname, groupname, file):
250
  print("evaluating...")
251
  global leaderboard_data
252
 
253
- modelname = modelname.strip()
254
- if not modelname:
255
  return leaderboard_data.values.tolist()
256
 
257
- script_path = f"submissions/{modelname}.py"
258
  os.makedirs("submissions", exist_ok=True)
259
 
260
  # # Get the file path from the NamedString object
@@ -339,12 +334,12 @@ def evaluate_model(modelname, groupname, file):
339
  status = "Success" if accuracy > 0 else "Incorrect Model"
340
  # ["Username", "Execution Time (s)", "Accuracy", "True Positive", "False Positive", "False Negative", "False Positive"]
341
  except Exception as e:
342
- leaderboard_data = pd.concat([leaderboard_data, pd.DataFrame([[modelname, groupname, float("inf"), 0,-1,-1,-1,-1]],
343
  columns=HEADERS)], ignore_index=True)
344
  return leaderboard_data.values.tolist()
345
  print("calculating new entry")
346
 
347
- new_entry = pd.DataFrame([[modelname, groupname, execution_time, accuracy, TP, FP, FN, TN]],
348
  columns=HEADERS)
349
  print("updating new entry")
350
  leaderboard_data = update_results_dataset(new_entry)
@@ -429,13 +424,13 @@ def import_and_run_function(script_path, function_name, filename):
429
 
430
 
431
 
432
- def update_leaderboard(modelname, groupname, zip_file):
433
  if not zip_file:
434
  set_error_message("No file uploaded.")
435
  return get_error_message(), None
436
 
437
  zip_path = zip_file.name
438
- extract_path = os.path.join("", modelname)
439
  # if not os.path.exists(extract_path):
440
  # os.makedirs(extract_path)
441
 
@@ -494,7 +489,7 @@ def update_leaderboard(modelname, groupname, zip_file):
494
  return "No Python script (main.py) found in ZIP.", None
495
 
496
  try:
497
- updated_leaderboard = evaluate_model(modelname, groupname, python_script)
498
 
499
  if updated_leaderboard == None:
500
  return "An error occured while evaluting the model", None
@@ -516,8 +511,7 @@ with gr.Blocks() as demo:
516
  gr.Markdown("# 🚀 Indoor vs Outdoor Detection Leaderboard \nUsing the provided dataset, submit a model that can predict if a device is inside or outside. \nSee the README for submission details.")
517
 
518
  with gr.Row():
519
- modelname_input = gr.Textbox(label="Model Name")
520
- groupname_input = gr.Textbox(label = "Group Name")
521
  file_input = gr.File(label="Upload Zip File")
522
  submit_button = gr.Button("Submit File")
523
 
@@ -532,7 +526,7 @@ with gr.Blocks() as demo:
532
 
533
 
534
  submit_button.click(fn=update_leaderboard,
535
- inputs=[modelname_input, groupname_input, file_input],
536
  outputs=[status_output, leaderboard_display])
537
 
538
  status_output.change(fn=get_error_message, inputs=[], outputs=status_output)
 
42
  return exp_config
43
 
44
 
45
+ def call_flask_server(username):
46
  url = "https://saraht14-server.hf.space/"
47
 
48
  try:
 
148
  print(f"Error: {file_path} not found.")
149
  except subprocess.CalledProcessError as e:
150
  print(f"Installation failed: {e}")
151
+ HEADERS = ["Username", "Execution Time (s)", "Accuracy", "TP", "FP", "FN", "TN"]
152
  BASE = {'ottawa':(45.30326753851309,-75.93640391349997),
153
  'ali_home':(37.88560412289598,-122.30218612514359),
154
  'josh_home':(37.8697406, -122.30218612514359),
 
173
  try:
174
  leaderboard_dataset = load_dataset("saraht14/responses", split="train", token=HF_TOKEN)
175
  leaderboard_data = leaderboard_dataset.to_pandas()
 
 
 
 
 
176
  leaderboard_data = leaderboard_data[HEADERS] # keep it ordered
177
  leaderboard_data = leaderboard_data.sort_values(by=["Accuracy", "Execution Time (s)"], ascending=[False, True])
178
  except Exception as e:
 
241
 
242
 
243
 
244
+ def evaluate_model(username, file):
245
  print("evaluating...")
246
  global leaderboard_data
247
 
248
+ username = username.strip()
249
+ if not username:
250
  return leaderboard_data.values.tolist()
251
 
252
+ script_path = f"submissions/{username}.py"
253
  os.makedirs("submissions", exist_ok=True)
254
 
255
  # # Get the file path from the NamedString object
 
334
  status = "Success" if accuracy > 0 else "Incorrect Model"
335
  # ["Username", "Execution Time (s)", "Accuracy", "True Positive", "False Positive", "False Negative", "False Positive"]
336
  except Exception as e:
337
+ leaderboard_data = pd.concat([leaderboard_data, pd.DataFrame([[username, float("inf"), 0,-1,-1,-1,-1]],
338
  columns=HEADERS)], ignore_index=True)
339
  return leaderboard_data.values.tolist()
340
  print("calculating new entry")
341
 
342
+ new_entry = pd.DataFrame([[username, execution_time, accuracy, TP, FP, FN, TN]],
343
  columns=HEADERS)
344
  print("updating new entry")
345
  leaderboard_data = update_results_dataset(new_entry)
 
424
 
425
 
426
 
427
+ def update_leaderboard(username, zip_file):
428
  if not zip_file:
429
  set_error_message("No file uploaded.")
430
  return get_error_message(), None
431
 
432
  zip_path = zip_file.name
433
+ extract_path = os.path.join("", username)
434
  # if not os.path.exists(extract_path):
435
  # os.makedirs(extract_path)
436
 
 
489
  return "No Python script (main.py) found in ZIP.", None
490
 
491
  try:
492
+ updated_leaderboard = evaluate_model(username, python_script)
493
 
494
  if updated_leaderboard == None:
495
  return "An error occured while evaluting the model", None
 
511
  gr.Markdown("# 🚀 Indoor vs Outdoor Detection Leaderboard \nUsing the provided dataset, submit a model that can predict if a device is inside or outside. \nSee the README for submission details.")
512
 
513
  with gr.Row():
514
+ username_input = gr.Textbox(label="Model Name")
 
515
  file_input = gr.File(label="Upload Zip File")
516
  submit_button = gr.Button("Submit File")
517
 
 
526
 
527
 
528
  submit_button.click(fn=update_leaderboard,
529
+ inputs=[username_input, file_input],
530
  outputs=[status_output, leaderboard_display])
531
 
532
  status_output.change(fn=get_error_message, inputs=[], outputs=status_output)