Spaces:
Running
Running
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
|
6 |
-
from utils.hub_storage import HubStorage
|
7 |
|
|
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
def
|
11 |
-
"""
|
12 |
try:
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
15 |
except Exception as e:
|
16 |
-
print(f"Error
|
17 |
-
return
|
18 |
|
19 |
-
def
|
20 |
-
"""
|
21 |
try:
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
except Exception as e:
|
31 |
-
print(f"Error
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
38 |
-
|
39 |
-
|
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 =
|
48 |
|
49 |
# Process each submission
|
50 |
for latest_file in latest_files:
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
if not latest_info:
|
55 |
-
print(f"Could not read {latest_file}, skipping...")
|
56 |
-
continue
|
57 |
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
print(f"
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
decision = input("\nApprove this submission? (y/n/skip/quit): ").lower()
|
95 |
-
if decision in ['y', 'n', 'skip', 'quit']:
|
96 |
break
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
102 |
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
new_status
|
118 |
-
|
119 |
-
|
120 |
-
|
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("\
|
135 |
-
|
|
|
|
|
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 |
-
|
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": "
|
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": "
|
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": "
|
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": "
|
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 |
]
|