Shiyu Zhao commited on
Commit
6161984
·
1 Parent(s): 3e890e9

Update space

Browse files
review_submission.py CHANGED
@@ -2,41 +2,59 @@ import json
2
  import os
3
  from datetime import datetime
4
  import glob
5
- from app import SubmissionForum
6
- from utils.hub_storage import HubStorage
7
 
 
8
 
 
 
 
 
 
9
 
10
- def read_json_file(file_path: str) -> dict:
11
- """Read and parse local JSON file."""
12
  try:
13
- with open(file_path, 'r') as f:
14
- return json.load(f)
 
 
 
15
  except Exception as e:
16
- print(f"Error reading {file_path}: {str(e)}")
17
- return None
18
 
19
- def update_json_file(file_path: str, content: dict, method_name: str = None, new_status: str = None) -> bool:
20
- """Update local JSON file and add forum post if status changed"""
21
  try:
22
- with open(file_path, 'w') as f:
23
- json.dump(content, f, indent=4)
24
-
25
- # Add forum post if this is a status update
26
- if method_name and new_status:
27
- forum.add_status_update(method_name, new_status)
28
-
29
- return True
 
 
 
30
  except Exception as e:
31
- print(f"Error updating {file_path}: {str(e)}")
32
- return False
 
 
 
 
 
 
 
33
 
34
  def review_pending_submissions(submissions_dir: str = "submissions"):
35
  """Review all pending submissions and allow admin to approve/reject them."""
36
  try:
37
- REPO_ID = "snap-stanford/stark-leaderboard"
38
- hub_storage = HubStorage(REPO_ID)
39
- forum = SubmissionForum(hub_storage=hub_storage)
40
  # Find all latest.json files
41
  latest_files = glob.glob(os.path.join(submissions_dir, "**", "latest.json"), recursive=True)
42
 
@@ -44,101 +62,101 @@ def review_pending_submissions(submissions_dir: str = "submissions"):
44
  print("No submissions found.")
45
  return
46
 
47
- changes_made = False
48
 
49
  # Process each submission
50
  for latest_file in latest_files:
51
- folder_path = os.path.dirname(latest_file)
52
- latest_info = read_json_file(latest_file)
53
-
54
- if not latest_info:
55
- print(f"Could not read {latest_file}, skipping...")
56
- continue
57
 
58
- if latest_info.get('status') != 'pending_review':
59
- continue
 
 
 
 
 
 
60
 
61
- # Find corresponding metadata file
62
- timestamp = latest_info.get('latest_submission')
63
- if not timestamp:
64
- print(f"No timestamp found in {latest_file}, skipping...")
65
- continue
 
 
66
 
67
- metadata_file = os.path.join(folder_path, f"metadata_{timestamp}.json")
68
- metadata = read_json_file(metadata_file)
69
-
70
- if not metadata:
71
- print(f"Could not read metadata for {latest_file}, skipping...")
72
- continue
73
-
74
- # Display submission details
75
- print("\n" + "="*80)
76
- print(f"Submission Details:")
77
- print(f"Method Name: {metadata.get('Method Name')}")
78
- print(f"Team Name: {metadata.get('Team Name')}")
79
- print(f"Dataset: {metadata.get('Dataset')}")
80
- print(f"Split: {metadata.get('Split')}")
81
- print(f"Contact Email(s): {metadata.get('Contact Email(s)')}")
82
- print(f"Code Repository: {metadata.get('Code Repository')}")
83
- print("\nModel Description:")
84
- print(metadata.get('Model Description', 'No description provided'))
85
- print("\nResults:")
86
- if 'results' in metadata:
87
- for metric, value in metadata['results'].items():
88
- print(f"{metric}: {value}")
89
- print("\nSubmission Date:", metadata.get('submission_date', 'Unknown'))
90
- print("="*80)
91
-
92
- # Get admin decision
93
- while True:
94
- decision = input("\nApprove this submission? (y/n/skip/quit): ").lower()
95
- if decision in ['y', 'n', 'skip', 'quit']:
96
  break
97
- print("Invalid input. Please enter 'y', 'n', 'skip', or 'quit'")
98
-
99
- if decision == 'quit':
100
- print("Exiting review process...")
101
- break
 
 
102
 
103
- if decision == 'skip':
104
- continue
 
 
 
 
105
 
106
- # Update status
107
- new_status = 'approved' if decision == 'y' else 'rejected'
108
- review_timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
109
-
110
- # Update latest.json
111
- latest_info['status'] = new_status
112
- latest_info['reviewed_at'] = review_timestamp
113
- if not update_json_file(
114
- latest_file,
115
- latest_info,
116
- method_name=metadata.get('Method Name'),
117
- new_status=new_status
118
- ):
119
- print("Failed to update latest.json")
120
- continue
121
-
122
- # Update metadata
123
- metadata['status'] = new_status
124
- metadata['reviewed_at'] = review_timestamp
125
- if not update_json_file(metadata_file, metadata):
126
- print("Failed to update metadata file")
127
  continue
128
-
129
- forum.add_status_update(metadata.get('Method Name'), new_status)
130
- print(f"Submission {new_status}")
131
- changes_made = True
132
-
133
  if changes_made:
