Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
import
|
4 |
from typing import Any
|
5 |
from communex.client import CommuneClient
|
6 |
from communex.balance import from_nano
|
@@ -19,15 +19,15 @@ def get_com_price() -> Any:
|
|
19 |
print(f"Error fetching COM price: {e}")
|
20 |
if i == retries - 1:
|
21 |
raise
|
22 |
-
|
23 |
raise RuntimeError("Failed to fetch COM price")
|
24 |
|
25 |
-
def get_leaderboard_data():
|
26 |
try:
|
27 |
com_price = get_com_price()
|
28 |
blocks_in_day = 10_800
|
29 |
client = CommuneClient(node_url)
|
30 |
-
emission = client.query("Emission", params=[netuid])
|
31 |
scores = {}
|
32 |
for uid, emi in enumerate(emission):
|
33 |
scores[uid] = ((emi / 10**11) * blocks_in_day) * com_price
|
@@ -43,14 +43,14 @@ def get_leaderboard_data():
|
|
43 |
print(f"Error fetching leaderboard data: {e}")
|
44 |
return []
|
45 |
|
46 |
-
def update_leaderboard_table():
|
47 |
-
leaderboard_data = get_leaderboard_data()
|
48 |
return gr.components.DataFrame.update(value=leaderboard_data)
|
49 |
|
50 |
with gr.Blocks() as demo:
|
51 |
gr.Markdown("# Commune Leaderboard")
|
52 |
|
53 |
-
leaderboard_table = gr.components.
|
54 |
headers=["rank", "uid", "score"],
|
55 |
datatype=["number", "number", "number"],
|
56 |
interactive=False,
|
@@ -63,7 +63,8 @@ with gr.Blocks() as demo:
|
|
63 |
refresh_button.click(fn=update_leaderboard_table, outputs=leaderboard_table)
|
64 |
|
65 |
# Initial load of leaderboard data
|
66 |
-
|
|
|
67 |
leaderboard_table.value = leaderboard_data
|
68 |
|
69 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
import asyncio
|
4 |
from typing import Any
|
5 |
from communex.client import CommuneClient
|
6 |
from communex.balance import from_nano
|
|
|
19 |
print(f"Error fetching COM price: {e}")
|
20 |
if i == retries - 1:
|
21 |
raise
|
22 |
+
asyncio.sleep(retries)
|
23 |
raise RuntimeError("Failed to fetch COM price")
|
24 |
|
25 |
+
async def get_leaderboard_data():
|
26 |
try:
|
27 |
com_price = get_com_price()
|
28 |
blocks_in_day = 10_800
|
29 |
client = CommuneClient(node_url)
|
30 |
+
emission = await client.query("Emission", params=[netuid])
|
31 |
scores = {}
|
32 |
for uid, emi in enumerate(emission):
|
33 |
scores[uid] = ((emi / 10**11) * blocks_in_day) * com_price
|
|
|
43 |
print(f"Error fetching leaderboard data: {e}")
|
44 |
return []
|
45 |
|
46 |
+
async def update_leaderboard_table():
|
47 |
+
leaderboard_data = await get_leaderboard_data()
|
48 |
return gr.components.DataFrame.update(value=leaderboard_data)
|
49 |
|
50 |
with gr.Blocks() as demo:
|
51 |
gr.Markdown("# Commune Leaderboard")
|
52 |
|
53 |
+
leaderboard_table = gr.components.Dataframe(
|
54 |
headers=["rank", "uid", "score"],
|
55 |
datatype=["number", "number", "number"],
|
56 |
interactive=False,
|
|
|
63 |
refresh_button.click(fn=update_leaderboard_table, outputs=leaderboard_table)
|
64 |
|
65 |
# Initial load of leaderboard data
|
66 |
+
loop = asyncio.get_event_loop()
|
67 |
+
leaderboard_data = loop.run_until_complete(get_leaderboard_data())
|
68 |
leaderboard_table.value = leaderboard_data
|
69 |
|
70 |
if __name__ == "__main__":
|