File size: 2,060 Bytes
0595902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from datasets import Dataset, load_dataset
from typing import Dict, Any, List
from config.settings import RESULTS_DATASET, HF_TOKEN


def save_submission_to_dataset(submission_record: Dict[str, Any]) -> None:
    """Save a submission record to the HuggingFace dataset."""
    
    # Load existing dataset or create new one
    try:
        dataset = load_dataset(RESULTS_DATASET, token=HF_TOKEN, split="test")
        existing_data = list(dataset)
    except:
        # Dataset doesn't exist or is empty, start fresh
        existing_data = []
    
    # Add new submission
    existing_data.append(submission_record)
    
    # Create new dataset
    new_dataset = Dataset.from_list(existing_data)
    
    # Push to HuggingFace
    new_dataset.push_to_hub(
        RESULTS_DATASET, 
        token=HF_TOKEN,
        split="test"
    )


def get_all_submissions(approved_only: bool = False) -> List[Dict[str, Any]]:
    """Get all submissions from the dataset."""
    
    dataset = load_dataset(RESULTS_DATASET, token=HF_TOKEN, split="test")
    submissions = list(dataset)
    
    if approved_only:
        submissions = [s for s in submissions if s["config"]["approved"]]
    
    return submissions


def update_submission_approval(model_name: str, hf_space_tag: str, approved: bool) -> None:
    """Update the approval status of a submission."""
    
    # Load dataset
    dataset = load_dataset(RESULTS_DATASET, token=HF_TOKEN, split="test")
    data = list(dataset)
    
    # Find and update the submission
    for submission in data:
        config = submission["config"]
        if config["model_name"] == model_name and config["hf_space_tag"] == hf_space_tag:
            config["approved"] = approved
            if approved:
                from datetime import datetime
                config["date_approved"] = datetime.now().isoformat()
            break
    
    # Save updated dataset
    updated_dataset = Dataset.from_list(data)
    updated_dataset.push_to_hub(
        RESULTS_DATASET,
        token=HF_TOKEN, 
        split="test"
    )