134
- print("\nChanges have been made to the following files:")
135
- print("Please push these changes to HuggingFace manually.")
 
 
136
 
137
  except Exception as e:
138
  print(f"Error during review process: {str(e)}")
139
 
140
  if __name__ == "__main__":
141
  print("Starting submission review process...")
142
- # You can specify a different submissions directory if needed
143
- review_pending_submissions("submissions")
144
  print("\nReview process completed.")
 
2
  import os
3
  from datetime import datetime
4
  import glob
5
+ from huggingface_hub import HfApi
 
6
 
7
+ REPO_ID = "snap-stanford/stark-leaderboard"
8
 
9
+ class ForumPost:
10
+ def __init__(self, message: str, timestamp: str, post_type: str):
11
+ self.message = message
12
+ self.timestamp = timestamp
13
+ self.post_type = post_type
14
 
15
+ def load_forum_posts(forum_file="submissions/forum_posts.json"):
16
+ """Load forum posts from local file"""
17
  try:
18
+ if os.path.exists(forum_file):
19
+ with open(forum_file, 'r') as f:
20
+ posts_data = json.load(f)
21
+ return [ForumPost(**post) for post in posts_data]
22
+ return []
23
  except Exception as e:
24
+ print(f"Error loading forum posts: {e}")
25
+ return []
26
 
27
+ def save_forum_posts(posts, forum_file="submissions/forum_posts.json"):
28
+ """Save forum posts to local file"""
29
  try:
30
+ posts_data = [
31
+ {
32
+ "message": post.message,
33
+ "timestamp": post.timestamp,
34
+ "post_type": post.post_type
35
+ }
36
+ for post in posts
37
+ ]
38
+ os.makedirs(os.path.dirname(forum_file), exist_ok=True)
39
+ with open(forum_file, 'w') as f:
40
+ json.dump(posts_data, f, indent=4)
41
  except Exception as e:
42
+ print(f"Error saving forum posts: {e}")
43
+
44
+ def add_status_update(posts, method_name: str, new_status: str):
45
+ """Add a status update post"""
46
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
47
+ emoji = "✅" if new_status == "approved" else "❌"
48
+ message = f"{emoji} Status update: {method_name} has been {new_status}"
49
+ posts.append(ForumPost(message, timestamp, "status_update"))
50
+ save_forum_posts(posts)
51
 
52
  def review_pending_submissions(submissions_dir: str = "submissions"):
53
  """Review all pending submissions and allow admin to approve/reject them."""
54
  try:
55
+ # Load forum posts
56
+ forum_posts = load_forum_posts()
57
+
58
  # Find all latest.json files
59
  latest_files = glob.glob(os.path.join(submissions_dir, "**", "latest.json"), recursive=True)
60
 
 
62
  print("No submissions found.")
63
  return
64
 
65
+ changes_made = []
66
 
67
  # Process each submission
68
  for latest_file in latest_files:
69
+ try:
70
+ with open(latest_file, 'r') as f:
71
+ latest_info = json.load(f)
 
 
 
72
 
73
+ if latest_info.get('status') != 'pending_review':
74
+ continue
75
+
76
+ folder_path = os.path.dirname(latest_file)
77
+ timestamp = latest_info.get('latest_submission')
78
+ if not timestamp:
79
+ print(f"No timestamp found in {latest_file}, skipping...")
80
+ continue
81
 
82
+ metadata_file = os.path.join(folder_path, f"metadata_{timestamp}.json")
83
+ try:
84
+ with open(metadata_file, 'r') as f:
85
+ metadata = json.load(f)
86
+ except Exception as e:
87
+ print(f"Could not read metadata for {latest_file}, skipping...")
88
+ continue
89
 
90
+ # Display submission details
91
+ print("\n" + "="*80)
92
+ print(f"Submission Details:")
93
+ print(f"Method Name: {metadata.get('Method Name')}")
94
+ print(f"Team Name: {metadata.get('Team Name')}")
95
+ print(f"Dataset: {metadata.get('Dataset')}")
96
+ print(f"Split: {metadata.get('Split')}")
97
+ print(f"Contact Email(s): {metadata.get('Contact Email(s)')}")
98
+ print(f"Code Repository: {metadata.get('Code Repository')}")
99
+ print("\nModel Description:")
100
+ print(metadata.get('Model Description', 'No description provided'))
101
+ print("\nResults:")
102
+ if 'results' in metadata:
103
+ for metric, value in metadata['results'].items():
104
+ print(f"{metric}: {value}")
105
+ print("\nSubmission Date:", metadata.get('submission_date', 'Unknown'))
106
+ print("="*80)
107
+
108
+ # Get admin decision
109
+ while True:
110
+ decision = input("\nApprove this submission? (y/n/skip/quit): ").lower()
111
+ if decision in ['y', 'n', 'skip', 'quit']:
112
+ break
113
+ print("Invalid input. Please enter 'y', 'n', 'skip', or 'quit'")
114
+
115
+ if decision == 'quit':
116
+ print("Exiting review process...")
 
 
117
  break
