Spaces:
Runtime error
Runtime error
looks nicer
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ df = pd.read_csv(
|
|
9 |
# All numbers to .2f
|
10 |
df = df.round(2)
|
11 |
# Rename columns
|
12 |
-
print(df.columns)
|
13 |
df.columns = [
|
14 |
"game_name",
|
15 |
"speakers",
|
@@ -25,64 +24,60 @@ df.columns = [
|
|
25 |
]
|
26 |
|
27 |
|
28 |
-
def
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
# Add clickable link that leads to the image URL
|
32 |
-
return f"[]({url})"
|
33 |
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
# 新しい列を追加
|
36 |
-
for i in range(1, 6):
|
37 |
-
df[f"spec{i}"] = df["game_name"].apply(lambda x: create_image_md(x, i))
|
38 |
|
39 |
# 必要な列だけを選択
|
40 |
df_display = df[
|
41 |
-
[
|
42 |
-
"game_name",
|
43 |
-
"speakers",
|
44 |
-
"mono",
|
45 |
-
"stereo",
|
46 |
-
"duration",
|
47 |
-
"bitrate",
|
48 |
-
"sr",
|
49 |
-
"spec1",
|
50 |
-
"spec2",
|
51 |
-
"spec3",
|
52 |
-
"spec4",
|
53 |
-
"spec5",
|
54 |
-
]
|
55 |
]
|
|
|
56 |
md = """
|
57 |
# Galgame_Dataset Stats Viewer
|
58 |
|
59 |
-
- Viewer for
|
60 |
-
- `bitrate`: in kbps
|
61 |
-
- `sr`: in kHz
|
62 |
-
- `duration`: in hours
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
"""
|
64 |
|
65 |
-
with gr.Blocks() as app:
|
66 |
gr.Markdown(md)
|
67 |
-
gr.
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
"
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
"markdown",
|
83 |
-
],
|
84 |
-
column_widths=[100, 100, 100, 100, 100, 100, 100, 300, 300, 300, 300, 300],
|
85 |
-
wrap=True,
|
86 |
-
)
|
87 |
|
88 |
app.launch(inbrowser=True)
|
|
|
9 |
# All numbers to .2f
|
10 |
df = df.round(2)
|
11 |
# Rename columns
|
|
|
12 |
df.columns = [
|
13 |
"game_name",
|
14 |
"speakers",
|
|
|
24 |
]
|
25 |
|
26 |
|
27 |
+
def gallery_images(game_name):
|
28 |
+
"""与えられたゲーム名に基づいて画像のリストを生成する"""
|
29 |
+
images = [
|
30 |
+
f"https://huggingface.co/datasets/litagin/Galgame_Dataset_stats/resolve/main/specs/{game_name}/spec{i}.png"
|
31 |
+
for i in range(1, 6)
|
32 |
+
]
|
33 |
+
return images
|
34 |
|
|
|
|
|
35 |
|
36 |
+
def update_gallery(event: gr.SelectData):
|
37 |
+
"""行がクリックされた時にGalleryを更新する"""
|
38 |
+
game_name = event.row_value[0]
|
39 |
+
return f"## `{game_name}`", gallery_images(game_name)
|
40 |
|
|
|
|
|
|
|
41 |
|
42 |
# 必要な列だけを選択
|
43 |
df_display = df[
|
44 |
+
["game_name", "speakers", "mono", "stereo", "duration", "bitrate", "sr"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
]
|
46 |
+
|
47 |
md = """
|
48 |
# Galgame_Dataset Stats Viewer
|
49 |
|
50 |
+
- Viewer for stats of each game in [OOPPEENN/Galgame_Dataset](https://huggingface.co/datasets/OOPPEENN/Galgame_Dataset)
|
51 |
+
- `bitrate`: bitrate in kbps
|
52 |
+
- `sr`: sample rate in kHz
|
53 |
+
- `duration`: total duration in hours
|
54 |
+
"""
|
55 |
+
|
56 |
+
HEIGHT = 500
|
57 |
+
|
58 |
+
CSS = f"""
|
59 |
+
.qa-pairs .table-wrap {{
|
60 |
+
min-height: {HEIGHT}px;
|
61 |
+
max-height: {HEIGHT}px;
|
62 |
+
}}
|
63 |
"""
|
64 |
|
65 |
+
with gr.Blocks(css=CSS) as app:
|
66 |
gr.Markdown(md)
|
67 |
+
with gr.Row():
|
68 |
+
with gr.Column():
|
69 |
+
table = gr.DataFrame(
|
70 |
+
df_display,
|
71 |
+
column_widths=[200, 100, 100, 100, 100, 100, 100],
|
72 |
+
wrap=True,
|
73 |
+
elem_classes="qa-pairs",
|
74 |
+
)
|
75 |
+
with gr.Column():
|
76 |
+
game_name = gr.Markdown("## Click on a row to see the gallery")
|
77 |
+
gallery = gr.Gallery(preview=True)
|
78 |
+
table.select(
|
79 |
+
fn=update_gallery,
|
80 |
+
outputs=[game_name, gallery],
|
81 |
+
)
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
app.launch(inbrowser=True)
|