Spaces:
Sleeping
Sleeping
do not write empty values to gsheet
Browse files
app.ipynb
CHANGED
@@ -191,20 +191,19 @@
|
|
191 |
" raise gr.Error(f'Could not reset the task demo_task_{task_id} :(')\n",
|
192 |
" return '', '', '', '', '', '', '', '', '', ''\n",
|
193 |
"\n",
|
194 |
-
" def save_gsheet(self,
|
195 |
" \"\"\"Save the task to google spreadsheet.\"\"\"\n",
|
196 |
-
" # parse the ratings\n",
|
197 |
-
" groundedness1, fluency1, utility1, notes1, \\\n",
|
198 |
-
" groundedness2, fluency2, utility2, notes2, \\\n",
|
199 |
-
" overall, notes = ratings\n",
|
200 |
" try:\n",
|
201 |
" # configure gsheet credentials\n",
|
202 |
" gc = gspread.service_account('./gsheet_service_account.json')\n",
|
203 |
" sheet_id = '1D2sfE9YXKtd7cKlgalo5UnuNKC-GhxlGqHVYUlkQlCY'\n",
|
204 |
" sh = gc.open_by_key(sheet_id).worksheet('demo-app')\n",
|
205 |
-
" # update task ratings in the worksheet\n",
|
206 |
-
"
|
207 |
-
"
|
|
|
|
|
|
|
208 |
" except:\n",
|
209 |
" gr.Warning(f'Could not save the task demo_task_{task_id} to the spreadsheet :(')\n",
|
210 |
"\n",
|
|
|
191 |
" raise gr.Error(f'Could not reset the task demo_task_{task_id} :(')\n",
|
192 |
" return '', '', '', '', '', '', '', '', '', ''\n",
|
193 |
"\n",
|
194 |
+
" def save_gsheet(self, task_id, ratings):\n",
|
195 |
" \"\"\"Save the task to google spreadsheet.\"\"\"\n",
|
|
|
|
|
|
|
|
|
196 |
" try:\n",
|
197 |
" # configure gsheet credentials\n",
|
198 |
" gc = gspread.service_account('./gsheet_service_account.json')\n",
|
199 |
" sheet_id = '1D2sfE9YXKtd7cKlgalo5UnuNKC-GhxlGqHVYUlkQlCY'\n",
|
200 |
" sh = gc.open_by_key(sheet_id).worksheet('demo-app')\n",
|
201 |
+
" # update non-empty task ratings in the worksheet\n",
|
202 |
+
" cell_val = []\n",
|
203 |
+
" for idx, rating in enumerate([ratings[idx] for idx in [0,1,2,4,5,6,8,9]]):\n",
|
204 |
+
" if rating:\n",
|
205 |
+
" cell_val.append({'range': f'{chr(67+idx)}{3+int(task_id)}', 'values': [[f'{rating}']]})\n",
|
206 |
+
" sh.batch_update(cell_val)\n",
|
207 |
" except:\n",
|
208 |
" gr.Warning(f'Could not save the task demo_task_{task_id} to the spreadsheet :(')\n",
|
209 |
"\n",
|