周倬孚 commited on
Commit
a6f3675
·
1 Parent(s): 507564e

fix bugs on auto save

Browse files
Files changed (2) hide show
  1. app.py +16 -13
  2. save_data.py +1 -1
app.py CHANGED
@@ -173,8 +173,9 @@ if __name__ == "__main__":
173
  login_button.click(login, inputs=identification_code, outputs=[task, group_a_content, group_b_content, group_c_content, login_status])
174
 
175
 
176
-
177
  with group_a_content:
 
178
  with gr.Row():
179
  human_input = gr.Textbox(label="Human Input (preperably between 100 and 150 words)")
180
  with gr.Row():
@@ -203,12 +204,13 @@ if __name__ == "__main__":
203
  save_result = gr.Label()
204
 
205
  save_btn.click(
206
- fn=lambda session_index: save_data(session_index, session_manager, service, SHEET_ID1),
207
- inputs=[session_index],
208
  outputs=[save_result]
209
  )
210
 
211
  with group_b_content:
 
212
  with gr.Row():
213
  human_input = gr.Textbox(label="Human Input (preperably between 100 and 150 words)")
214
  with gr.Row():
@@ -240,12 +242,13 @@ if __name__ == "__main__":
240
  save_result = gr.Label()
241
 
242
  save_btn.click(
243
- fn=lambda session_index: save_data(session_index, session_manager, service, SHEET_ID2),
244
- inputs=[session_index],
245
  outputs=[save_result]
246
  )
247
 
248
  with group_c_content:
 
249
  with gr.Row():
250
  create_initial_btn = gr.Button("Create")
251
  with gr.Row():
@@ -283,8 +286,8 @@ if __name__ == "__main__":
283
  save_result = gr.Label()
284
 
285
  save_btn.click(
286
- fn=lambda session_index: save_data(session_index, session_manager, service, SHEET_ID3),
287
- inputs=[session_index],
288
  outputs=[save_result]
289
  )
290
 
@@ -295,12 +298,12 @@ if __name__ == "__main__":
295
  auto_save_btn = gr.Button("Auto Save", visible=False)
296
  auto_save_result = gr.Label(visible=False)
297
 
298
- def auto_save(session_index):
299
- return save_data(session_index, session_manager, service, SHEET_ID1)
300
 
301
  auto_save_btn.click(
302
- fn=lambda session_index: auto_save(session_index),
303
- inputs=[session_index],
304
  outputs=[auto_save_result]
305
  )
306
 
@@ -320,7 +323,7 @@ if __name__ == "__main__":
320
  </script>
321
  """
322
 
323
- app.add_component(gr.HTML(auto_save_js))
324
 
325
 
326
- app.launch(share=True)
 
173
  login_button.click(login, inputs=identification_code, outputs=[task, group_a_content, group_b_content, group_c_content, login_status])
174
 
175
 
176
+ sheet_id = None
177
  with group_a_content:
178
+ sheet_id = SHEET_ID1
179
  with gr.Row():
180
  human_input = gr.Textbox(label="Human Input (preperably between 100 and 150 words)")
181
  with gr.Row():
 
204
  save_result = gr.Label()
205
 
206
  save_btn.click(
207
+ fn=lambda session_index, sheet_id: save_data(session_index, session_manager, service, sheet_id),
208
+ inputs=[session_index, sheet_id],
209
  outputs=[save_result]
210
  )
211
 
212
  with group_b_content:
213
+ sheet_id = SHEET_ID2
214
  with gr.Row():
215
  human_input = gr.Textbox(label="Human Input (preperably between 100 and 150 words)")
216
  with gr.Row():
 
242
  save_result = gr.Label()
243
 
244
  save_btn.click(
245
+ fn=lambda session_index, sheet_id: save_data(session_index, session_manager, service, sheet_id),
246
+ inputs=[session_index, sheet_id],
247
  outputs=[save_result]
248
  )
249
 
250
  with group_c_content:
251
+ sheet_id = SHEET_ID3
252
  with gr.Row():
253
  create_initial_btn = gr.Button("Create")
254
  with gr.Row():
 
286
  save_result = gr.Label()
287
 
288
  save_btn.click(
289
+ fn=lambda session_index, sheet_id: save_data(session_index, session_manager, service, sheet_id),
290
+ inputs=[session_index, sheet_id],
291
  outputs=[save_result]
292
  )
293
 
 
298
  auto_save_btn = gr.Button("Auto Save", visible=False)
299
  auto_save_result = gr.Label(visible=False)
300
 
301
+ def auto_save(session_index, sheet_id):
302
+ return save_data(session_index, session_manager, service, sheet_id)
303
 
304
  auto_save_btn.click(
305
+ fn=lambda session_index: auto_save(session_index, sheet_id),
306
+ inputs=[session_index, sheet_id],
307
  outputs=[auto_save_result]
308
  )
309
 
 
323
  </script>
324
  """
325
 
326
+ gr.HTML(auto_save_js)
327
 
328
 
329
+ app.launch(share=True)
save_data.py CHANGED
@@ -41,7 +41,7 @@ def col_letter(col_num):
41
  return letter
42
 
43
  def is_redudant_data(new_row, last_row):
44
- return new_row == last_row
45
 
46
  def add_new_data(new_row, service, SPREADSHEET_ID, num_of_columns = 5):
47
  """Add new data to the spreadsheet.
 
41
  return letter
42
 
43
  def is_redudant_data(new_row, last_row):
44
+ return new_row[0] == last_row[0] #compare vertification id
45
 
46
  def add_new_data(new_row, service, SPREADSHEET_ID, num_of_columns = 5):
47
  """Add new data to the spreadsheet.