언어선택에 따른 자막생성 구현
This commit is contained in:
1 parent
bdee852bed
commit
997927d42a
10 files changed
+149
-45
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import os
|
||||
import gspread
|
||||
from pathlib import Path
|
||||
from pydantic import BaseModel
|
||||
from google.oauth2.service_account import Credentials
|
||||
from config import prompt_settings
|
||||
@@ -34,15 +36,24 @@ class Prompt():
|
||||
prompt_input_class = BaseModel
|
||||
prompt_output_class = BaseModel
|
||||
|
||||
def __init__(self, sheet_name, prompt_input_class, prompt_output_class):
|
||||
def __init__(self, sheet_name, prompt_input_class, prompt_output_class, template_file: str = None, prompt_model: str = None):
|
||||
self.sheet_name = sheet_name
|
||||
self.prompt_input_class = prompt_input_class
|
||||
self.prompt_output_class = prompt_output_class
|
||||
self.prompt_template, self.prompt_model = _read_sheet_data(sheet_name)
|
||||
if template_file:
|
||||
self.prompt_template = Path(template_file).read_text(encoding="utf-8")
|
||||
self.prompt_model = prompt_model
|
||||
self._template_file = template_file
|
||||
else:
|
||||
self.prompt_template, self.prompt_model = _read_sheet_data(sheet_name)
|
||||
self._template_file = None
|
||||
|
||||
def _reload_prompt(self):
|
||||
_sheet_cache.pop(self.sheet_name, None)
|
||||
self.prompt_template, self.prompt_model = _read_sheet_data(self.sheet_name)
|
||||
if self._template_file:
|
||||
self.prompt_template = Path(self._template_file).read_text(encoding="utf-8")
|
||||
else:
|
||||
_sheet_cache.pop(self.sheet_name, None)
|
||||
self.prompt_template, self.prompt_model = _read_sheet_data(self.sheet_name)
|
||||
|
||||
def build_prompt(self, input_data:dict, silent:bool = False) -> str:
|
||||
verified_input = self.prompt_input_class(**input_data)
|
||||
@@ -77,12 +88,17 @@ image_autotag_prompt = Prompt(
|
||||
prompt_output_class=ImageTagPromptOutput,
|
||||
)
|
||||
|
||||
_SUBTITLE_TEMPLATE_PATH = str(Path(__file__).parent / "templates" / "subtitle_prompt.txt")
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def create_dynamic_subtitle_prompt(length: int) -> Prompt:
|
||||
return Prompt(
|
||||
sheet_name="subtitle",
|
||||
prompt_input_class=SubtitlePromptInput,
|
||||
prompt_output_class=SubtitlePromptOutput[length],
|
||||
template_file=_SUBTITLE_TEMPLATE_PATH,
|
||||
prompt_model=os.getenv("SUBTITLE_PROMPT_MODEL", "gpt-4o-mini"),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ class LyricPromptInput(BaseModel):
|
||||
detail_region_info : str = Field(..., description = "마케팅 대상 지역 상세")
|
||||
marketing_intelligence_summary : Optional[str] = Field(None, description = "마케팅 분석 정보 보고서")
|
||||
language : str= Field(..., description = "가사 언어")
|
||||
promotional_expression_example : str = Field(..., description = "판촉 가사 표현 예시")
|
||||
timing_rules : str = Field(..., description = "시간 제어문")
|
||||
|
||||
# Output 정의
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
from pydantic import BaseModel, create_model, Field
|
||||
from typing import List, Optional
|
||||
from typing import List
|
||||
from functools import lru_cache
|
||||
|
||||
# Input 정의
|
||||
|
||||
class SubtitlePromptInput(BaseModel):
|
||||
marketing_intelligence : str = Field(..., description="마케팅 인텔리전스 정보")
|
||||
marketing_intelligence : str = Field(..., description="마케팅 인텔리전스 정보")
|
||||
pitching_tag_list_string : str = Field(..., description="필요한 피칭 레이블 리스트 stringify")
|
||||
customer_name : str = Field(..., description = "마케팅 대상 사업체 이름")
|
||||
detail_region_info : str = Field(..., description = "마케팅 대상 지역 상세")
|
||||
|
||||
#subtillecars :
|
||||
language : str = Field(default="Korean", description="자막 출력 언어 (Korean, English, Chinese, Japanese, Thai, Vietnamese)")
|
||||
|
||||
# Output 정의
|
||||
class PitchingOutput(BaseModel):
|
||||
pitching_tag: str = Field(..., description="피칭 레이블")
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
|
||||
You are a subtitle copywriter for hospitality short-form videos. You generate subtitle text AND layer names from marketing JSON data.
|
||||
|
||||
**GENERATION LANGUAGE**: Korean (한국어)
|
||||
**OUTPUT LANGUAGE**: {language}
|
||||
|
||||
**WORKFLOW**:
|
||||
1. Generate all subtitles and keywords in Korean following the rules below.
|
||||
2. If {language} is NOT Korean, translate every subtitle text and keyword to {language} while preserving meaning, tone, and approximate character count spirit. Fixed anchor texts (availability, cta_action) must also be translated naturally.
|
||||
|
||||
---
|
||||
|
||||
### RULES
|
||||
@@ -231,3 +238,6 @@ Keyword pattern analysis:
|
||||
**입력 3: 비즈니스 정보 **
|
||||
Business Name: {customer_name}
|
||||
Region Details: {detail_region_info}
|
||||
|
||||
**입력 4: 출력 언어**
|
||||
Language: {language}
|
||||
Reference in new issue
Block a user