daniescamilla commited on
Commit
e34a145
·
verified ·
1 Parent(s): ce8ba5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -40
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import pandas as pd
3
  from collections import Counter
4
  import gradio as gr
@@ -9,6 +10,7 @@ client = rg.Argilla(
9
  api_url=os.getenv("ARGILLA_API_URL"), api_key=os.getenv("ARGILLA_API_KEY")
10
  )
11
 
 
12
  def fetch_data(dataset_name: str, workspace: str):
13
  """
14
  Fetch dataset from Argilla.
@@ -27,6 +29,28 @@ def fetch_data(dataset_name: str, workspace: str):
27
  print(f"Error fetching dataset: {e}")
28
  return None
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def get_leaderboard(dataset) -> dict:
31
  """
32
  Get the leaderboard of user contributions.
@@ -46,6 +70,7 @@ def get_leaderboard(dataset) -> dict:
46
  contributions[unique_key] = client.users(id=first_response.user_id).username
47
  return dict(Counter(contributions.values()))
48
 
 
49
  def update_dashboard():
50
  """
51
  Update the dashboard with the latest data.
@@ -62,75 +87,110 @@ def update_dashboard():
62
  )
63
  leaderboard_df = leaderboard_df.sort_values("Contribuciones", ascending=False).head(5)
64
 
65
- # Añadir emojis de medallas
66
- leaderboard_df["Usuario"] = leaderboard_df.apply(
67
- lambda row: f"🥇 {row['Usuario']}" if row.name == 0 else
68
- f"🥈 {row['Usuario']}" if row.name == 1 else
69
- f"🥉 {row['Usuario']}" if row.name == 2 else
70
- f"🎖️ {row['Usuario']}", axis=1
71
- )
72
-
73
  # Reset index for better display
74
  leaderboard_df.reset_index(drop=True, inplace=True)
75
 
76
  return leaderboard_df
77
 
78
- # CSS personalizado para estilizar el dashboard
79
- custom_css = """
80
 
81
- /* Estilo para el título */
 
 
 
 
 
 
 
82
  h1 {
83
- font-size: 2.5rem !important;
84
- font-weight: 600 !important;
85
- color: white !important;
86
- margin-bottom: 20px !important;
87
  }
88
-
89
- /* Estilo para el DataFrame */
90
  .dataframe {
91
- width: 100% !important;
92
- heigth: 100% !important;
93
- margin: 0 auto !important;
94
- border-collapse: collapse !important;
95
- font-size: 1.1rem !important;
96
- color: grey
 
 
97
  }
98
-
99
- /* Colores de medallas para las filas */
100
- .dataframe tr:nth-child(1) {
101
- background-color: #FFD700 !important; /* Oro */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  }
103
  .dataframe tr:nth-child(2) {
104
- background-color: #C0C0C0 !important; /* Plata */
 
105
  }
106
  .dataframe tr:nth-child(3) {
107
- background-color: #CD7F32 !important; /* Bronce */
 
108
  }
109
-
110
- /* Estilo para los botones */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  button {
112
- background-color: #4CAF50 !important;
 
 
 
113
  color: white !important;
114
  border: none !important;
115
- padding: 10px 20px !important;
116
- font-size: 1rem !important;
117
  border-radius: 5px !important;
118
  cursor: pointer !important;
119
- margin-top: 20px !important;
120
  }
121
-
122
  button:hover {
123
- background-color: #45a049 !important;
 
 
 
 
124
  }
125
  """
126
 
 
127
  # Gradio Interface
128
  with gr.Blocks(css=custom_css) as demo:
129
- gr.Markdown("# 🏆 Ranking Contribuciones Letras Carnaval Cádiz")
130
 
131
  with gr.Row():
132
  leaderboard_output = gr.Dataframe(
133
- headers=["Usuario", "Contribuciones"],
134
  datatype=["str", "number"],
135
  interactive=False,
136
  elem_classes="dataframe",
@@ -141,11 +201,12 @@ with gr.Blocks(css=custom_css) as demo:
141
  inputs=None,
142
  outputs=[leaderboard_output],
143
  )
144
- gr.Button("🔄 Actualizar").click(
145
  update_dashboard,
146
  inputs=None,
147
  outputs=[leaderboard_output],
148
  )
149
 
 
150
  if __name__ == "__main__":
151
  demo.launch()
 
1
  import os
2
+ import datetime
3
  import pandas as pd
4
  from collections import Counter
5
  import gradio as gr
 
10
  api_url=os.getenv("ARGILLA_API_URL"), api_key=os.getenv("ARGILLA_API_KEY")
11
  )
12
 
13
+
14
  def fetch_data(dataset_name: str, workspace: str):
15
  """
16
  Fetch dataset from Argilla.
 
29
  print(f"Error fetching dataset: {e}")
30
  return None
31
 
32
+
33
+ def get_progress(dataset) -> dict:
34
+ """
35
+ Calculate the annotation progress of the dataset.
36
+ Args:
37
+ dataset: The dataset to calculate progress for.
38
+ Returns:
39
+ A dictionary with the total number of records, the number of annotated records, and the progress percentage.
40
+ """
41
+ records = list(dataset.records)
42
+ total_records = len(records)
43
+ annotated_records = len(
44
+ [record.status for record in records if record.status == "completed"]
45
+ )
46
+ progress = (annotated_records / total_records) * 100 if total_records > 0 else 0
47
+ return {
48
+ "total": total_records,
49
+ "annotated": annotated_records,
50
+ "progress": progress,
51
+ }
52
+
53
+
54
  def get_leaderboard(dataset) -> dict:
55
  """
56
  Get the leaderboard of user contributions.
 
70
  contributions[unique_key] = client.users(id=first_response.user_id).username
71
  return dict(Counter(contributions.values()))
72
 
73
+
74
  def update_dashboard():
75
  """
76
  Update the dashboard with the latest data.
 
87
  )
