Spaces:
Sleeping
Sleeping
add spreadsheet syncing
Browse files
app.ipynb
CHANGED
@@ -16,6 +16,7 @@
|
|
16 |
"outputs": [],
|
17 |
"source": [
|
18 |
"import json\n",
|
|
|
19 |
"import gradio as gr\n",
|
20 |
"\n",
|
21 |
"\n",
|
@@ -151,10 +152,12 @@
|
|
151 |
" # update overall ratings\n",
|
152 |
" task['overall'] = overall\n",
|
153 |
" task['notes'] = notes\n",
|
154 |
-
" # save the task to json file\n",
|
155 |
" try:\n",
|
|
|
156 |
" with open(f'./data/demo_task_{task_id}.json', 'w', encoding='utf-8') as task_file:\n",
|
157 |
" json.dump(task, task_file, ensure_ascii=False, indent=4)\n",
|
|
|
|
|
158 |
" gr.Info(f'Task demo_task_{task_id} is saved!')\n",
|
159 |
" except:\n",
|
160 |
" raise gr.Error(f'Could not save the task demo_task_{task_id} :(')\n",
|
@@ -177,15 +180,46 @@
|
|
177 |
" # erase overall ratings\n",
|
178 |
" task['overall'] = ''\n",
|
179 |
" task['notes'] = ''\n",
|
180 |
-
" # save the reset task to json file\n",
|
181 |
" try:\n",
|
|
|
182 |
" with open(f'./data/demo_task_{task_id}.json', 'w', encoding='utf-8') as task_file:\n",
|
183 |
" json.dump(task, task_file, ensure_ascii=False, indent=4)\n",
|
184 |
-
"
|
|
|
|
|
185 |
" except:\n",
|
186 |
" raise gr.Error(f'Could not reset the task demo_task_{task_id} :(')\n",
|
187 |
" return '', '', '', '', '', '', '', '', '', ''\n",
|
188 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
" def launch_interface(self):\n",
|
190 |
" \"\"\"Launch the A/B Evaluation RAG task interface.\"\"\"\n",
|
191 |
" gr.close_all()\n",
|
|
|
16 |
"outputs": [],
|
17 |
"source": [
|
18 |
"import json\n",
|
19 |
+
"import gspread\n",
|
20 |
"import gradio as gr\n",
|
21 |
"\n",
|
22 |
"\n",
|
|
|
152 |
" # update overall ratings\n",
|
153 |
" task['overall'] = overall\n",
|
154 |
" task['notes'] = notes\n",
|
|
|
155 |
" try:\n",
|
156 |
+
" # save the task to json file\n",
|
157 |
" with open(f'./data/demo_task_{task_id}.json', 'w', encoding='utf-8') as task_file:\n",
|
158 |
" json.dump(task, task_file, ensure_ascii=False, indent=4)\n",
|
159 |
+
" # save the task to google spreadsheet\n",
|
160 |
+
" self.save_gsheet(task_id, ratings)\n",
|
161 |
" gr.Info(f'Task demo_task_{task_id} is saved!')\n",
|
162 |
" except:\n",
|
163 |
" raise gr.Error(f'Could not save the task demo_task_{task_id} :(')\n",
|
|
|
180 |
" # erase overall ratings\n",
|
181 |
" task['overall'] = ''\n",
|
182 |
" task['notes'] = ''\n",
|
|
|
183 |
" try:\n",
|
184 |
+
" # save the reset task to json file\n",
|
185 |
" with open(f'./data/demo_task_{task_id}.json', 'w', encoding='utf-8') as task_file:\n",
|
186 |
" json.dump(task, task_file, ensure_ascii=False, indent=4)\n",
|
187 |
+
" # save the reset task to google spreadsheet\n",
|
188 |
+
" self.reset_gsheet(task_id)\n",
|
189 |
+
" gr.Info(f'Task demo_task_{task_id} is reset!')\n",
|
190 |
" except:\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, id, ratings):\n",
|
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 |
+
" sh.update(range_name=f'C{3+int(id)}:J{3+int(id)}',\n",
|
207 |
+
" values=[[groundedness1, fluency1, utility1, groundedness2, fluency2, utility2, overall, notes]])\n",
|
208 |
+
" except:\n",
|
209 |
+
" gr.Warning(f'Could not save the task demo_task_{task_id} to the spreadsheet :(')\n",
|
210 |
+
"\n",
|
211 |
+
" def reset_gsheet(self, id):\n",
|
212 |
+
" \"\"\"Reset the task ratings in google spreadsheet.\"\"\"\n",
|
213 |
+
" try:\n",
|
214 |
+
" # configure gsheet credentials\n",
|
215 |
+
" gc = gspread.service_account('./gsheet_service_account.json')\n",
|
216 |
+
" sheet_id = '1D2sfE9YXKtd7cKlgalo5UnuNKC-GhxlGqHVYUlkQlCY'\n",
|
217 |
+
" sh = gc.open_by_key(sheet_id).worksheet('demo-app')\n",
|
218 |
+
" # update task ratings in the worksheet\n",
|
219 |
+
" sh.batch_clear([f'C{3+int(id)}:J{3+int(id)}'])\n",
|
220 |
+
" except:\n",
|
221 |
+
" gr.Warning(f'Could not reset the task demo_task_{task_id} in the spreadsheet :(')\n",
|
222 |
+
"\n",
|
223 |
" def launch_interface(self):\n",
|
224 |
" \"\"\"Launch the A/B Evaluation RAG task interface.\"\"\"\n",
|
225 |
" gr.close_all()\n",
|