Spaces:
Runtime error
Runtime error
Commit
β’
abb2057
1
Parent(s):
372b939
Update app.py
Browse files
app.py
CHANGED
@@ -66,41 +66,46 @@ import altair as alt
|
|
66 |
import pandas as pd
|
67 |
import os
|
68 |
|
|
|
|
|
|
|
|
|
69 |
def progress_bar_chart() -> alt.Chart:
|
70 |
source_dataset, _ = obtain_source_target_datasets()
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
74 |
|
75 |
-
#
|
76 |
progress_data = pd.DataFrame({
|
77 |
-
'category': ['
|
78 |
'percentage': [percentage_complete]
|
79 |
})
|
80 |
|
81 |
-
#
|
82 |
-
|
83 |
-
'category': ['
|
84 |
-
'percentage': [
|
85 |
-
'label': [f'{
|
86 |
})
|
87 |
|
88 |
-
#
|
89 |
progress_bar = alt.Chart(progress_data).mark_bar(color='lightgreen', size=50).encode(
|
90 |
x=alt.X('percentage:Q', axis=alt.Axis(title='Completion Percentage', format='%'), scale=alt.Scale(domain=(0, 100)))
|
91 |
)
|
92 |
|
93 |
-
#
|
94 |
-
|
95 |
-
x=alt.X('percentage:Q'),
|
96 |
text=alt.Text('label:N')
|
97 |
)
|
98 |
|
99 |
-
# Combine the bar and the
|
100 |
-
chart = progress_bar +
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
|
105 |
return chart
|
106 |
|
|
|
66 |
import pandas as pd
|
67 |
import os
|
68 |
|
69 |
+
import altair as alt
|
70 |
+
import pandas as pd
|
71 |
+
import os
|
72 |
+
|
73 |
def progress_bar_chart() -> alt.Chart:
|
74 |
source_dataset, _ = obtain_source_target_datasets()
|
75 |
+
total_records = int(os.getenv("TARGET_RECORDS")) # This should be the total number of records you want to annotate.
|
76 |
+
annotated_records = len(source_dataset) # This is the number of records already annotated.
|
77 |
+
pending_records = total_records - annotated_records # Calculate the pending records.
|
78 |
+
percentage_complete = annotated_records / total_records * 100 # The percentage of completion.
|
79 |
|
80 |
+
# Create a DataFrame for the progress bar data.
|
81 |
progress_data = pd.DataFrame({
|
82 |
+
'category': ['Annotated'],
|
83 |
'percentage': [percentage_complete]
|
84 |
})
|
85 |
|
86 |
+
# Create a DataFrame for the annotation label.
|
87 |
+
annotation_label = pd.DataFrame({
|
88 |
+
'category': ['Pending'],
|
89 |
+
'percentage': [percentage_complete],
|
90 |
+
'label': [f'{pending_records} / {annotated_records}']
|
91 |
})
|
92 |
|
93 |
+
# Create the progress bar chart.
|
94 |
progress_bar = alt.Chart(progress_data).mark_bar(color='lightgreen', size=50).encode(
|
95 |
x=alt.X('percentage:Q', axis=alt.Axis(title='Completion Percentage', format='%'), scale=alt.Scale(domain=(0, 100)))
|
96 |
)
|
97 |
|
98 |
+
# Add the annotation text to the chart.
|
99 |
+
annotation_text = alt.Chart(annotation_label).mark_text(dx=-15, dy=20, align='right', fontSize=16, fontWeight='bold').encode(
|
100 |
+
x=alt.X('percentage:Q', stack='zero'),
|
101 |
text=alt.Text('label:N')
|
102 |
)
|
103 |
|
104 |
+
# Combine the progress bar and the annotation text.
|
105 |
+
chart = (progress_bar + annotation_text).properties(
|
106 |
+
title='Progress Towards Goal',
|
107 |
+
width=700
|
108 |
+
)
|
109 |
|
110 |
return chart
|
111 |
|