Spaces:
Sleeping
Sleeping
Commit 路
20cc6ef
1
Parent(s): 96a04e2
bugfix: fix minor bugs
Browse files- app.py +214 -204
- utils/completion_reward.py +1 -0
- utils/completion_reward_utils.py +5 -1
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(
|
|
|
|
|
|
|
| 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(
|
|
|
|
|
|
|
| 144 |
|
| 145 |
# handling player info
|
| 146 |
with gr.Row():
|
| 147 |
-
player_backend_id = gr.Textbox(
|
|
|
|
|
|
|
| 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 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 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 = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"chen.kao@junyiacademy.org",
|
| 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":
|