Create openllm.py
Browse files- openllm.py +40 -0
openllm.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import requests
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
+
import pandas as pd
|
5 |
+
import json
|
6 |
+
|
7 |
+
# Repo: https://github.com/Weyaxi/scrape-open-llm-leaderboard
|
8 |
+
|
9 |
+
def get_json_format_data():
|
10 |
+
url = 'https://huggingfaceh4-open-llm-leaderboard.hf.space/'
|
11 |
+
response = requests.get(url)
|
12 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
13 |
+
|
14 |
+
script_elements = soup.find_all('script')
|
15 |
+
json_format_data = json.loads(str(script_elements[1])[31:-10])
|
16 |
+
return json_format_data
|
17 |
+
|
18 |
+
|
19 |
+
def get_datas(data):
|
20 |
+
for component_index in range(10, 50, 1): # component_index sometimes changes when they update the space, we can use this "for" loop to avoid changing component index manually
|
21 |
+
try:
|
22 |
+
result_list = []
|
23 |
+
i = 0
|
24 |
+
while True:
|
25 |
+
try:
|
26 |
+
results = data['components'][component_index]['props']['value']['data'][i][2:15]
|
27 |
+
type_of_emoji = data['components'][component_index]['props']['value']['data'][i][0]
|
28 |
+
|
29 |
+
try:
|
30 |
+
results_json = {"T": type_of_emoji, "Model": results[-1], "Average ⬆️": results[0], "ARC": results[1], "HellaSwag": results[2], "MMLU": results[3], "TruthfulQA": results[4], "Type": results[5],"Precision": results[6], "Hub License": results[7], "#Params (B)": results[8], "Hub ❤️": results[9], "Model Sha": results[11]}
|
31 |
+
except IndexError: # Wrong component index, so breaking loop to try next component index. (NOTE: More than one component index can give you some results but we must find the right component index to get all results we want.)
|
32 |
+
break
|
33 |
+
result_list.append(results_json)
|
34 |
+
i += 1
|
35 |
+
except IndexError: # No rows to extract so return the list (We know it is the right component index because we didn't break out of loop on the other exception.)
|
36 |
+
return result_list
|
37 |
+
except (KeyError, TypeError):
|
38 |
+
continue
|
39 |
+
|
40 |
+
return result_list
|