ChenyuRabbitLove commited on
Commit
20cc6ef
1 Parent(s): 96a04e2

bugfix: fix minor bugs

Browse files
app.py CHANGED
@@ -67,9 +67,11 @@ def get_player_logs(player_backend_user_id):
67
  f"Player {player_backend_user_id} not found in processed_player_adventure_logs.json"
68
  )
69
 
 
70
  def init_reward():
71
  return CompletionReward()
72
 
 
73
  # start of gradio interface
74
  with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
75
  player_info = gr.State()
@@ -93,7 +95,9 @@ with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
93
  height=200,
94
  )
95
 
96
- badge_description = gr.Markdown("# 徽章", elem_id="badge_avatar_description")
 
 
97
  badge_gallery = gr.Gallery(
98
  [],
99
  label="徽章",
@@ -140,11 +144,15 @@ with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
140
  "<div style='max-width:100%; max-height:360px; overflow:auto'>"
141
  + get_content("htmls/adventure_blank.html")
142
  )
143
- adventure_log = gr.HTML(html, label="Adventure Log", elem_id="adventure_log")
 
 
144
 
145
  # handling player info
146
  with gr.Row():
147
- player_backend_id = gr.Textbox("", elem_id="player_backend_id", visible=False)
 
 
148
  player_info_query_btn = gr.Button(
149
  "Query", elem_id="trigger_button", visible=False
150
  )
@@ -293,207 +301,209 @@ with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
293
 
294
  # actions when player login
295
  # define args
