dvilasuero HF staff commited on
Commit
abb2057
β€’
1 Parent(s): 372b939

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
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
- annotated_records = len(source_dataset)
72
- total_records = int(os.getenv("TARGET_RECORDS"))
73
- percentage_complete = annotated_records / total_records * 100
 
74
 
75
- # Data for the progress bar
76
  progress_data = pd.DataFrame({
77
- 'category': ['Progress'],
78
  'percentage': [percentage_complete]
79
  })
80
 
81
- # Data for the total label
82
- total_label = pd.DataFrame({
83
- 'category': ['Total'],
84
- 'percentage': [100],
85
- 'label': [f'{annotated_records} / {total_records}']
86
  })
87
 
88
- # Progress bar
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
- # Total label
94
- total_text = alt.Chart(total_label).mark_text(dx=5, dy=-5, align='left', fontSize=15, fontWeight='bold').encode(
95
- x=alt.X('percentage:Q'),
96
  text=alt.Text('label:N')
97
  )
98
 
99
- # Combine the bar and the label
100
- chart = progress_bar + total_text
101
-
102
- # Optionally, add a title
103
- chart = chart.properties(title='Progress Towards Goal')
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