|
import pandas as pd |
|
import os |
|
import fnmatch |
|
import json |
|
import re |
|
import numpy as np |
|
import requests |
|
|
|
class DetailsDataProcessor: |
|
|
|
|
|
|
|
def __init__(self, directory='results', pattern='results*.json'): |
|
self.directory = directory |
|
self.pattern = pattern |
|
|
|
|
|
|
|
def _find_files(self, directory='results', pattern='results*.json'): |
|
matching_files = [] |
|
for root, dirs, files in os.walk(directory): |
|
for basename in files: |
|
if fnmatch.fnmatch(basename, pattern): |
|
filename = os.path.join(root, basename) |
|
matching_files.append(filename) |
|
return matching_files |
|
|
|
|
|
@staticmethod |
|
def download_file(url, filename): |
|
r = requests.get(url, allow_redirects=True) |
|
open(filename, 'wb').write(r.content) |
|
|
|
@staticmethod |
|
def single_file_pipeline(url, filename): |
|
DetailsDataProcessor.download_file(url, filename) |
|
|
|
with open(filename) as f: |
|
data = json.load(f) |
|
|
|
df = pd.DataFrame(data) |
|
return df |
|
|
|
@staticmethod |
|
def generate_url(file_path): |
|
base_url = 'https://huggingface.co/datasets/open-llm-leaderboard/details/resolve/main/' |
|
|
|
|
|
organization = '64bits' |
|
model = 'LexPodLM-13B' |
|
filename = '_2023-07-25T13%3A41%3A51.227672.json' |
|
|
|
|
|
|
|
|
|
|
|
other_chunk = 'details_harness%7ChendrycksTest-moral_scenarios%7C5' |
|
constructed_url = base_url + organization + '/' + model + '/' + other_chunk + filename |
|
return constructed_url |
|
|
|
|
|
|
|
|
|
|
|
def pipeline(self): |
|
dataframes = [] |
|
file_paths = self._find_files(self.directory, self.pattern) |
|
for file_path in file_paths: |
|
print(file_path) |
|
url = self.generate_url(file_path) |
|
file_path = file_path.split('/')[-1] |
|
df = self.single_file_pipeline(url, file_path) |
|
dataframes.append(df) |
|
return dataframes |
|
|