Spaces:
Runtime error
Runtime error
updating dashboard
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import altair as alt
|
|
8 |
import argilla as rg
|
9 |
from argilla.feedback import FeedbackDataset
|
10 |
from argilla.client.feedback.dataset.remote.dataset import RemoteFeedbackDataset
|
|
|
11 |
import gradio as gr
|
12 |
import pandas as pd
|
13 |
|
@@ -17,6 +18,7 @@ It's designed as a template to recreate the dashboard for the prompt translation
|
|
17 |
|
18 |
To create a new dashboard, you need several environment variables, that you can easily set in the HuggingFace Space that you are using to host the dashboard:
|
19 |
|
|
|
20 |
- SOURCE_DATASET: The dataset id of the source dataset
|
21 |
- SOURCE_WORKSPACE: The workspace id of the source dataset
|
22 |
- TARGET_RECORDS: The number of records that you have as a target to annotate. We usually set this to 500.
|
@@ -25,15 +27,30 @@ To create a new dashboard, you need several environment variables, that you can
|
|
25 |
"""
|
26 |
|
27 |
# Translation of legends and titles
|
28 |
-
ANNOTATED =
|
29 |
-
NUMBER_ANNOTATED =
|
30 |
-
PENDING =
|
31 |
|
32 |
NUMBER_ANNOTATORS = "Number of annotators"
|
33 |
-
NAME =
|
34 |
-
NUMBER_ANNOTATIONS =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
CATEGORY = 'Category'
|
37 |
|
38 |
def obtain_source_target_datasets() -> (
|
39 |
Tuple[
|
@@ -108,19 +125,27 @@ def donut_chart_total() -> alt.Chart:
|
|
108 |
{
|
109 |
"values": [annotated_records, pending_records],
|
110 |
"category": [ANNOTATED, PENDING],
|
111 |
-
"colors": [
|
|
|
|
|
|
|
112 |
}
|
113 |
)
|
114 |
|
115 |
-
domain = source[
|
116 |
-
range_ = source[
|
117 |
|
118 |
base = alt.Chart(source).encode(
|
119 |
theta=alt.Theta("values:Q", stack=True),
|
120 |
radius=alt.Radius(
|
121 |
"values", scale=alt.Scale(type="sqrt", zero=True, rangeMin=20)
|
122 |
),
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
124 |
)
|
125 |
|
126 |
c1 = base.mark_arc(innerRadius=20, stroke="#fff")
|
@@ -146,7 +171,7 @@ def kpi_chart_remaining() -> alt.Chart:
|
|
146 |
# Create Altair chart
|
147 |
chart = (
|
148 |
alt.Chart(data)
|
149 |
-
.mark_text(fontSize=100, align="center", baseline="middle", color="#
|
150 |
.encode(text="Value:N")
|
151 |
.properties(title=PENDING, width=250, height=200)
|
152 |
)
|
@@ -169,7 +194,7 @@ def kpi_chart_submitted() -> alt.Chart:
|
|
169 |
# Create Altair chart
|
170 |
chart = (
|
171 |
alt.Chart(data)
|
172 |
-
.mark_text(fontSize=100, align="center", baseline="middle", color="
|
173 |
.encode(text="Value:N")
|
174 |
.properties(title=NUMBER_ANNOTATED, width=250, height=200)
|
175 |
)
|
@@ -189,9 +214,7 @@ def kpi_chart_total_annotators() -> alt.Chart:
|
|
189 |
total_annotators = len(user_ids_annotations)
|
190 |
|
191 |
# Assuming you have a DataFrame with user data, create a sample DataFrame
|
192 |
-
data = pd.DataFrame(
|
193 |
-
{"Category": [NUMBER_ANNOTATORS], "Value": [total_annotators]}
|
194 |
-
)
|
195 |
|
196 |
# Create Altair chart
|
197 |
chart = (
|
@@ -204,14 +227,14 @@ def kpi_chart_total_annotators() -> alt.Chart:
|
|
204 |
return chart
|
205 |
|
206 |
|
207 |
-
def render_hub_user_link(hub_id:str) -> str:
|
208 |
"""
|
209 |
This function returns a link to the user's profile on Hugging Face.
|
210 |
|
211 |
Args:
|
212 |
hub_id: The user's id on Hugging Face.
|
213 |
|
214 |
-
Returns:
|
215 |
A string with the link to the user's profile on Hugging Face.
|
216 |
"""
|
217 |
link = f"https://huggingface.co/{hub_id}"
|
@@ -258,7 +281,7 @@ def fetch_data() -> None:
|
|
258 |
print(f"Data fetched: {datetime.datetime.now()}")
|
259 |
|
260 |
|
261 |
-
def get_top(N
|
262 |
"""
|
263 |
This function returns the top N users with the most annotations.
|
264 |
|
@@ -290,7 +313,7 @@ def main() -> None:
|
|
290 |
}
|
291 |
"""
|
292 |
|
293 |
-
with gr.Blocks(css=css) as demo:
|
294 |
gr.Markdown(
|
295 |
"""
|
296 |
# π²π¬ Malagasy - Multilingual Prompt Evaluation Project
|
@@ -346,9 +369,7 @@ def main() -> None:
|
|
346 |
with gr.Row():
|
347 |
|
348 |
kpi_hall_plot = gr.Plot(label="Plot")
|
349 |
-
demo.load(
|
350 |
-
kpi_chart_total_annotators, inputs=[], outputs=[kpi_hall_plot]
|
351 |
-
)
|
352 |
|
353 |
top_df_plot = gr.Dataframe(
|
354 |
headers=[NAME, NUMBER_ANNOTATIONS],
|
@@ -362,6 +383,11 @@ def main() -> None:
|
|
362 |
)
|
363 |
demo.load(get_top, None, [top_df_plot])
|
364 |
|
|
|
|
|
|
|
|
|
|
|
365 |
# Launch the Gradio interface
|
366 |
demo.launch()
|
367 |
|
|
|
8 |
import argilla as rg
|
9 |
from argilla.feedback import FeedbackDataset
|
10 |
from argilla.client.feedback.dataset.remote.dataset import RemoteFeedbackDataset
|
11 |
+
from huggingface_hub import restart_space
|
12 |
import gradio as gr
|
13 |
import pandas as pd
|
14 |
|
|
|
18 |
|
19 |
To create a new dashboard, you need several environment variables, that you can easily set in the HuggingFace Space that you are using to host the dashboard:
|
20 |
|
21 |
+
- HF_TOKEN: Token with write access from your Hugging Face account: https://huggingface.co/settings/tokens
|
22 |
- SOURCE_DATASET: The dataset id of the source dataset
|
23 |
- SOURCE_WORKSPACE: The workspace id of the source dataset
|
24 |
- TARGET_RECORDS: The number of records that you have as a target to annotate. We usually set this to 500.
|
|
|
27 |
"""
|
28 |
|
29 |
# Translation of legends and titles
|
30 |
+
ANNOTATED = "Annotations"
|
31 |
+
NUMBER_ANNOTATED = "Total Annotations"
|
32 |
+
PENDING = "Pending"
|
33 |
|
34 |
NUMBER_ANNOTATORS = "Number of annotators"
|
35 |
+
NAME = "Username"
|
36 |
+
NUMBER_ANNOTATIONS = "Number of annotations"
|
37 |
+
|
38 |
+
CATEGORY = "Category"
|
39 |
+
|
40 |
+
|
41 |
+
def restart() -> None:
|
42 |
+
"""
|
43 |
+
This function restarts the space where the dashboard is hosted.
|
44 |
+
"""
|
45 |
+
|
46 |
+
# Update Space name with your Space information
|
47 |
+
gr.Info("Restarting space at " + str(datetime.datetime.now()))
|
48 |
+
restart_space(
|
49 |
+
"ignacioct/TryingRestartDashboard",
|
50 |
+
token=os.getenv("HF_TOKEN"),
|
51 |
+
# factory_reboot=True,
|
52 |
+
)
|
53 |
|
|
|
54 |
|
55 |
def obtain_source_target_datasets() -> (
|
56 |
Tuple[
|
|
|
125 |
{
|
126 |
"values": [annotated_records, pending_records],
|
127 |
"category": [ANNOTATED, PENDING],
|
128 |
+
"colors": [
|
129 |
+
"#4682b4",
|
130 |
+
"#e68c39",
|
131 |
+
], # Blue for Completed, Orange for Remaining
|
132 |
}
|
133 |
)
|
134 |
|
135 |
+
domain = source["category"].tolist()
|
136 |
+
range_ = source["colors"].tolist()
|
137 |
|
138 |
base = alt.Chart(source).encode(
|
139 |
theta=alt.Theta("values:Q", stack=True),
|
140 |
radius=alt.Radius(
|
141 |
"values", scale=alt.Scale(type="sqrt", zero=True, rangeMin=20)
|
142 |
),
|
143 |
+
color=alt.Color(
|
144 |
+
field="category",
|
145 |
+
type="nominal",
|
146 |
+
scale=alt.Scale(domain=domain, range=range_),
|
147 |
+
legend=alt.Legend(title=CATEGORY),
|
148 |
+
),
|
149 |
)
|
150 |
|
151 |
c1 = base.mark_arc(innerRadius=20, stroke="#fff")
|
|
|
171 |
# Create Altair chart
|
172 |
chart = (
|
173 |
alt.Chart(data)
|
174 |
+
.mark_text(fontSize=100, align="center", baseline="middle", color="#e68b39")
|
175 |
.encode(text="Value:N")
|
176 |
.properties(title=PENDING, width=250, height=200)
|
177 |
)
|
|
|
194 |
# Create Altair chart
|
195 |
chart = (
|
196 |
alt.Chart(data)
|
197 |
+
.mark_text(fontSize=100, align="center", baseline="middle", color="steelblue")
|
198 |
.encode(text="Value:N")
|
199 |
.properties(title=NUMBER_ANNOTATED, width=250, height=200)
|
200 |
)
|
|
|
214 |
total_annotators = len(user_ids_annotations)
|
215 |
|
216 |
# Assuming you have a DataFrame with user data, create a sample DataFrame
|
217 |
+
data = pd.DataFrame({"Category": [NUMBER_ANNOTATORS], "Value": [total_annotators]})
|
|
|
|
|
218 |
|
219 |
# Create Altair chart
|
220 |
chart = (
|
|
|
227 |
return chart
|
228 |
|
229 |
|
230 |
+
def render_hub_user_link(hub_id: str) -> str:
|
231 |
"""
|
232 |
This function returns a link to the user's profile on Hugging Face.
|
233 |
|
234 |
Args:
|
235 |
hub_id: The user's id on Hugging Face.
|
236 |
|
237 |
+
Returns:
|
238 |
A string with the link to the user's profile on Hugging Face.
|
239 |
"""
|
240 |
link = f"https://huggingface.co/{hub_id}"
|
|
|
281 |
print(f"Data fetched: {datetime.datetime.now()}")
|
282 |
|
283 |
|
284 |
+
def get_top(N=50) -> pd.DataFrame:
|
285 |
"""
|
286 |
This function returns the top N users with the most annotations.
|
287 |
|
|
|
313 |
}
|
314 |
"""
|
315 |
|
316 |
+
with gr.Blocks(css=css, delete_cache=(300, 300)) as demo:
|
317 |
gr.Markdown(
|
318 |
"""
|
319 |
# π²π¬ Malagasy - Multilingual Prompt Evaluation Project
|
|
|
369 |
with gr.Row():
|
370 |
|
371 |
kpi_hall_plot = gr.Plot(label="Plot")
|
372 |
+
demo.load(kpi_chart_total_annotators, inputs=[], outputs=[kpi_hall_plot])
|
|
|
|
|
373 |
|
374 |
top_df_plot = gr.Dataframe(
|
375 |
headers=[NAME, NUMBER_ANNOTATIONS],
|
|
|
383 |
)
|
384 |
demo.load(get_top, None, [top_df_plot])
|
385 |
|
386 |
+
# Manage background refresh
|
387 |
+
scheduler = BackgroundScheduler()
|
388 |
+
_ = scheduler.add_job(restart, "interval", minutes=30)
|
389 |
+
scheduler.start()
|
390 |
+
|
391 |
# Launch the Gradio interface
|
392 |
demo.launch()
|
393 |
|