File size: 1,545 Bytes
1d4678a
6297f2c
 
 
205d979
6297f2c
a290dce
 
 
 
dfc5b32
 
a290dce
 
 
 
 
 
 
 
c0c969f
 
a290dce
 
 
 
c0c969f
 
 
 
dfc5b32
84af953
dfc5b32
205d979
 
17cb536
 
c0c969f
84af953
 
 
 
 
 
 
dfc5b32
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, jsonify

app = Flask(__name__)

@app.route("/")
def hello():
    return jsonify({"status": "running"})

from flask import Flask, jsonify, request
from datasets import load_dataset, Dataset
from huggingface_hub import hf_hub_download
import requests
import pandas as pd
import os

HF_TOKEN = os.environ.get("HF_TOKEN")
REPO_ID = "saraht14/responses"

@app.route("/leaderboard", methods=["GET"])
def get_leaderboard():
    try:
        ds = load_dataset(REPO_ID, split="train", token=HF_TOKEN)
        df = ds.to_pandas()
        df = df.sort_values(by=["Accuracy", "Execution Time (s)"], ascending=[False, True])
        return jsonify(df.to_dict(orient="records"))
    except Exception as e:
        df = pd.DataFrame(columns=HEADERS)
        return jsonify(df.to_dict(orient="records"))



HF_CACHE_DIR = "/tmp/hf"

@app.route("/file/<path:filename>", methods=["GET"])
def get_file(filename):
    if request.headers.get("Authorization") != f"Bearer {HF_TOKEN}":
        return jsonify({"error": "Unauthorized"}), 403
    try:
        local_path = hf_hub_download(
            repo_id="saraht14/metadata",
            filename=filename,
            repo_type="dataset",
            token=HF_TOKEN,
            cache_dir=HF_CACHE_DIR
        )

        with open(local_path, "r") as f:
            content = f.read()

        return jsonify({
            "filename": filename,
            "content": content
        })

    except Exception as e:
        return jsonify({"error": f"Failed to fetch file: {str(e)}"}), 500