tohid.abedini commited on
Commit
d779abf
·
1 Parent(s): 744607e

[Add] jsonl load handling

Browse files
Files changed (2) hide show
  1. app.py +2 -2
  2. utils.py +9 -8
app.py CHANGED
@@ -10,7 +10,7 @@ import json
10
  import requests
11
 
12
  from envs import API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO
13
- from utils import LLM_BENCHMARKS_ABOUT_TEXT, LLM_BENCHMARKS_SUBMIT_TEXT, custom_css, load_jsonl_with_check
14
 
15
 
16
 
@@ -102,7 +102,7 @@ abs_path = Path(__file__).parent
102
 
103
  # Any pandas-compatible data
104
  # persian_df = pd.read_json(str(abs_path / "leaderboard_persian.jsonl"))
105
- persian_df = load_jsonl_with_check(str(abs_path / "leaderboard_persian.jsonl"))
106
  base_df = pd.read_json(str(abs_path / "leaderboard_base.json"))
107
 
108
  with gr.Blocks(css=custom_css) as demo:
 
10
  import requests
11
 
12
  from envs import API, EVAL_REQUESTS_PATH, TOKEN, QUEUE_REPO
13
+ from utils import LLM_BENCHMARKS_ABOUT_TEXT, LLM_BENCHMARKS_SUBMIT_TEXT, custom_css, jsonl_to_dataframe
14
 
15
 
16
 
 
102
 
103
  # Any pandas-compatible data
104
  # persian_df = pd.read_json(str(abs_path / "leaderboard_persian.jsonl"))
105
+ persian_df = jsonl_to_dataframe(str(abs_path / "leaderboard_persian.jsonl"))
106
  base_df = pd.read_json(str(abs_path / "leaderboard_base.json"))
107
 
108
  with gr.Blocks(css=custom_css) as demo:
utils.py CHANGED
@@ -138,13 +138,14 @@ LLM_BENCHMARKS_SUBMIT_TEXT = """## Submit your model
138
  """
139
 
140
 
141
- def load_jsonl_with_check(file_path):
142
  data = []
143
- with open(file_path, 'r', encoding='utf-8') as file:
144
- for idx, line in enumerate(file):
145
- try:
146
- data.append(json.loads(line.strip())) # Use json.loads instead of pd.json.loads
147
- except ValueError as e:
148
- print(f"Error parsing line {idx + 1}: {line.strip()}")
149
- print(f"Error details: {e}")
 
150
  return pd.DataFrame(data)
 
138
  """
139
 
140
 
141
+ def load_jsonl(input_file):
142
  data = []
143
+ with open(input_file, 'r') as f:
144
+ for line in f:
145
+ data.append(json.loads(line))
146
+ return data
147
+
148
+
149
+ def jsonl_to_dataframe(input_file):
150
+ data = load_jsonl(input_file)
151
  return pd.DataFrame(data)