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