296
- # send_player_login_info = dict(
297
- # fn=render_finished,
298
- # inputs=[player_activity_tracker, player_info],
299
- # outputs=None,
300
- # )
301
-
302
- # player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
303
- # render_player_data,
304
- # player_info,
305
- # [avatar, pet_gallery, badge_gallery, adventure_log, achievements, adventure],
306
- # ).then(
307
- # **send_player_login_info
308
- # )
309
-
310
- # pull_newest_player_data.submit(
311
- # save_latest_player_data,
312
- # None,
313
- # update_status,
314
- # api_name="pull_newest_player_data",
315
- # )
316
-
317
- # def create_visibility_updates(visible, count):
318
- # return tuple(gr.update(visible=visible) for _ in range(count))
319
-
320
- # start_make_reward.click(
321
- # check_is_in_completion_reward,
322
- # player_backend_id,
323
- # [
324
- # start_make_reward,
325
- # player_name_title,
326
- # player_name,
327
- # confirm_player_name,
328
- # not_participate,
329
- # not_start,
330
- # already_issued,
331
- # ],
332
- # queue=False,
333
- # )
334
-
335
- # set_player_name_args = dict(
336
- # fn=set_player_name,
337
- # inputs=[completion_reward, player_name, player_backend_id],
338
- # outputs=None,
339
- # queue=False,
340
- # )
341
-
342
- # confirm_player_name.click(
343
- # lambda: (gr.update(interactive=False), gr.update(visible=False)),
344
- # None,
345
- # [player_name, confirm_player_name],
346
- # queue=False,
347
- # ).then(
348
- # lambda: create_visibility_updates(True, 2),
349
- # None,
350
- # [cancel_player_name, player_name_next_step],
351
- # queue=False,
352
- # ).then(
353
- # **set_player_name_args
354
- # )
355
-
356
- # cancel_player_name.click(
357
- # lambda: (gr.update(interactive=True), gr.update(visible=True)),
358
- # None,
359
- # [player_name, confirm_player_name],
360
- # queue=False,
361
- # ).then(
362
- # lambda: create_visibility_updates(False, 2),
363
- # None,
364
- # [cancel_player_name, player_name_next_step],
365
- # queue=False,
366
- # )
367
-
368
- # player_name_next_step.click(
369
- # lambda: create_visibility_updates(False, 5),
370
- # None,
371
- # [
372
- # player_name,
373
- # player_name_next_step,
374
- # confirm_player_name,
375
- # player_name_title,
376
- # cancel_player_name,
377
- # ],
378
- # queue=False,
379
- # ).then(
380
- # lambda: create_visibility_updates(True, 11),
381
- # None,
382
- # [
383
- # openai_img,
384
- # aws_img,
385
- # google_img,
386
- # mtk_img,
387
- # story_title,
388
- # story_description,
389
- # openai_description,
390
- # aws_description,
391
- # google_description,
392
- # mtk_description,
393
- # start_generate_story,
394
- # ],
395
- # queue=False,
396
- # )
397
-
398
- # get_llm_response_args = dict(
399
- # fn=get_llm_response,
400
- # inputs=[completion_reward, player_logs],
401
- # outputs=[bot1, bot2, bot3, bot4],
402
- # queue=False,
403
- # )
404
-
405
- # start_generate_story.click(
406
- # lambda: gr.update(visible=False), None, start_generate_story, queue=False
407
- # ).then(
408
- # lambda: create_visibility_updates(True, 4),
409
- # None,
410
- # [bot1, bot2, bot3, bot4],
411
- # queue=False,
412
- # ).then(
413
- # **get_llm_response_args
414
- # ).then(
415
- # lambda: gr.update(visible=True), None, [select_story], queue=False
416
- # )
417
-
418
- # select_story.select(
419
- # lambda: gr.update(visible=True), None, confirm_story, queue=False
420
- # )
421
-
422
- # set_player_selected_character_args = dict(
423
- # fn=set_player_selected_character,
424
- # inputs=[completion_reward, select_story],
425
- # outputs=None,
426
- # queue=False,
427
- # )
428
-
429
- # confirm_story.click(
430
- # lambda: gr.update(interactive=False), None, [select_story], queue=False
431
- # ).then(lambda: gr.update(visible=False), None, [confirm_story], queue=False).then(
432
- # lambda: (gr.update(visible=True), gr.update(visible=True)),
433
- # None,
434
- # [start_generate_certificate, cancel_story],
435
- # queue=False,
436
- # ).then(
437
- # **set_player_selected_character_args
438
- # )
439
-
440
- # cancel_story.click(
441
- # lambda: gr.update(interactive=True), None, [select_story], queue=False
442
- # ).then(lambda: gr.update(visible=False), None, [cancel_story], queue=False).then(
443
- # lambda: (gr.update(visible=False), gr.update(visible=True)),
444
- # None,
445
- # [start_generate_certificate, confirm_story],
446
- # queue=False,
447
- # )
448
-
449
- # create_certificate_args = dict(
450
- # fn=create_certificate,
451
- # inputs=[completion_reward],
452
- # outputs=reward_result,
453
- # queue=False,
454
- # )
455
-
456
- # complete_reward_args = dict(
457
- # fn=complete_reward,
458
- # inputs=[completion_reward],
459
- # outputs=None,
460
- # queue=False,
461
- # )
462
-
463
- # start_generate_certificate.click(
464
- # lambda: create_visibility_updates(False, 18),
465
- # None,
466
- # [
467
- # openai_img,
468
- # aws_img,
469
- # google_img,
470
- # mtk_img,
471
- # story_title,
472
- # story_description,
473
- # openai_description,
474
- # aws_description,
475
- # google_description,
476
- # mtk_description,
477
- # bot1,
478
- # bot2,
479
- # bot3,
480
- # bot4,
481
- # select_story,
482
- # processing,
483
- # cancel_story,
484
- # start_generate_certificate,
485
- # ],
486
- # queue=False,
487
- # ).then(lambda: gr.update(visible=True), None, [processing], queue=False).then(
488
- # **create_certificate_args
489
- # ).then(
490
- # lambda: (gr.update(visible=True), gr.update(visible=False)),
491
- # None,
492
- # [complete, processing],
493
- # queue=False,
494
- # ).then(
495
- # **complete_reward_args
496
- # )
 
 
497
 
498
  if __name__ == "__main__":
499
  demo.launch()
 
67
  f"Player {player_backend_user_id} not found in processed_player_adventure_logs.json"
68
  )
69
 
70
+
71
  def init_reward():
72
  return CompletionReward()
73
 
74
+
75
  # start of gradio interface
76
  with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
77
  player_info = gr.State()
 
95
  height=200,
96
  )
97
 
98
+ badge_description = gr.Markdown(
99
+ "# 徽章", elem_id="badge_avatar_description"
100
+ )
101
  badge_gallery = gr.Gallery(
102
  [],
103
  label="徽章",
 
144
  "<div style='max-width:100%; max-height:360px; overflow:auto'>"
145
  + get_content("htmls/adventure_blank.html")
146
  )
