Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 7 : Insert the description into the render #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/pokemon_content/pokemon_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ def generate_desc(card: Card) -> str:
response = gpt_client().get_completion(prompt, max_tokens=256)
desc = response.choices[0].text
desc = desc.strip()

# Summarize the description.
if gpt_client().is_openai_enabled:
prompt = f"Summarize in less than 200 caraters the following description : {desc}. "
print(prompt)
response = gpt_client().get_completion(prompt, max_tokens=256)
desc = response.choices[0].text
desc = desc.strip()

return desc
else:
return "No description available."
24 changes: 13 additions & 11 deletions src/render_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import pathlib
import textwrap
from PIL import Image, ImageFont, ImageDraw

from pokemon_content.pokemon_elements import PokemonElements, get_resist, get_weakness
Expand Down Expand Up @@ -143,17 +144,18 @@ def render_card(card: Card, collection_path: str):
# Render the status of the card (weakness, resistance, etc.)
render_weakness_and_resist(card, card_image)

# Write the rarity of the Pokemon.
rarity_text_position = (58, 602)
rarity_font = ImageFont.truetype("resources/font/Cabin_Condensed-Regular.ttf", 18)
rarity_text = f"{card.rarity.name} {card.element.name}-type Card"
draw.text(
rarity_text_position,
rarity_text.title(),
font=rarity_font,
fill=(0, 0, 0),
anchor="lm",
)
# Write the description of the Pokemon.
description_text_position_x = 50
description_text_position_y = 594
description_font = ImageFont.truetype("resources/font/Cabin_Condensed-Regular.ttf", 8)
description_text = card.description

lines = textwrap.wrap(description_text, width=110)

for line in lines:
unused, unused2, width, height = description_font.getbbox(line)
draw.text((description_text_position_x, description_text_position_y), line, font=description_font, fill=(0, 0, 0),anchor="lm")
description_text_position_y += height

# Write the rarity of the Pokemon.
rarity_symbol_position = (card_image.width - 64, 605)
Expand Down