118
+
119
+ if decision == 'skip':
120
+ continue
121
+
122
+ # Update status
123
+ new_status = 'approved' if decision == 'y' else 'rejected'
124
+ review_timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
125
 
126
+ # Update latest.json
127
+ latest_info['status'] = new_status
128
+ latest_info['reviewed_at'] = review_timestamp
129
+ with open(latest_file, 'w') as f:
130
+ json.dump(latest_info, f, indent=4)
131
+ changes_made.append(latest_file)
132
 
133
+ # Update metadata
134
+ metadata['status'] = new_status
135
+ metadata['reviewed_at'] = review_timestamp
136
+ with open(metadata_file, 'w') as f:
137
+ json.dump(metadata, f, indent=4)
138
+ changes_made.append(metadata_file)
139
+
140
+ # Add forum post
141
+ add_status_update(forum_posts, metadata.get('Method Name'), new_status)
142
+ changes_made.append("submissions/forum_posts.json")
143
+
144
+ print(f"Submission {new_status}")
145
+
146
+ except Exception as e:
147
+ print(f"Error processing {latest_file}: {e}")
 
 
 
 
 
 
148
  continue
149
+
 
 
 
 
150
  if changes_made:
151
+ print("\nThe following files have been modified:")
152
+ for file in sorted(set(changes_made)):
153
+ print(f"- {file}")
154
+ print("\nPlease push these changes to HuggingFace manually.")
155
 
156
  except Exception as e:
157
  print(f"Error during review process: {str(e)}")
158
 
159
  if __name__ == "__main__":
160
  print("Starting submission review process...")
161
+ review_pending_submissions()
 
162
  print("\nReview process completed.")
submissions/abc_a/latest.json CHANGED
@@ -1,6 +1,7 @@
1
  {
2
  "latest_submission": "20241121_015958",
3
- "status": "pending_review",
4
  "method_name": "abc",
5
- "team_name": "a"
 
6
  }
 
1
  {
2
  "latest_submission": "20241121_015958",
3
+ "status": "approved",
4
  "method_name": "abc",
5
+ "team_name": "a",
6
+ "reviewed_at": "2024-11-20 17:09:16"
7
  }
submissions/abc_a/metadata_20241121_015958.json CHANGED
@@ -15,7 +15,8 @@
15
  "recall@20": 35.95,
16
  "mrr": 35.94
17
  },
18
- "status": "pending_review",
19
  "submission_date": "2024-11-21 02:00:15",
20
- "csv_path": "submissions/abc_a/predictions_20241121_015958.csv"
 
21
  }
 
15
  "recall@20": 35.95,
16
  "mrr": 35.94
17
  },
18
+ "status": "approved",
19
  "submission_date": "2024-11-21 02:00:15",
20
+ "csv_path": "submissions/abc_a/predictions_20241121_015958.csv",
21
+ "reviewed_at": "2024-11-20 17:09:16"
22
  }
submissions/debug_test_abc/latest.json CHANGED
@@ -1,6 +1,7 @@
1
  {
2
  "latest_submission": "20241121_011636",
3
- "status": "pending_review",
4
  "method_name": "debug_test",
5
- "team_name": "abc"
 
6
  }
 
1
  {
2
  "latest_submission": "20241121_011636",
3
+ "status": "rejected",
4
  "method_name": "debug_test",
5
+ "team_name": "abc",
6
+ "reviewed_at": "2024-11-20 17:09:52"
7
  }
submissions/debug_test_abc/metadata_20241121_011636.json CHANGED
@@ -15,7 +15,8 @@
15
  "recall@20": 35.95,
16
  "mrr": 35.94
17
  },
18
- "status": "pending_review",
19
  "submission_date": "2024-11-21 01:16:52",
20
- "csv_path": "submissions/debug_test_abc/predictions_20241121_011636.csv"
 
21
  }
 
15
  "recall@20": 35.95,
16
  "mrr": 35.94
17
  },
18
+ "status": "rejected",
19
  "submission_date": "2024-11-21 01:16:52",
20
+ "csv_path": "submissions/debug_test_abc/predictions_20241121_011636.csv",
21
+ "reviewed_at": "2024-11-20 17:09:52"
22
  }
submissions/forum_posts.json CHANGED
@@ -8,5 +8,15 @@
8
  "message": "\ud83d\udce5 New submission: abc on human_generated_eval/mag",
9
  "timestamp": "2024-11-21 02:00:17",
10
  "post_type": "submission"
 
 
 
 
 
 
 
 
 
 
11
  }
12
  ]
 
8
  "message": "\ud83d\udce5 New submission: abc on human_generated_eval/mag",
9
  "timestamp": "2024-11-21 02:00:17",
10
  "post_type": "submission"
11
+ },
12
+ {
13
+ "message": "\u2705 Status update: abc has been approved",
14
+ "timestamp": "2024-11-20 17:09:16",
15
+ "post_type": "status_update"
16
+ },
17
+ {
18
+ "message": "\u274c Status update: debug_test has been rejected",
19
+ "timestamp": "2024-11-20 17:09:52",
20
+ "post_type": "status_update"
21
  }
22
  ]