Commit
·
fd62121
1
Parent(s):
f16f37c
add date picker using dropdown
Browse files- __pycache__/app.cpython-313.pyc +0 -0
- app.py +66 -24
- assets/__pycache__/text_content.cpython-313.pyc +0 -0
- assets/text_content.py +4 -1
- src/__pycache__/filter_utils.cpython-313.pyc +0 -0
- src/filter_utils.py +57 -10
- test.py +10 -0
__pycache__/app.cpython-313.pyc
ADDED
Binary file (8.95 kB). View file
|
|
app.py
CHANGED
@@ -2,6 +2,8 @@ import pandas as pd
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
from gradio_rangeslider import RangeSlider
|
|
|
|
|
5 |
|
6 |
from src.filter_utils import filter, filter_cols
|
7 |
from src.process_data import merge_data
|
@@ -12,7 +14,8 @@ text_leaderboard = pd.read_csv(os.path.join('assets', 'merged_data.csv'))
|
|
12 |
text_leaderboard = text_leaderboard.sort_values(by=tc.CLEMSCORE, ascending=False)
|
13 |
|
14 |
# When displaying latency values
|
15 |
-
text_leaderboard[tc.LATENCY] = text_leaderboard[tc.LATENCY].round(
|
|
|
16 |
|
17 |
open_weight_df = text_leaderboard[text_leaderboard[tc.OPEN_WEIGHT] == True]
|
18 |
if not open_weight_df.empty: # Check if filtered df is non-empty
|
@@ -67,8 +70,16 @@ context_step = 8
|
|
67 |
min_date = min(dates)
|
68 |
max_date = max(dates)
|
69 |
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
|
|
72 |
|
73 |
llm_calc_app = gr.Blocks()
|
74 |
with llm_calc_app:
|
@@ -92,17 +103,30 @@ with llm_calc_app:
|
|
92 |
)
|
93 |
|
94 |
with gr.Row():
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
-
end_date = gr.DateTime(
|
102 |
-
value=max_date,
|
103 |
-
type="string",
|
104 |
-
label="End Date"
|
105 |
-
)
|
106 |
|
107 |
# Multiodality Select
|
108 |
with gr.Row():
|
@@ -201,7 +225,7 @@ with llm_calc_app:
|
|
201 |
filter,
|
202 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
203 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
204 |
-
context_slider, open_weight_checkbox,
|
205 |
[leaderboard_table],
|
206 |
queue=True
|
207 |
)
|
@@ -210,7 +234,7 @@ with llm_calc_app:
|
|
210 |
filter,
|
211 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
212 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
213 |
-
context_slider, open_weight_checkbox,
|
214 |
[leaderboard_table],
|
215 |
queue=True
|
216 |
)
|
@@ -219,7 +243,7 @@ with llm_calc_app:
|
|
219 |
filter,
|
220 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
221 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
222 |
-
context_slider, open_weight_checkbox,
|
223 |
[leaderboard_table],
|
224 |
queue=True
|
225 |
)
|
@@ -228,7 +252,7 @@ with llm_calc_app:
|
|
228 |
filter,
|
229 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
230 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
231 |
-
context_slider, open_weight_checkbox,
|
232 |
[leaderboard_table],
|
233 |
queue=True
|
234 |
)
|
@@ -237,7 +261,7 @@ with llm_calc_app:
|
|
237 |
filter,
|
238 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
239 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
240 |
-
context_slider, open_weight_checkbox,
|
241 |
[leaderboard_table],
|
242 |
queue=True
|
243 |
)
|
@@ -246,7 +270,7 @@ with llm_calc_app:
|
|
246 |
filter,
|
247 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
248 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
249 |
-
context_slider, open_weight_checkbox,
|
250 |
[leaderboard_table],
|
251 |
queue=True
|
252 |
)
|
@@ -255,25 +279,43 @@ with llm_calc_app:
|
|
255 |
filter,
|
256 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
257 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
258 |
-
context_slider, open_weight_checkbox,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
[leaderboard_table],
|
260 |
queue=True
|
261 |
)
|
262 |
|
263 |
-
|
264 |
filter,
|
265 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
266 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
267 |
-
context_slider, open_weight_checkbox,
|
268 |
[leaderboard_table],
|
269 |
queue=True
|
270 |
)
|
271 |
|
272 |
-
|
273 |
filter,
|
274 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
275 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
276 |
-
context_slider, open_weight_checkbox,
|
277 |
[leaderboard_table],
|
278 |
queue=True
|
279 |
)
|
@@ -282,7 +324,7 @@ with llm_calc_app:
|
|
282 |
filter,
|
283 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
284 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
285 |
-
context_slider, open_weight_checkbox,
|
286 |
[leaderboard_table],
|
287 |
queue=True
|
288 |
)
|
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
from gradio_rangeslider import RangeSlider
|
5 |
+
import calendar
|
6 |
+
import datetime
|
7 |
|
8 |
from src.filter_utils import filter, filter_cols
|
9 |
from src.process_data import merge_data
|
|
|
14 |
text_leaderboard = text_leaderboard.sort_values(by=tc.CLEMSCORE, ascending=False)
|
15 |
|
16 |
# When displaying latency values
|
17 |
+
text_leaderboard[tc.LATENCY] = text_leaderboard[tc.LATENCY].round(1)
|
18 |
+
text_leaderboard[tc.CLEMSCORE] = text_leaderboard[tc.CLEMSCORE].round(1)
|
19 |
|
20 |
open_weight_df = text_leaderboard[text_leaderboard[tc.OPEN_WEIGHT] == True]
|
21 |
if not open_weight_df.empty: # Check if filtered df is non-empty
|
|
|
70 |
min_date = min(dates)
|
71 |
max_date = max(dates)
|
72 |
|
73 |
+
# Date settings
|
74 |
+
today = datetime.date.today()
|
75 |
+
end_year = today.year
|
76 |
+
start_year = tc.START_YEAR
|
77 |
+
|
78 |
+
YEARS = list(range(int(start_year), int(end_year)+1))
|
79 |
+
YEARS = [str(y) for y in YEARS]
|
80 |
+
MONTHS = list(calendar.month_name[1:])
|
81 |
|
82 |
+
TITLE = tc.TITLE
|
83 |
|
84 |
llm_calc_app = gr.Blocks()
|
85 |
with llm_calc_app:
|
|
|
103 |
)
|
104 |
|
105 |
with gr.Row():
|
106 |
+
with gr.Column():
|
107 |
+
start_year = gr.Dropdown(
|
108 |
+
choices=YEARS,
|
109 |
+
value=[YEARS[0]],
|
110 |
+
allow_custom_value=True
|
111 |
+
)
|
112 |
+
start_month = gr.Dropdown(
|
113 |
+
choices=MONTHS,
|
114 |
+
value=[MONTHS[0]],
|
115 |
+
allow_custom_value=True
|
116 |
+
)
|
117 |
+
|
118 |
+
with gr.Column():
|
119 |
+
end_year = gr.Dropdown(
|
120 |
+
choices=YEARS,
|
121 |
+
value=[YEARS[-1]],
|
122 |
+
allow_custom_value=True
|
123 |
+
)
|
124 |
+
end_month = gr.Dropdown(
|
125 |
+
choices=MONTHS,
|
126 |
+
value=[MONTHS[-1]],
|
127 |
+
allow_custom_value=True
|
128 |
+
)
|
129 |
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
# Multiodality Select
|
132 |
with gr.Row():
|
|
|
225 |
filter,
|
226 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
227 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
228 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
229 |
[leaderboard_table],
|
230 |
queue=True
|
231 |
)
|
|
|
234 |
filter,
|
235 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
236 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
237 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
238 |
[leaderboard_table],
|
239 |
queue=True
|
240 |
)
|
|
|
243 |
filter,
|
244 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
245 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
246 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
247 |
[leaderboard_table],
|
248 |
queue=True
|
249 |
)
|
|
|
252 |
filter,
|
253 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
254 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
255 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
256 |
[leaderboard_table],
|
257 |
queue=True
|
258 |
)
|
|
|
261 |
filter,
|
262 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
263 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
264 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
265 |
[leaderboard_table],
|
266 |
queue=True
|
267 |
)
|
|
|
270 |
filter,
|
271 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
272 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
273 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
274 |
[leaderboard_table],
|
275 |
queue=True
|
276 |
)
|
|
|
279 |
filter,
|
280 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
281 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
282 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
283 |
+
[leaderboard_table],
|
284 |
+
queue=True
|
285 |
+
)
|
286 |
+
|
287 |
+
start_year.change(
|
288 |
+
filter,
|
289 |
+
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
290 |
+
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
291 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
292 |
+
[leaderboard_table],
|
293 |
+
queue=True
|
294 |
+
)
|
295 |
+
|
296 |
+
start_month.change(
|
297 |
+
filter,
|
298 |
+
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
299 |
+
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
300 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
301 |
[leaderboard_table],
|
302 |
queue=True
|
303 |
)
|
304 |
|
305 |
+
end_year.change(
|
306 |
filter,
|
307 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
308 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
309 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
310 |
[leaderboard_table],
|
311 |
queue=True
|
312 |
)
|
313 |
|
314 |
+
end_month.change(
|
315 |
filter,
|
316 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
317 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
318 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
319 |
[leaderboard_table],
|
320 |
queue=True
|
321 |
)
|
|
|
324 |
filter,
|
325 |
[dummy_leaderboard_table, lang_dropdown, parameter_slider,
|
326 |
input_pricing_slider, output_pricing_slider, multimodal_checkbox,
|
327 |
+
context_slider, open_weight_checkbox, start_year, start_month, end_year, end_month, license_checkbox],
|
328 |
[leaderboard_table],
|
329 |
queue=True
|
330 |
)
|
assets/__pycache__/text_content.cpython-313.pyc
CHANGED
Binary files a/assets/__pycache__/text_content.cpython-313.pyc and b/assets/__pycache__/text_content.cpython-313.pyc differ
|
|
assets/text_content.py
CHANGED
@@ -36,4 +36,7 @@ TEMP_DATE = "Temp Date"
|
|
36 |
OPEN = "Open-Weight"
|
37 |
COMM = "Commercial"
|
38 |
|
39 |
-
TITLE = """<h1 align="center" id="space-title"> LLM Calculator ⚖️⚡ 📏💰</h1>"""
|
|
|
|
|
|
|
|
36 |
OPEN = "Open-Weight"
|
37 |
COMM = "Commercial"
|
38 |
|
39 |
+
TITLE = """<h1 align="center" id="space-title"> LLM Calculator ⚖️⚡ 📏💰</h1>"""
|
40 |
+
|
41 |
+
# Date Picker (set as Dropdown until datetime object is fixed)
|
42 |
+
START_YEAR = "2020"
|
src/__pycache__/filter_utils.cpython-313.pyc
CHANGED
Binary files a/src/__pycache__/filter_utils.cpython-313.pyc and b/src/__pycache__/filter_utils.cpython-313.pyc differ
|
|
src/filter_utils.py
CHANGED
@@ -19,9 +19,53 @@ def filter_cols(df):
|
|
19 |
|
20 |
return df
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def filter(df, language_list, parameters, input_price, output_price, multimodal,
|
24 |
-
context, open_weight,
|
25 |
|
26 |
|
27 |
if not df.empty: # Check if df is non-empty
|
@@ -81,20 +125,23 @@ def filter(df, language_list, parameters, input_price, output_price, multimodal,
|
|
81 |
if not df.empty: # Check if df is non-empty
|
82 |
df = df[df[tc.LICENSE_NAME].apply(lambda x: any(lic in x for lic in license))]
|
83 |
|
84 |
-
# Convert 'Release Date' to int temporarily
|
85 |
-
if not df.empty: # Check if df is non-empty
|
86 |
-
|
87 |
|
88 |
-
# Convert start and end to int (seconds since epoch)
|
89 |
-
start = int(pd.to_datetime(start).timestamp())
|
90 |
-
end = int(pd.to_datetime(end).timestamp())
|
91 |
|
92 |
-
# Filter based on the converted 'Release Date'
|
93 |
-
if not df.empty: # Check if df is non-empty
|
94 |
-
|
|
|
|
|
95 |
|
96 |
df = filter_cols(df)
|
97 |
df = df.sort_values(by=tc.CLEMSCORE, ascending=False)
|
98 |
|
99 |
return df # Return the filtered dataframe
|
100 |
|
|
|
|
19 |
|
20 |
return df
|
21 |
|
22 |
+
def convert_date_components_to_timestamp(year: str, month: str) -> int:
|
23 |
+
"""Convert year and month strings to timestamp."""
|
24 |
+
# Create a datetime object for the first day of the month
|
25 |
+
date_str = f"{year}-{month:02d}-01"
|
26 |
+
return int(pd.to_datetime(date_str).timestamp())
|
27 |
+
|
28 |
+
def filter_by_date(df: pd.DataFrame,
|
29 |
+
start_year: str,
|
30 |
+
start_month: str,
|
31 |
+
end_year: str,
|
32 |
+
end_month: str,
|
33 |
+
date_column: str) -> pd.DataFrame:
|
34 |
+
"""
|
35 |
+
Filter DataFrame by date range using separate year and month components.
|
36 |
+
|
37 |
+
Args:
|
38 |
+
df: DataFrame to filter
|
39 |
+
start_year: Starting year (e.g., "2023")
|
40 |
+
start_month: Starting month (e.g., "1" for January)
|
41 |
+
end_year: Ending year (e.g., "2024")
|
42 |
+
end_month: Ending month (e.g., "12" for December)
|
43 |
+
date_column: Name of the date column to filter on
|
44 |
+
"""
|
45 |
+
# Convert string inputs to integers for date creation
|
46 |
+
start_timestamp = convert_date_components_to_timestamp(
|
47 |
+
int(start_year),
|
48 |
+
int(start_month)
|
49 |
+
)
|
50 |
+
|
51 |
+
end_timestamp = convert_date_components_to_timestamp(
|
52 |
+
int(end_year),
|
53 |
+
int(end_month)
|
54 |
+
)
|
55 |
+
|
56 |
+
# Convert the DataFrame's date column to timestamps for comparison
|
57 |
+
date_timestamps = pd.to_datetime(df[date_column]).apply(lambda x: int(x.timestamp()))
|
58 |
+
|
59 |
+
# Filter the DataFrame
|
60 |
+
return df[
|
61 |
+
(date_timestamps >= start_timestamp) &
|
62 |
+
(date_timestamps <= end_timestamp)
|
63 |
+
]
|
64 |
+
|
65 |
+
|
66 |
|
67 |
def filter(df, language_list, parameters, input_price, output_price, multimodal,
|
68 |
+
context, open_weight, start_year, start_month, end_year, end_month, license ):
|
69 |
|
70 |
|
71 |
if not df.empty: # Check if df is non-empty
|
|
|
125 |
if not df.empty: # Check if df is non-empty
|
126 |
df = df[df[tc.LICENSE_NAME].apply(lambda x: any(lic in x for lic in license))]
|
127 |
|
128 |
+
# # Convert 'Release Date' to int temporarily
|
129 |
+
# if not df.empty: # Check if df is non-empty
|
130 |
+
# df[tc.TEMP_DATE] = pd.to_datetime(df[tc.TEMP_DATE]).astype(int) // 10**9 # Convert to seconds since epoch
|
131 |
|
132 |
+
# # Convert start and end to int (seconds since epoch)
|
133 |
+
# start = int(pd.to_datetime(start).timestamp())
|
134 |
+
# end = int(pd.to_datetime(end).timestamp())
|
135 |
|
136 |
+
# # Filter based on the converted 'Release Date'
|
137 |
+
# if not df.empty: # Check if df is non-empty
|
138 |
+
# df = df[(df[tc.TEMP_DATE] >= start) & (df[tc.TEMP_DATE] <= end)]
|
139 |
+
|
140 |
+
df = filter_by_date(df, start_year, start_month, end_year, end_month, tc.TEMP_DATE)
|
141 |
|
142 |
df = filter_cols(df)
|
143 |
df = df.sort_values(by=tc.CLEMSCORE, ascending=False)
|
144 |
|
145 |
return df # Return the filtered dataframe
|
146 |
|
147 |
+
|
test.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import calendar
|
2 |
+
import datetime
|
3 |
+
|
4 |
+
today = datetime.date.today()
|
5 |
+
|
6 |
+
year = today.year
|
7 |
+
|
8 |
+
print(year)
|
9 |
+
|
10 |
+
print(list(calendar.month_name[1:]))
|