Spaces:
Runtime error
Runtime error
Filter extra 'Actions' text from result HTML, try two column layout, add labels to app components, rename from Test Space to MonsterGen
Browse files- README.md +1 -1
- app.py +23 -7
- monsterMakerTemplate.html +1 -1
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: π
|
4 |
colorFrom: gray
|
5 |
colorTo: red
|
1 |
---
|
2 |
+
title: MonsterGen
|
3 |
emoji: π
|
4 |
colorFrom: gray
|
5 |
colorTo: red
|
app.py
CHANGED
@@ -208,6 +208,8 @@ def format_monster_card(monster_text, image_data):
|
|
208 |
x = x.split(':')
|
209 |
if len(x) > 1:
|
210 |
trait = x[0]
|
|
|
|
|
211 |
if 'Action' in trait:
|
212 |
break
|
213 |
detail = ":".join(x[1:])
|
@@ -230,6 +232,8 @@ def format_monster_card(monster_text, image_data):
|
|
230 |
x = x.split(':')
|
231 |
if len(x) > 1:
|
232 |
action = x[0]
|
|
|
|
|
233 |
if 'Passive' in action:
|
234 |
break
|
235 |
detail = ":".join(x[1:])
|
@@ -238,7 +242,7 @@ def format_monster_card(monster_text, image_data):
|
|
238 |
else:
|
239 |
card = card.replace('{actions}', f'<div class="monster-action"><p>{actions}</p></div>')
|
240 |
|
241 |
-
# TODO: Legendary actions, reactions
|
242 |
|
243 |
card = card.replace('Melee Weapon Attack:', '<i>Melee Weapon Attack:</i>')
|
244 |
card = card.replace('Ranged Weapon Attack:', '<i>Ranged Weapon Attack:</i>')
|
@@ -278,7 +282,7 @@ def crop_background(image):
|
|
278 |
|
279 |
def html_to_png(html):
|
280 |
print('CONVERTING HTML CARD TO PNG IMAGE')
|
281 |
-
paths = hti.screenshot(html_str=html, css_file="monstermaker.css", save_as="test.png", size=(
|
282 |
path = paths[0]
|
283 |
print('OPENING IMAGE FROM FILE')
|
284 |
img = Image.open(path).convert("RGB")
|
@@ -298,9 +302,21 @@ def run(name):
|
|
298 |
card_html = format_monster_card(text, image_data)
|
299 |
card_image = html_to_png(card_html)
|
300 |
end = time.time()
|
301 |
-
print(f'RUN COMPLETED IN {end - start} seconds')
|
302 |
-
return text, pil,
|
303 |
-
|
304 |
-
|
305 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
iface.launch()
|
208 |
x = x.split(':')
|
209 |
if len(x) > 1:
|
210 |
trait = x[0]
|
211 |
+
if trait == "Passives":
|
212 |
+
continue
|
213 |
if 'Action' in trait:
|
214 |
break
|
215 |
detail = ":".join(x[1:])
|
232 |
x = x.split(':')
|
233 |
if len(x) > 1:
|
234 |
action = x[0]
|
235 |
+
if action == "Actions":
|
236 |
+
continue
|
237 |
if 'Passive' in action:
|
238 |
break
|
239 |
detail = ":".join(x[1:])
|
242 |
else:
|
243 |
card = card.replace('{actions}', f'<div class="monster-action"><p>{actions}</p></div>')
|
244 |
|
245 |
+
# TODO: Legendary actions, reactions, make column count for format an option (1 or 2 column layout), add examples
|
246 |
|
247 |
card = card.replace('Melee Weapon Attack:', '<i>Melee Weapon Attack:</i>')
|
248 |
card = card.replace('Ranged Weapon Attack:', '<i>Ranged Weapon Attack:</i>')
|
282 |
|
283 |
def html_to_png(html):
|
284 |
print('CONVERTING HTML CARD TO PNG IMAGE')
|
285 |
+
paths = hti.screenshot(html_str=html, css_file="monstermaker.css", save_as="test.png", size=(800, 1440))
|
286 |
path = paths[0]
|
287 |
print('OPENING IMAGE FROM FILE')
|
288 |
img = Image.open(path).convert("RGB")
|
302 |
card_html = format_monster_card(text, image_data)
|
303 |
card_image = html_to_png(card_html)
|
304 |
end = time.time()
|
305 |
+
print(f'RUN COMPLETED IN {int(end - start)} seconds')
|
306 |
+
return card_image, text, pil, card_html
|
307 |
+
|
308 |
+
|
309 |
+
app_description = (
|
310 |
+
"""
|
311 |
+
# Create your own D&D monster!
|
312 |
+
Enter a name, click Submit, and wait for about 4 minutes to see the result.
|
313 |
+
""")
|
314 |
+
input_box = gr.Textbox(label="Enter a monster name", placeholder="Jabberwock")
|
315 |
+
output_monster_card = gr.Pil(label="Monster Card")
|
316 |
+
output_text_box = gr.Textbox(label="Monster Text")
|
317 |
+
output_monster_image = gr.Pil(label="Monster Image")
|
318 |
+
output_monster_html = gr.HTML(label="Monster HTML")
|
319 |
+
iface = gr.Interface(title="MonsterGen", theme="default", description=app_description, fn=run, inputs=[input_box],
|
320 |
+
outputs=[output_monster_card, output_text_box, output_monster_image, output_monster_html],
|
321 |
+
css="monstermaker.css")
|
322 |
iface.launch()
|
monsterMakerTemplate.html
CHANGED
@@ -18,7 +18,7 @@
|
|
18 |
</head>
|
19 |
|
20 |
<body>
|
21 |
-
<div class="monster theme-5e columns-
|
22 |
<div class="monster-contents">
|
23 |
<div class="monster-contents-header"></div>
|
24 |
<div class="monster-contents-body">
|
18 |
</head>
|
19 |
|
20 |
<body>
|
21 |
+
<div class="monster theme-5e columns-2">
|
22 |
<div class="monster-contents">
|
23 |
<div class="monster-contents-header"></div>
|
24 |
<div class="monster-contents-body">
|