Spaces:
Running
Running
File size: 1,413 Bytes
d79f5f2 de7f21d bb68beb d79f5f2 5fafe16 d79f5f2 5784cf3 77f112d 5784cf3 77f112d 5784cf3 77f112d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
from typing import List
import gradio as gr
MEDIA_PATH = "medias/"
MEDIA_FILE_TYPE = ".png"
def get_content(file_name: str) -> str:
with open(file_name, "r", encoding="utf-8") as file:
content = file.read()
return "<div style='max-width:100%; max-height:360px; overflow:auto'>" + content
def get_player_partners(player_info: gr.State) -> List[str]:
return [
f"{MEDIA_PATH}{partner}{MEDIA_FILE_TYPE}" for partner in player_info["partners"]
]
def get_player_nickname(player_info: gr.State) -> str:
player_nickname = player_info["player_nickname"]
if player_nickname:
return f'# 光束守護者 - {player_info["player_nickname"]}'
else:
return "# 光束守護者"
def get_player_badges(player_info: gr.State) -> List[str]:
return [f"{MEDIA_PATH}{badge}{MEDIA_FILE_TYPE}" for badge in player_info["badges"]]
def get_player_adventure_logs(player_info: gr.State) -> List[str]:
log_template = """<div class="adventure"><p>{player_log}</p></div>"""
return [
log_template.format(player_log=player_log)
for player_log in player_info["adventure_logs"]
]
def get_player_adventure_logs_html(player_info: gr.State) -> str:
adventure_logs = "".join(get_player_adventure_logs(player_info))
template_content = get_content("htmls/adventure_template.html")
return template_content.replace("{logs}", adventure_logs)
|