
    `Dj	                     f    d Z ddlZddlmZmZ ddlmZ  ej                  e      Z	 G d de      Z
y)u,   텍스트 Phase StepRunner — text_cleanup.    N)AnyDict)
StepRunnerc                   (    e Zd ZdZddeeef   fdZy)TextCleanupStepu6   Step 1: PDF → Gemini Flash Lite로 텍스트 추출.returnc                    ddl m} ddlm} | j                  j                  |      j                   ||j                              j                  |j                  | j                  k(        j                         }|sddlm}  |ddd      dd l}|j                  }|r6|j                   j#                  |      rdd	lm}  ||| j(                  
      }	n>|rt*        j-                  d|       nt*        j-                  d       |j                  xs d}	|j                  rt/        |j                        nd}
ddd|	|
t/        |	      ddS )Nr   )Episode)undefer)AppErrorzstep.no_episodeu(   에피소드를 찾을 수 없습니다.i  )codemessagestatus_code)extract_text_from_pdf_llm)pdf_pathproject_configu?   text_cleanup: source_path '%s' 파일 없음, fulltext fallbacku;   text_cleanup: source_path 없음, fulltext 그대로 사용    )cleaned_textoriginal_lengthcleaned_length)completed_countapplicable_countfailed_countdata)app.models.projectr
   sqlalchemy.ormr   dbqueryoptionsfulltextfilterid
episode_idfirstapp.core.errorsr   ossource_pathpathisfile!app.modules.pipeline.text_cleanerr   r   loggerwarninglen)selfmoder
   r   epr   r'   r   r   cleanedr   s              O/Users/manta/Documents/Projects/TheRoad-I1/backend/app/core/steps/text_steps.py_executezTextCleanupStep._execute   s   .*WW]]7#++GG4D4D,EFMMJJ$//)

%' 	 0 1;esvww 	>>x0S 0!#22G `bjk\]kk'RG.0kk#bkk*q  ! ! '#2"%g,		
 		
    N)resume)__name__
__module____qualname____doc__r   strr   r4    r5   r3   r   r      s    @-
c3h -
r5   r   )r:   loggingtypingr   r   app.core.step_runnerr   	getLoggerr7   r,   r   r<   r5   r3   <module>rA      s/    2   +			8	$0
j 0
r5   