import gradio as gr from news_analyzer import run_once, title_attention_index import math def convert_sim_to_text(score: float, threshold: float = 0.5) -> str: if score is None or (isinstance(score, float) and math.isnan(score)): return "판단 불가" # nan 값 처리 if score >= threshold + 0.20: # 0.7 이상 return "높음 (제목이 본문을 잘 반영합니다)" elif score >= threshold: # 예: 0.5 ~ 0.65 return "보통 (제목이 본문과 어느 정도 일치합니다)" else: # 예: 0.5 미만 return "낮음 (제목과 본문 내용에 차이가 있습니다)" def predict(title, body): r = run_once(title, body) final_score = r["최종 기사 점수"] grade = title_attention_index(final_score) summary_sim_text = convert_sim_to_text(r["요약유사도"], threshold=0.45) body_sim_text = convert_sim_to_text(r["본문 일치도(Top5 평균)"], threshold=0.5) return ( grade, summary_sim_text, body_sim_text, r["과장점수"], final_score, ) demo = gr.Interface( fn=predict, inputs=[ gr.Textbox(label="제목", lines=2), gr.Textbox(label="본문", lines=18, placeholder="여기에 기사 본문을 붙여넣으세요"), ], outputs=[ gr.Textbox(label="제목 주의 지수", interactive=False), # <-- [0] gr.Textbox( label="요약 유사도", info="기사 제목과 기사의 요약된 내용이 일치할까?" ), # <-- [1] gr.Textbox( label="본문 일치도(Top5 평균)", info="기사 내용을 잘 함축한 제목일까?" ), # <-- [2] gr.Number( label="과장점수", info="기사의 제목이 얼마나 과장되어 있을까?" ), # <-- [3] gr.Number( label="최종 기사 점수", info="기사의 제목을 점수 매겨본다면?" ), # <-- [4] ], title="제목 주의 지수", description=( "원하는 기사의 제목과 본문을 아래에 입력하면 제목-본문 유사도, 과장 점수를 바탕으로 '제목 주의 지수'를 계산합니다.\n\n" "ℹ️ **자세한 설명이 궁금하다면 " "[여기를 클릭하세요](https://www.notion.so/25cb058cee088026badfcab340e9966d?source=copy_link)**" ), ) if __name__ == "__main__": demo.launch()