Spaces:
Runtime error
Runtime error
Commit
•
263c06c
1
Parent(s):
439d0c0
catch error
Browse files
app.py
CHANGED
@@ -33,8 +33,14 @@ def relative_rank(my_dict, target_key, filter_zero=False):
|
|
33 |
sorted_items = sorted(my_dict.items(), key=lambda item: item[1], reverse=True)
|
34 |
|
35 |
position = [key for key, _ in sorted_items].index(target_key)
|
|
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
|
40 |
def relative_rank_for_space(space_id, filter_zero=False):
|
@@ -56,10 +62,12 @@ def rank_space_and_org(space_or_org_id, filter_zero):
|
|
56 |
split = space_or_org_id.split("/")
|
57 |
if len(split) == 2:
|
58 |
space_rank = relative_rank_for_space(space_or_org_id, filter_zero=filter_zero)
|
59 |
-
return f"Space {space_or_org_id} is ranked {space_rank:.2f}%"
|
60 |
if len(split) == 1:
|
61 |
org_rank = relative_rank_for_org(space_or_org_id, filter_zero=filter_zero)
|
62 |
-
return
|
|
|
|
|
63 |
|
64 |
|
65 |
with gr.Blocks() as demo:
|
|
|
33 |
sorted_items = sorted(my_dict.items(), key=lambda item: item[1], reverse=True)
|
34 |
|
35 |
position = [key for key, _ in sorted_items].index(target_key)
|
36 |
+
num_lower = len(sorted_items) - position - 1
|
37 |
|
38 |
+
num_higher = position
|
39 |
+
return {
|
40 |
+
"rank": (num_higher + 1) / len(my_dict) * 100,
|
41 |
+
"num_higher": num_higher,
|
42 |
+
"num_lower": num_lower,
|
43 |
+
}
|
44 |
|
45 |
|
46 |
def relative_rank_for_space(space_id, filter_zero=False):
|
|
|
62 |
split = space_or_org_id.split("/")
|
63 |
if len(split) == 2:
|
64 |
space_rank = relative_rank_for_space(space_or_org_id, filter_zero=filter_zero)
|
65 |
+
return f"Space {space_or_org_id} is ranked {space_rank['rank']:.2f}%"
|
66 |
if len(split) == 1:
|
67 |
org_rank = relative_rank_for_org(space_or_org_id, filter_zero=filter_zero)
|
68 |
+
return (
|
69 |
+
f"Organization or user {space_or_org_id} is ranked {org_rank['rank']:.2f}%"
|
70 |
+
)
|
71 |
|
72 |
|
73 |
with gr.Blocks() as demo:
|