Commit
·
d8f251a
1
Parent(s):
bbae640
update fetching
Browse files- app.py +2 -10
- src/__pycache__/pricing.cpython-310.pyc +0 -0
- src/pricing.py +29 -60
app.py
CHANGED
@@ -2,10 +2,10 @@ import pandas as pd
|
|
2 |
import gradio as gr
|
3 |
import asyncio # Ensure asyncio is imported
|
4 |
|
5 |
-
from src.pricing import
|
6 |
|
7 |
|
8 |
-
text_leaderboard =
|
9 |
llm_calc_app = gr.Blocks()
|
10 |
with llm_calc_app:
|
11 |
|
@@ -18,13 +18,5 @@ with llm_calc_app:
|
|
18 |
)
|
19 |
llm_calc_app.load()
|
20 |
|
21 |
-
# # Ensure the app runs in an asyncio event loop
|
22 |
-
# async def main():
|
23 |
-
# llm_calc_app.queue()
|
24 |
-
# await llm_calc_app.launch()
|
25 |
-
|
26 |
-
# Run the async main function
|
27 |
-
# asyncio.run(main())
|
28 |
-
|
29 |
llm_calc_app.queue()
|
30 |
llm_calc_app.launch()
|
|
|
2 |
import gradio as gr
|
3 |
import asyncio # Ensure asyncio is imported
|
4 |
|
5 |
+
from src.pricing import fetch_prices
|
6 |
|
7 |
|
8 |
+
text_leaderboard = fetch_prices()
|
9 |
llm_calc_app = gr.Blocks()
|
10 |
with llm_calc_app:
|
11 |
|
|
|
18 |
)
|
19 |
llm_calc_app.load()
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
llm_calc_app.queue()
|
22 |
llm_calc_app.launch()
|
src/__pycache__/pricing.cpython-310.pyc
CHANGED
Binary files a/src/__pycache__/pricing.cpython-310.pyc and b/src/__pycache__/pricing.cpython-310.pyc differ
|
|
src/pricing.py
CHANGED
@@ -1,61 +1,30 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
# Iterate through the rows of the table
|
30 |
-
for row in table.find_all('tr')[1:]: # Skip the header row
|
31 |
-
cols = row.find_all('td')
|
32 |
-
if len(cols) > 0:
|
33 |
-
model_names.append(cols[0].text.strip())
|
34 |
-
# providers.append(cols[1].text.strip())
|
35 |
-
input_tokens.append(cols[2].text.strip())
|
36 |
-
output_tokens.append(cols[3].text.strip())
|
37 |
-
sources.append(cols[4].text.strip())
|
38 |
-
updated_times.append(cols[5].text.strip())
|
39 |
-
|
40 |
-
# Create a DataFrame from the collected data
|
41 |
-
data = {
|
42 |
-
'Model Name': model_names,
|
43 |
-
# 'Providers': providers,
|
44 |
-
'1 M Input Tokens': input_tokens,
|
45 |
-
'1 M Output Tokens': output_tokens,
|
46 |
-
'Source': sources,
|
47 |
-
'Updated Time': updated_times
|
48 |
-
}
|
49 |
-
|
50 |
-
df = pd.DataFrame(data)
|
51 |
-
return df
|
52 |
else:
|
53 |
-
print("
|
54 |
-
|
55 |
-
# Close the browser
|
56 |
-
await browser.close()
|
57 |
-
|
58 |
-
# Run the main function
|
59 |
-
def get_pricing_df():
|
60 |
-
price_df = asyncio.get_event_loop().run_until_complete(main())
|
61 |
-
return price_df
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def fetch_prices():
|
5 |
+
# Fetch the JSON data from the URL
|
6 |
+
url = "https://llm-price.huhuhang.workers.dev/"
|
7 |
+
response = requests.get(url)
|
8 |
+
|
9 |
+
# Check if the request was successful
|
10 |
+
if response.status_code == 200:
|
11 |
+
data = response.json()
|
12 |
+
# Extract relevant information
|
13 |
+
extracted_data = []
|
14 |
+
for entry in data:
|
15 |
+
extracted_info = {
|
16 |
+
"output_tokens": entry["fields"]["output_tokens"],
|
17 |
+
"provider": entry["fields"]["provider"],
|
18 |
+
"model_name": entry["fields"]["model_name"],
|
19 |
+
"url": entry["fields"]["url"],
|
20 |
+
"input_tokens": entry["fields"]["input_tokens"],
|
21 |
+
"update_time": entry["fields"]["update_time"]
|
22 |
+
}
|
23 |
+
extracted_data.append(extracted_info)
|
24 |
+
|
25 |
+
# Create a DataFrame from the extracted data
|
26 |
+
df = pd.DataFrame(extracted_data)
|
27 |
+
return df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
else:
|
29 |
+
print(f"Failed to retrieve data: {response.status_code}")
|
30 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|