147
+ adventure_log = gr.HTML(
148
+ html, label="Adventure Log", elem_id="adventure_log"
149
+ )
150
 
151
  # handling player info
152
  with gr.Row():
153
+ player_backend_id = gr.Textbox(
154
+ "", elem_id="player_backend_id", visible=False
155
+ )
156
  player_info_query_btn = gr.Button(
157
  "Query", elem_id="trigger_button", visible=False
158
  )
 
301
 
302
  # actions when player login
303
  # define args
304
+ send_player_login_info = dict(
305
+ fn=render_finished,
306
+ inputs=[player_activity_tracker, player_info],
307
+ outputs=None,
308
+ )
309
+
310
+ player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
311
+ get_player_logs, player_backend_id, player_logs
312
+ ).then(
313
+ render_player_data,
314
+ player_info,
315
+ [avatar, pet_gallery, badge_gallery, adventure_log, achievements, adventure],
316
+ ).then(
317
+ **send_player_login_info
318
+ )
319
+
320
+ pull_newest_player_data.submit(
321
+ save_latest_player_data,
322
+ None,
323
+ update_status,
324
+ api_name="pull_newest_player_data",
325
+ )
326
+
327
+ def create_visibility_updates(visible, count):
328
+ return tuple(gr.update(visible=visible) for _ in range(count))
329
+
330
+ start_make_reward.click(
331
+ check_is_in_completion_reward,
332
+ player_backend_id,
333
+ [
334
+ start_make_reward,
335
+ player_name_title,
336
+ player_name,
337
+ confirm_player_name,
338
+ not_participate,
339
+ not_start,
340
+ already_issued,
341
+ ],
342
+ queue=False,
343
+ )
344
+
345
+ set_player_name_args = dict(
346
+ fn=set_player_name,
347
+ inputs=[completion_reward, player_name, player_backend_id],
348
+ outputs=None,
349
+ queue=False,
350
+ )
351
+
352
+ confirm_player_name.click(
353
+ lambda: (gr.update(interactive=False), gr.update(visible=False)),
354
+ None,
355
+ [player_name, confirm_player_name],
356
+ queue=False,
357
+ ).then(
358
+ lambda: create_visibility_updates(True, 2),
359
+ None,
360
+ [cancel_player_name, player_name_next_step],
361
+ queue=False,
362
+ ).then(
363
+ **set_player_name_args
364
+ )
365
+
366
+ cancel_player_name.click(
367
+ lambda: (gr.update(interactive=True), gr.update(visible=True)),
368
+ None,
369
+ [player_name, confirm_player_name],
370
+ queue=False,
371
+ ).then(
372
+ lambda: create_visibility_updates(False, 2),
373
+ None,
374
+ [cancel_player_name, player_name_next_step],
375
+ queue=False,
376
+ )
377
+
378
+ player_name_next_step.click(
379
+ lambda: create_visibility_updates(False, 5),
380
+ None,
381
+ [
382
+ player_name,
383
+ player_name_next_step,
384
+ confirm_player_name,
385
+ player_name_title,
386
+ cancel_player_name,
387
+ ],
388
+ queue=False,
389
+ ).then(
390
+ lambda: create_visibility_updates(True, 11),
391
+ None,
392
+ [
393
+ openai_img,
394
+ aws_img,
395
+ google_img,
396
+ mtk_img,
397
+ story_title,
398
+ story_description,
399
+ openai_description,
400
+ aws_description,
401
+ google_description,
402
+ mtk_description,
403
+ start_generate_story,
404
+ ],
405
+ queue=False,
406
+ )
407
+
408
+ get_llm_response_args = dict(
409
+ fn=get_llm_response,
410
+ inputs=[completion_reward, player_logs],
411
+ outputs=[bot1, bot2, bot3, bot4],
412
+ queue=False,
413
+ )
414
+
415
+ start_generate_story.click(
416
+ lambda: gr.update(visible=False), None, start_generate_story, queue=False
417
+ ).then(
418
+ lambda: create_visibility_updates(True, 4),
419
+ None,
420
+ [bot1, bot2, bot3, bot4],
421
+ queue=False,
422
+ ).then(
423
+ **get_llm_response_args
424
+ ).then(
425
+ lambda: gr.update(visible=True), None, [select_story], queue=False
426
+ )
427
+
428
+ select_story.select(
429
+ lambda: gr.update(visible=True), None, confirm_story, queue=False
430
+ )
431
+
432
+ set_player_selected_character_args = dict(
433
+ fn=set_player_selected_character,
434
+ inputs=[completion_reward, select_story],
435
+ outputs=None,
436
+ queue=False,
437
+ )
438
+
439
+ confirm_story.click(
440
+ lambda: gr.update(interactive=False), None, [select_story], queue=False
441
+ ).then(lambda: gr.update(visible=False), None, [confirm_story], queue=False).then(
442
+ lambda: (gr.update(visible=True), gr.update(visible=True)),
443
+ None,
444
+ [start_generate_certificate, cancel_story],
445
+ queue=False,
446
+ ).then(
447
+ **set_player_selected_character_args
448
+ )
449
+
450
+ cancel_story.click(
451
+ lambda: gr.update(interactive=True), None, [select_story], queue=False
452
+ ).then(lambda: gr.update(visible=False), None, [cancel_story], queue=False).then(
453
+ lambda: (gr.update(visible=False), gr.update(visible=True)),
454
+ None,
455
+ [start_generate_certificate, confirm_story],
456
+ queue=False,
457
+ )
458
+
459
+ create_certificate_args = dict(
460
+ fn=create_certificate,
461
+ inputs=[completion_reward],
462
+ outputs=reward_result,
463
+ queue=False,
464
+ )
465
+
466
+ complete_reward_args = dict(
467
+ fn=complete_reward,
468
+ inputs=[completion_reward],
469
+ outputs=None,
470
+ queue=False,
471
+ )
472
+
473
+ start_generate_certificate.click(
474
+ lambda: create_visibility_updates(False, 18),
475
+ None,
476
+ [
477
+ openai_img,
478
+ aws_img,
479
+ google_img,
480
+ mtk_img,
481
+ story_title,
482
+ story_description,
483
+ openai_description,
484
+ aws_description,
485
+ google_description,
486
+ mtk_description,
487
+ bot1,
488
+ bot2,
489
+ bot3,
490
+ bot4,
491
+ select_story,
492
+ processing,
493
+ cancel_story,
494
+ start_generate_certificate,
495
+ ],
496
+ queue=False,
497
+ ).then(lambda: gr.update(visible=True), None, [processing], queue=False).then(
498
+ **create_certificate_args
499
+ ).then(
500
+ lambda: (gr.update(visible=True), gr.update(visible=False)),
501
+ None,
502
+ [complete, processing],
503
+ queue=False,
504
+ ).then(
505
+ **complete_reward_args
506
+ )
507
 
