Update model to v16, fix name bug, add alternate render option for local.
Browse files- app.py +12 -4
- gpt2-magic-card/pytorch_model.bin +1 -1
app.py
CHANGED
|
@@ -45,7 +45,7 @@ def gen_card_text(name):
|
|
| 45 |
if name == '':
|
| 46 |
prompt = f"Name: {random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ')}"
|
| 47 |
else:
|
| 48 |
-
prompt = f"Name: {name}\
|
| 49 |
print(f'GENERATING CARD TEXT with prompt: {prompt}')
|
| 50 |
output = text_pipeline(prompt, max_length=512, num_return_sequences=1, num_beams=5, temperature=1.5, do_sample=True,
|
| 51 |
repetition_penalty=1.2, eos_token_id=eos_id)
|
|
@@ -211,10 +211,18 @@ def html_to_png(card_name, html):
|
|
| 211 |
|
| 212 |
path = os.path.join('rendered_cards', save_name)
|
| 213 |
try:
|
| 214 |
-
|
| 215 |
-
|
| 216 |
except:
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
print('OPENING IMAGE FROM FILE')
|
| 219 |
img = Image.open(path)
|
| 220 |
print('CROPPING BACKGROUND')
|
|
|
|
| 45 |
if name == '':
|
| 46 |
prompt = f"Name: {random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ')}"
|
| 47 |
else:
|
| 48 |
+
prompt = f"Name: {name}\n"
|
| 49 |
print(f'GENERATING CARD TEXT with prompt: {prompt}')
|
| 50 |
output = text_pipeline(prompt, max_length=512, num_return_sequences=1, num_beams=5, temperature=1.5, do_sample=True,
|
| 51 |
repetition_penalty=1.2, eos_token_id=eos_id)
|
|
|
|
| 211 |
|
| 212 |
path = os.path.join('rendered_cards', save_name)
|
| 213 |
try:
|
| 214 |
+
css = ['./colab-data-test/css/mana.css', './colab-data-test/css/keyrune.css', './colab-data-test/css/mtg_custom.css']
|
| 215 |
+
imgkit.from_string(html, path, {"xvfb": ""}, css=css)
|
| 216 |
except:
|
| 217 |
+
# For Windows local, requires 'html2image' package from pip.
|
| 218 |
+
from html2image import Html2Image
|
| 219 |
+
rendered_card_dir = 'rendered_cards'
|
| 220 |
+
hti = Html2Image(output_path=rendered_card_dir)
|
| 221 |
+
paths = hti.screenshot(html_str=html,
|
| 222 |
+
css_file=['./colab-data-test/css/mtg_custom.css', './colab-data-test/css/mana.css', './colab-data-test/css/keyrune.css'],
|
| 223 |
+
save_as=save_name, size=(450, 600))
|
| 224 |
+
print(paths)
|
| 225 |
+
path = paths[0]
|
| 226 |
print('OPENING IMAGE FROM FILE')
|
| 227 |
img = Image.open(path)
|
| 228 |
print('CROPPING BACKGROUND')
|
gpt2-magic-card/pytorch_model.bin
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 248927581
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dee3589ff13b3b51415f3eec89cb6119f36688ae26a65c1f07d695297a919656
|
| 3 |
size 248927581
|