스타일링 1차 기능 추가
This commit is contained in:
1 parent
3555fa05a2
commit
2140f7d5c8
12 files changed
+531
No files matched your search
@@ -0,0 +1,37 @@
|
||||
"""스타일링 ① — 포스터에 인쇄된 글자를 읽는다
|
||||
|
||||
이미지 생성 모델은 한글을 다시 그리며 자모를 바꾼다(맥주축제 → 백주축제).
|
||||
프롬프트로는 못 막으므로 읽기를 먼저 하고 그 문자열을 생성 프롬프트에 못 박는다.
|
||||
"""
|
||||
from PIL import Image
|
||||
|
||||
from answers.poster_text_answer import PosterTextAnswer
|
||||
from settings import settings
|
||||
from utils.common_llm import StructuredLLM
|
||||
from utils.image import to_data_uri
|
||||
from utils.prompt import load_prompt
|
||||
|
||||
# 자모가 보일 만큼은 키워서 넣는다
|
||||
MIN_LONG_EDGE = 1400
|
||||
MAX_SIZE = (1536, 1536)
|
||||
|
||||
POSTER_TEXT_PROMPT = load_prompt("poster_text")
|
||||
|
||||
poster_text_llm = StructuredLLM("gpt-4o", settings.chatgpt_api_key)
|
||||
|
||||
|
||||
def readable_copy(poster: Image.Image) -> Image.Image:
|
||||
source = poster.convert("RGB")
|
||||
if max(source.size) < MIN_LONG_EDGE:
|
||||
scale = MIN_LONG_EDGE / max(source.size)
|
||||
source = source.resize((round(source.width * scale), round(source.height * scale)),
|
||||
Image.LANCZOS)
|
||||
source.thumbnail(MAX_SIZE, Image.LANCZOS)
|
||||
return source
|
||||
|
||||
|
||||
async def read_poster_text(poster: Image.Image) -> PosterTextAnswer:
|
||||
image = readable_copy(poster)
|
||||
return await poster_text_llm.ask_with_images(
|
||||
PosterTextAnswer, POSTER_TEXT_PROMPT, [("포스터", to_data_uri(image))],
|
||||
temperature=0.1)
|
||||
Reference in new issue
Block a user