ChenyuRabbitLove commited on
Commit
d79f5f2
1 Parent(s): 4427f36

feat: add get players badges and partners function when user login

Browse files
Files changed (3) hide show
  1. app.py +14 -1
  2. css/style.css +1 -1
  3. utils/utils.py +18 -0
app.py CHANGED
@@ -3,7 +3,7 @@ import json
3
  import gradio as gr
4
 
5
  from theme import Seafoam
6
- from utils.utils import get_content
7
 
8
  seafoam = Seafoam()
9
 
@@ -16,6 +16,8 @@ def get_player_info(player_backend_user_id):
16
 
17
  # start of gradio interface
18
  with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
 
 
19
  with gr.Row():
20
  with gr.Column(
21
  scale=1,
@@ -88,5 +90,16 @@ with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
88
  )
89
  f = gr.HTML(html, label="Achievement Log", elem_id="achievement_log")
90
 
 
 
 
 
 
 
 
 
 
 
 
91
  if __name__ == "__main__":
92
  demo.launch()
 
3
  import gradio as gr
4
 
5
  from theme import Seafoam
6
+ from utils.utils import get_content, get_player_partners, get_player_badges
7
 
8
  seafoam = Seafoam()
9
 
 
16
 
17
  # start of gradio interface
18
  with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
19
+ player_info = gr.State()
20
+
21
  with gr.Row():
22
  with gr.Column(
23
  scale=1,
 
90
  )
91
  f = gr.HTML(html, label="Achievement Log", elem_id="achievement_log")
92
 
93
+ # handling player info
94
+ with gr.Row():
95
+ player_backend_id = gr.Textbox(
96
+ "http://id.junyiacademy.org/d6317d299321450191dd5da599a48b3d", visible=False
97
+ )
98
+ player_info_query_btn = gr.Button("Query")
99
+
100
+ player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
101
+ get_player_partners, player_info, pet_gallery
102
+ ).then(get_player_badges, player_info, badge_gallery)
103
+
104
  if __name__ == "__main__":
105
  demo.launch()
css/style.css CHANGED
@@ -1,4 +1,4 @@
1
- .gradio-container {background: url('file=media/bg_clear.png')}
2
 
3
  #user_avatar {
4
  background-color: transparent !important;
 
1
+ .gradio-container {background: url('file=medias/bg_clear.png')}
2
 
3
  #user_avatar {
4
  background-color: transparent !important;
utils/utils.py CHANGED
@@ -1,4 +1,22 @@
 
 
 
 
 
 
 
 
1
  def get_content(file_name: str) -> str:
2
  with open(file_name, "r", encoding="utf-8") as file:
3
  content = file.read()
4
  return content
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+
3
+ import gradio as gr
4
+
5
+ MEDIA_PATH = "medias/"
6
+ MEDIA_FILE_TYPE = ".png"
7
+
8
+
9
  def get_content(file_name: str) -> str:
10
  with open(file_name, "r", encoding="utf-8") as file:
11
  content = file.read()
12
  return content
13
+
14
+
15
+ def get_player_partners(player_info: gr.State) -> List[str]:
16
+ return [
17
+ f"{MEDIA_PATH}{partner}{MEDIA_FILE_TYPE}" for partner in player_info["partners"]
18
+ ]
19
+
20
+
21
+ def get_player_badges(player_info: gr.State) -> List[str]:
22
+ return [f"{MEDIA_PATH}{badge}{MEDIA_FILE_TYPE}" for badge in player_info["badges"]]