508
  if __name__ == "__main__":
509
  demo.launch()
utils/completion_reward.py CHANGED
@@ -35,6 +35,7 @@ gcs_client = storage.Client(
35
  credentials=creds, project=service_account_info_dict["project_id"]
36
  )
37
 
 
38
  class CompletionReward:
39
  def __init__(self):
40
  self.player_backend_user_id = None
 
35
  credentials=creds, project=service_account_info_dict["project_id"]
36
  )
37
 
38
+
39
  class CompletionReward:
40
  def __init__(self):
41
  self.player_backend_user_id = None
utils/completion_reward_utils.py CHANGED
@@ -32,7 +32,11 @@ def check_is_in_completion_reward(player_backend_user_id):
32
  completion_reward_issue_status_dict = json.load(f)
33
 
34
  if player_backend_user_id in completion_reward_issue_status_dict:
35
- preview_list = ["[email protected]", "http://googleid.junyiacademy.org/111939868185365078143", "http://googleid.junyiacademy.org/107407156051367422051"]
 
 
 
 
36
  if player_backend_user_id in preview_list:
37
  value = completion_reward_issue_status_dict[player_backend_user_id]
38
  if value == "not_issued":
 
32
  completion_reward_issue_status_dict = json.load(f)
33
 
34
  if player_backend_user_id in completion_reward_issue_status_dict:
35
+ preview_list = [
36
37
+ "http://googleid.junyiacademy.org/111939868185365078143",
38
+ "http://googleid.junyiacademy.org/107407156051367422051",
39
+ ]
40
  if player_backend_user_id in preview_list:
41
  value = completion_reward_issue_status_dict[player_backend_user_id]
42
  if value == "not_issued":