88
  leaderboard_df = leaderboard_df.sort_values("Contribuciones", ascending=False).head(5)
89
 
 
 
 
 
 
 
 
 
90
  # Reset index for better display
91
  leaderboard_df.reset_index(drop=True, inplace=True)
92
 
93
  return leaderboard_df
94
 
 
 
95
 
96
+ # Custom CSS for styling
97
+ custom_css = """
98
+ .gradio-container {
99
+ font-family: 'Poppins', sans-serif; /* Fuente moderna */
100
+ background-color: white; /* Fondo blanco */
101
+ padding: 20px;
102
+ border-radius: 10px;
103
+ }
104
  h1 {
105
+ color: #2c3e50; /* Color oscuro para el título */
106
+ text-align: center;
107
+ font-size: 32px;
108
+ margin-bottom: 20px;
109
  }
 
 
110
  .dataframe {
111
+ width: 100%;
112
+ border-collapse: collapse;
113
+ margin: 0 auto;
114
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
115
+ border-radius: 10px;
116
+ overflow: hidden;
117
+ background-color: white; /* Fondo blanco para la tabla */
118
+ border: 1px solid white; /* Líneas separadoras blancas */
119
  }
120
+ .dataframe th, .dataframe td {
121
+ padding: 12px 15px;
122
+ text-align: left;
123
+ border-bottom: 1px solid white; /* Líneas separadoras blancas */
124
+ }
125
+ .dataframe th {
126
+ background-color: #6c757d; /* Color más neutro (gris) */
127
+ color: white;
128
+ font-weight: bold;
129
+ }
130
+ .dataframe tr:nth-child(even) {
131
+ background-color: #f8f9fa; /* Fondo gris claro para filas pares */
132
+ }
133
+ .dataframe tr:hover {
134
+ background-color: #e9ecef; /* Color de hover más suave */
135
+ }
136
+ .dataframe tr:first-child {
137
+ background-color: #FFD700; /* Dorado para el 1er puesto */
138
+ color: #000; /* Texto negro para mejor contraste */
139
  }
140
  .dataframe tr:nth-child(2) {
141
+ background-color: #C0C0C0; /* Plateado para el 2do puesto */
142
+ color: #000; /* Texto negro para mejor contraste */
143
  }
144
  .dataframe tr:nth-child(3) {
145
+ background-color: #cd7f32; /* Bronce para el 3er puesto */
146
+ color: #000; /* Texto negro para mejor contraste */
147
  }
148
+ .dataframe tr:nth-child(4), .dataframe tr:nth-child(5) {
149
+ background-color: #2c3e50; /* Color oscuro para el y 5º puesto */
150
+ color: #fff; /* Texto blanco para mejor contraste */
151
+ }
152
+ /* Añadir emojis a los puestos */
153
+ .dataframe tr:first-child td:first-child::before {
154
+ content: "🥇 "; /* Emoji para el 1er puesto */
155
+ }
156
+ .dataframe tr:nth-child(2) td:first-child::before {
157
+ content: "🥈 "; /* Emoji para el 2do puesto */
158
+ }
159
+ .dataframe tr:nth-child(3) td:first-child::before {
160
+ content: "🥉 "; /* Emoji para el 3er puesto */
161
+ }
162
+ .dataframe tr:nth-child(4) td:first-child::before,
163
+ .dataframe tr:nth-child(5) td:first-child::before {
164
+ content: "🎖️ "; /* Emoji para el 4º y 5º puesto */
165
+ }
166
+ /* Estilo para el botón */
167
  button {
168
+ width: auto !important; /* Ancho automático */
169
+ padding: 10px 20px !important; /* Padding más pequeño */
170
+ font-size: 16px !important;
171
+ background-color: #6c757d !important; /* Color más neutro */
172
  color: white !important;
173
  border: none !important;
 
 
174
  border-radius: 5px !important;
175
  cursor: pointer !important;
 
176
  }
 
177
  button:hover {
178
+ background-color: #5a6268 !important; /* Color más oscuro al pasar el ratón */
179
+ }
180
+ /* Eliminar scroll */
181
+ .dataframe {
182
+ overflow: hidden !important; /* Eliminar scroll */
183
  }
184
  """
185
 
186
+
187
  # Gradio Interface
188
  with gr.Blocks(css=custom_css) as demo:
189
+ gr.Markdown("# 🏆 Ranking Contribuciones Letras Carnaval Cádiz") # Emoji en el título
190
 
191
  with gr.Row():
192
  leaderboard_output = gr.Dataframe(
193
+ headers=["Usuario", "Contribuciones"], # Cambiado a "Usuario" y "Contribuciones"
194
  datatype=["str", "number"],
195
  interactive=False,
196
  elem_classes="dataframe",
 
201
  inputs=None,
202
  outputs=[leaderboard_output],
203
  )
204
+ gr.Button("🔄 Actualizar").click( # Emoji en el botón y texto "Actualizar"
205
  update_dashboard,
206
  inputs=None,
207
  outputs=[leaderboard_output],
208
  )
209
 
210
+
211
  if __name__ == "__main__":
212
  demo.launch()