Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,9 @@ from reportlab.lib.units import cm
|
|
11 |
|
12 |
with open('pokemon.json', 'r') as f:
|
13 |
pokemons = json.load(f)
|
14 |
-
|
15 |
GEN_RANGE = {
|
|
|
16 |
"1์ธ๋": [1, 151],
|
17 |
"2์ธ๋": [152, 251],
|
18 |
"3์ธ๋": [252, 386],
|
@@ -25,14 +26,17 @@ GEN_RANGE = {
|
|
25 |
}
|
26 |
|
27 |
generation = gr.Dropdown(
|
28 |
-
[f"{k}์ธ๋" for k in range(1, 10)], value="1์ธ๋", label="ํฌ์ผ๋ชฌ ์ธ๋", info="์ํ๋ ํฌ์ผ๋ชฌ ์ธ๋๋ฅผ ์ ํํ์ธ์."
|
|
|
|
|
|
|
29 |
)
|
30 |
|
31 |
download = gr.File(label="ํ๋ ๊ธ์จ๋ฅผ ๋๋ฌ์ ๋ค์ด๋ก๋ ๋ฐ์ผ์ธ์.")
|
32 |
text = gr.DataFrame(label="ํฌ์ผ๋ชฌ ๋ฆฌ์คํธ")
|
33 |
|
34 |
-
def write_pdf(gen, progress=gr.Progress()):
|
35 |
-
filename = f'ํฌ์ผ๋ชฌ{gen}.pdf'
|
36 |
pdfmetrics.registerFont(TTFont("๋๋๊ณ ๋", "NanumGothic.ttf"))
|
37 |
# PDF ๋ฌธ์๋ฅผ ์์ฑํฉ๋๋ค.
|
38 |
pdfmetrics.registerFont(TTFont("๋๋๊ณ ๋", "NanumGothic.ttf"))
|
@@ -60,30 +64,35 @@ def write_pdf(gen, progress=gr.Progress()):
|
|
60 |
types = pokemons[k-1]['types']
|
61 |
image_path = pokemons[k-1]['image_path']
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
|
82 |
doc.build(story)
|
83 |
df = pd.DataFrame(data_dict)
|
84 |
return df[['No', '์ด๋ฆ', 'ํ์
']], filename
|
85 |
|
86 |
-
demo = gr.Interface(write_pdf, generation, [text, download], title="๋์น๋ ํฌ์ผ๋ชฌ ๋๊ฐ ์์ฑ๊ธฐ",
|
87 |
description="์ํ๋ ํฌ์ผ๋ชฌ ์ธ๋๋ฅผ ์ ํํ๊ณ , ๋ค์ด๋ก๋๋ฅผ ๋๋ฌ์ฃผ์ธ์.")
|
88 |
demo.queue(concurrency_count=3)
|
89 |
demo.launch()
|
|
|
11 |
|
12 |
with open('pokemon.json', 'r') as f:
|
13 |
pokemons = json.load(f)
|
14 |
+
pokemons_types = ["๋ชจ๋ ํ์
"] + sorted(set([t for poke in pokemons for t in poke['types']]))
|
15 |
GEN_RANGE = {
|
16 |
+
"๋ชจ๋ ์ธ๋": [1, 1017],
|
17 |
"1์ธ๋": [1, 151],
|
18 |
"2์ธ๋": [152, 251],
|
19 |
"3์ธ๋": [252, 386],
|
|
|
26 |
}
|
27 |
|
28 |
generation = gr.Dropdown(
|
29 |
+
[f"{k}์ธ๋" for k in range(1, 10)] + ["๋ชจ๋ ์ธ๋"], value="1์ธ๋", label="ํฌ์ผ๋ชฌ ์ธ๋", info="์ํ๋ ํฌ์ผ๋ชฌ ์ธ๋๋ฅผ ์ ํํ์ธ์."
|
30 |
+
)
|
31 |
+
poke_types = gr.Dropdown(
|
32 |
+
pokemons_types, value="๋ชจ๋ ํ์
", label="ํฌ์ผ๋ชฌ ํ์
", info="์ํ๋ ํฌ์ผ๋ชฌ ํ์
์ ์ ํํ์ธ์."
|
33 |
)
|
34 |
|
35 |
download = gr.File(label="ํ๋ ๊ธ์จ๋ฅผ ๋๋ฌ์ ๋ค์ด๋ก๋ ๋ฐ์ผ์ธ์.")
|
36 |
text = gr.DataFrame(label="ํฌ์ผ๋ชฌ ๋ฆฌ์คํธ")
|
37 |
|
38 |
+
def write_pdf(gen, poke_type, progress=gr.Progress()):
|
39 |
+
filename = f'ํฌ์ผ๋ชฌ{gen}_{poke_type}.pdf'
|
40 |
pdfmetrics.registerFont(TTFont("๋๋๊ณ ๋", "NanumGothic.ttf"))
|
41 |
# PDF ๋ฌธ์๋ฅผ ์์ฑํฉ๋๋ค.
|
42 |
pdfmetrics.registerFont(TTFont("๋๋๊ณ ๋", "NanumGothic.ttf"))
|
|
|
64 |
types = pokemons[k-1]['types']
|
65 |
image_path = pokemons[k-1]['image_path']
|
66 |
|
67 |
+
if poke_type == "๋ชจ๋ ํ์
":
|
68 |
+
condition = True
|
69 |
+
else:
|
70 |
+
condition = poke_type in types
|
71 |
+
if condition:
|
72 |
+
data_dict.append(
|
73 |
+
dict(์ด๋ฆ=name, No=number, ํ์
='+'.join(types))
|
74 |
+
)
|
75 |
|
76 |
+
# PDF์ ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํฉ๋๋ค. ์ด๋ฏธ์ง ํ์ผ์ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ์ธ์.
|
77 |
+
image = Image(image_path, width=13.5*cm, height=13.5*cm)
|
78 |
|
79 |
+
# ํ
์ด๋ธ ๋ฐ์ดํฐ๋ฅผ ์ค๋นํฉ๋๋ค.
|
80 |
+
data = [
|
81 |
+
[number],
|
82 |
+
[image], # 2๋ฒ์งธ ํ์ ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํ ๊ฒ์
๋๋ค.
|
83 |
+
['+'.join(types)],
|
84 |
+
[name],
|
85 |
+
]
|
86 |
+
# ํ
์ด๋ธ ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค.
|
87 |
+
table = Table(data)
|
88 |
+
table.setStyle(style)
|
89 |
+
story.append(table)
|
90 |
|
91 |
doc.build(story)
|
92 |
df = pd.DataFrame(data_dict)
|
93 |
return df[['No', '์ด๋ฆ', 'ํ์
']], filename
|
94 |
|
95 |
+
demo = gr.Interface(write_pdf, [generation, poke_types], [text, download], title="๋์น๋ ํฌ์ผ๋ชฌ ๋๊ฐ ์์ฑ๊ธฐ",
|
96 |
description="์ํ๋ ํฌ์ผ๋ชฌ ์ธ๋๋ฅผ ์ ํํ๊ณ , ๋ค์ด๋ก๋๋ฅผ ๋๋ฌ์ฃผ์ธ์.")
|
97 |
demo.queue(concurrency_count=3)
|
98 |
demo.launch()
|