HLMCC commited on
Commit
24b2c65
·
verified ·
1 Parent(s): a9821d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -42
app.py CHANGED
@@ -60,54 +60,59 @@ st.warning("Your CSV file must only contain the following columns:\n\n"
60
 
61
  # Form to upload CSV file
62
  with st.form("submission_form"):
63
- username = st.text_input("Username", max_chars=20)
64
  uploaded_file = st.file_uploader("Upload your prediction CSV file", type="csv")
65
  submit_button = st.form_submit_button("Submit")
66
 
67
  # Process submission
68
  if submit_button and uploaded_file:
69
- predictions = pd.read_csv(uploaded_file)
70
-
71
- # Check if file format is correct
72
- if "patient_id" in predictions.columns and "predicted_scores" in predictions.columns:
73
- # Merge with ground truth to calculate C-Index
74
- merged = pd.merge(ground_truth, predictions, on="patient_id", how="inner")
75
- if merged.empty:
76
- st.error("No matching patient IDs found between the ground truth and your submission. Please check your patient IDs.")
77
-
78
- c_index = concordance_index(event_times=merged["survival_time"],
79
- predicted_scores=merged["predicted_scores"],
80
- event_observed=merged["vital_status"],
81
- )
82
-
83
- # Save submission to file
84
- submission_file = submission_dir / f"{username}_{uploaded_file.name}"
85
- predictions.to_csv(submission_file, index=False)
86
-
87
- # Update leaderboard
88
- new_entry = pd.DataFrame({
89
- "Username": [username],
90
- "C-Index": [c_index],
91
- "Submission Date": [pd.Timestamp.now()],
92
- })
93
- leaderboard_df = pd.concat([leaderboard_df, new_entry], ignore_index=True)
94
-
95
- # Save updated leaderboard locally
96
- leaderboard_df.to_csv(leaderboard_file_path, index=False)
97
-
98
- # Upload updated leaderboard to Hugging Face
99
- upload_file(
100
- path_or_fileobj=leaderboard_file_path,
101
- path_in_repo="leaderboard.csv",
102
- repo_type="dataset",
103
- repo_id="HLMCC/tcga-paad-ground-truth",
104
- token=hf_token,
105
- )
106
-
107
- # Display the calculated C-Index to the user
108
- st.success(f"Submission received! Your C-Index score: {c_index:.4f}")
109
  else:
110
- st.error("Incorrect file format. Ensure columns include 'patient_id' and 'predicted_scores'.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  # Display the leaderboard
113
  st.subheader("Leaderboard")
 
60
 
61
  # Form to upload CSV file
62
  with st.form("submission_form"):
63
+ username = st.text_input("Username (required)", max_chars=20)
64
  uploaded_file = st.file_uploader("Upload your prediction CSV file", type="csv")
65
  submit_button = st.form_submit_button("Submit")
66
 
67
  # Process submission
68
  if submit_button and uploaded_file:
69
+ if not username.strip():
70
+ st.error("Username is required. Please enter your username.")
71
+ elif not uploaded_file:
72
+ st.error("Please upload your prediction CSV file.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  else:
74
+ predictions = pd.read_csv(uploaded_file)
75
+
76
+ # Check if file format is correct
77
+ if "patient_id" in predictions.columns and "predicted_scores" in predictions.columns:
78
+ # Merge with ground truth to calculate C-Index
79
+ merged = pd.merge(ground_truth, predictions, on="patient_id", how="inner")
80
+ if merged.empty:
81
+ st.error("No matching patient IDs found between the ground truth and your submission. Please check your patient IDs.")
82
+
83
+ c_index = concordance_index(event_times=merged["survival_time"],
84
+ predicted_scores=merged["predicted_scores"],
85
+ event_observed=merged["vital_status"],
86
+ )
87
+
88
+ # Save submission to file
89
+ submission_file = submission_dir / f"{username}_{uploaded_file.name}"
90
+ predictions.to_csv(submission_file, index=False)
91
+
92
+ # Update leaderboard
93
+ new_entry = pd.DataFrame({
94
+ "Username": [username],
95
+ "C-Index": [c_index],
96
+ "Submission Date": [pd.Timestamp.now()],
97
+ })
98
+ leaderboard_df = pd.concat([leaderboard_df, new_entry], ignore_index=True)
99
+
100
+ # Save updated leaderboard locally
101
+ leaderboard_df.to_csv(leaderboard_file_path, index=False)
102
+
103
+ # Upload updated leaderboard to Hugging Face
104
+ upload_file(
105
+ path_or_fileobj=leaderboard_file_path,
106
+ path_in_repo="leaderboard.csv",
107
+ repo_type="dataset",
108
+ repo_id="HLMCC/tcga-paad-ground-truth",
109
+ token=hf_token,
110
+ )
111
+
112
+ # Display the calculated C-Index to the user
113
+ st.success(f"Submission received! Your C-Index score: {c_index:.4f}")
114
+ else:
115
+ st.error("Incorrect file format. Ensure columns include 'patient_id' and 'predicted_scores'.")
116
 
117
  # Display the leaderboard
118
  st.subheader("Leaderboard")