File size: 2,578 Bytes
09e0b44
 
9e91550
cd47b16
 
9e91550
cd47b16
83680c0
 
 
cd47b16
83680c0
cd47b16
 
 
 
83680c0
09e0b44
 
 
 
83680c0
cd47b16
 
83680c0
09e0b44
9e91550
 
 
 
 
09e0b44
 
9e91550
 
 
 
 
 
 
 
 
c576332
9e91550
 
 
c576332
9e91550
 
 
c576332
9e91550
 
 
c576332
9e91550
 
 
 
 
 
 
 
 
 
09e0b44
 
047b5ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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()