Spaces:
Sleeping
Sleeping
Commit
•
7554959
1
Parent(s):
6f2b708
Update app.py
Browse files
app.py
CHANGED
@@ -15,34 +15,19 @@ def fetch_data(dataset_name: str, workspace: str):
|
|
15 |
return client.datasets(dataset_name, workspace=workspace)
|
16 |
|
17 |
|
18 |
-
def get_progress(dataset) -> dict:
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
progress = (annotated_records / total_records) * 100 if total_records > 0 else 0
|
25 |
return {
|
26 |
-
"total":
|
27 |
-
"annotated":
|
28 |
"progress": progress,
|
|
|
29 |
}
|
30 |
|
31 |
-
|
32 |
-
def get_leaderboard(dataset) -> dict:
|
33 |
-
user_annotations = {}
|
34 |
-
for record in dataset.records:
|
35 |
-
for response in record.responses:
|
36 |
-
user = response.user_id
|
37 |
-
retrieved_user = client.users(id=user)
|
38 |
-
user = retrieved_user.username
|
39 |
-
if user not in user_annotations:
|
40 |
-
user_annotations[user] = 0
|
41 |
-
user_annotations[user] += 1
|
42 |
-
print(user_annotations)
|
43 |
-
return user_annotations
|
44 |
-
|
45 |
-
|
46 |
def create_gauge_chart(progress):
|
47 |
fig = go.Figure(
|
48 |
go.Indicator(
|
@@ -151,13 +136,12 @@ def create_treemap(user_annotations, total_records):
|
|
151 |
def update_dashboard():
|
152 |
dataset = fetch_data(os.getenv("DATASET_NAME"), os.getenv("WORKSPACE"))
|
153 |
progress = get_progress(dataset)
|
154 |
-
|
155 |
-
|
156 |
gauge_chart = create_gauge_chart(progress)
|
157 |
-
treemap = create_treemap(
|
158 |
|
159 |
leaderboard_df = pd.DataFrame(
|
160 |
-
list(
|
161 |
)
|
162 |
leaderboard_df = leaderboard_df.sort_values(
|
163 |
"Annotations", ascending=False
|
|
|
15 |
return client.datasets(dataset_name, workspace=workspace)
|
16 |
|
17 |
|
18 |
+
def get_progress(dataset: rg.Dataset) -> dict:
|
19 |
+
dataset_progress = dataset.progress(with_users_distribution=True)
|
20 |
+
|
21 |
+
total, completed = dataset_progress["total"], dataset_progress["completed"]
|
22 |
+
progress = (completed / total) * 100 if total > 0 else 0
|
23 |
+
|
|
|
24 |
return {
|
25 |
+
"total": total,
|
26 |
+
"annotated": completed,
|
27 |
"progress": progress,
|
28 |
+
"users": dataset_progress["users"]
|
29 |
}
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def create_gauge_chart(progress):
|
32 |
fig = go.Figure(
|
33 |
go.Indicator(
|
|
|
136 |
def update_dashboard():
|
137 |
dataset = fetch_data(os.getenv("DATASET_NAME"), os.getenv("WORKSPACE"))
|
138 |
progress = get_progress(dataset)
|
139 |
+
|
|
|
140 |
gauge_chart = create_gauge_chart(progress)
|
141 |
+
treemap = create_treemap(progress["users"], progress["total"])
|
142 |
|
143 |
leaderboard_df = pd.DataFrame(
|
144 |
+
list(progress["users"].items()), columns=["User", "Annotations"]
|
145 |
)
|
146 |
leaderboard_df = leaderboard_df.sort_values(
|
147 |
"Annotations", ascending=False
|