Spaces:
Runtime error
Runtime error
Create openllm.py
Browse files- openllm.py +44 -0
openllm.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def get_json_format_data():
|
| 8 |
+
url = 'https://huggingfaceh4-open-llm-leaderboard.hf.space/'
|
| 9 |
+
response = requests.get(url)
|
| 10 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
| 11 |
+
|
| 12 |
+
script_elements = soup.find_all('script')
|
| 13 |
+
json_format_data = json.loads(str(script_elements[1])[31:-10])
|
| 14 |
+
return json_format_data
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def get_datas(data):
|
| 18 |
+
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
|
| 19 |
+
try:
|
| 20 |
+
result_list = []
|
| 21 |
+
i = 0
|
| 22 |
+
while True:
|
| 23 |
+
try:
|
| 24 |
+
results = data['components'][component_index]['props']['value']['data'][i]
|
| 25 |
+
columns = data['components'][component_index]['props']['headers']
|
| 26 |
+
try:
|
| 27 |
+
results_json = {"T": results[0], "Model": results[-1]}
|
| 28 |
+
|
| 29 |
+
if len(columns) < 15: # If there are less than 15 columns (this number can definetly change), we know that we are trying wrong component index, so breaking loop to try next component index.
|
| 30 |
+
break
|
| 31 |
+
|
| 32 |
+
for col_index, col_name in enumerate(columns[2:-1], start=2):
|
| 33 |
+
results_json[col_name] = results[col_index]
|
| 34 |
+
|
| 35 |
+
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.)
|
| 36 |
+
break
|
| 37 |
+
result_list.append(results_json)
|
| 38 |
+
i += 1
|
| 39 |
+
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.)
|
| 40 |
+
return result_list
|
| 41 |
+
except (KeyError, TypeError):
|
| 42 |
+
continue
|
| 43 |
+
|
| 44 |
+
return result_list
|