UI 텍스트 수정 (숫자 -> 단어)
Browse files
app.py
CHANGED
|
@@ -1,26 +1,43 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
"""Untitled0.ipynb
|
| 3 |
-
|
| 4 |
-
Automatically generated by Colab.
|
| 5 |
-
|
| 6 |
-
Original file is located at
|
| 7 |
-
https://colab.research.google.com/drive/1wnyeCNxzRVxoae3tCcMuf3s9Adx503U7
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
# app.py
|
| 11 |
import gradio as gr
|
| 12 |
from news_analyzer import run_once, title_attention_index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def predict(title, body):
|
| 15 |
r = run_once(title, body)
|
| 16 |
final_score = r["최종 기사 점수"]
|
| 17 |
grade = title_attention_index(final_score)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
return (
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
)
|
| 25 |
|
| 26 |
demo = gr.Interface(
|
|
@@ -29,12 +46,14 @@ demo = gr.Interface(
|
|
| 29 |
gr.Textbox(label="제목", lines=2),
|
| 30 |
gr.Textbox(label="본문", lines=18, placeholder="여기에 기사 본문을 붙여넣으세요"),
|
| 31 |
],
|
|
|
|
|
|
|
| 32 |
outputs=[
|
| 33 |
-
gr.
|
| 34 |
-
gr.
|
| 35 |
-
gr.
|
| 36 |
-
gr.Number(label="
|
| 37 |
-
gr.
|
| 38 |
],
|
| 39 |
title="제목 주의 지수",
|
| 40 |
description=(
|
|
@@ -45,4 +64,4 @@ demo = gr.Interface(
|
|
| 45 |
)
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
| 48 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
from news_analyzer import run_once, title_attention_index
|
| 4 |
+
import math # math 모듈 추가
|
| 5 |
+
|
| 6 |
+
# [NEW] ✨ 점수를 텍스트로 변환하는 헬퍼 함수
|
| 7 |
+
# (news_analyzer.py에 있던 함수를 app.py로 가져옵니다)
|
| 8 |
+
def convert_sim_to_text(score: float, threshold: float = 0.5) -> str:
|
| 9 |
+
"""
|
| 10 |
+
유사도 점수를 기준으로 텍스트 등급을 반환합니다.
|
| 11 |
+
threshold (기본값 0.5) 이상이면 '유사', 미만이면 '유사하지 않음'으로 판단합니다.
|
| 12 |
+
"""
|
| 13 |
+
if score is None or (isinstance(score, float) and math.isnan(score)):
|
| 14 |
+
return "판단 불가" # nan 값 처리
|
| 15 |
+
|
| 16 |
+
if score >= threshold + 0.15: # 예: 0.65 이상
|
| 17 |
+
return "높음 (제목이 본문을 잘 반영합니다)"
|
| 18 |
+
elif score >= threshold: # 예: 0.5 ~ 0.65
|
| 19 |
+
return "보통 (제목이 본문과 어느 정도 일치합니다)"
|
| 20 |
+
else: # 예: 0.5 미만
|
| 21 |
+
return "낮음 (제목과 본문 내용에 차이가 있습니다)"
|
| 22 |
+
|
| 23 |
|
| 24 |
def predict(title, body):
|
| 25 |
r = run_once(title, body)
|
| 26 |
final_score = r["최종 기사 점수"]
|
| 27 |
grade = title_attention_index(final_score)
|
| 28 |
+
|
| 29 |
+
# [NEW] 텍스트 변환 로직을 predict 함수에 직접 추가
|
| 30 |
+
summary_sim_text = convert_sim_to_text(r["요약유사도"], threshold=0.45)
|
| 31 |
+
body_sim_text = convert_sim_to_text(r["본문 일치도(Top5 평균)"], threshold=0.5)
|
| 32 |
+
|
| 33 |
+
# [MODIFIED] 💡 return 순서 변경
|
| 34 |
+
# 'grade' (제목 주의 지수)를 가장 첫 번째로 보냅니다.
|
| 35 |
return (
|
| 36 |
+
grade, # <-- [0]
|
| 37 |
+
summary_sim_text, # <-- [1]
|
| 38 |
+
body_sim_text, # <-- [2]
|
| 39 |
+
r["과장점수"], # <-- [3]
|
| 40 |
+
final_score, # <-- [4]
|
| 41 |
)
|
| 42 |
|
| 43 |
demo = gr.Interface(
|
|
|
|
| 46 |
gr.Textbox(label="제목", lines=2),
|
| 47 |
gr.Textbox(label="본문", lines=18, placeholder="여기에 기사 본문을 붙여넣으세요"),
|
| 48 |
],
|
| 49 |
+
# [MODIFIED] 💡 outputs 리스트 순서 변경
|
| 50 |
+
# '제목 주의 지수'를 가장 위로 올리고, 텍스트 출력을 위해 Textbox로 변경
|
| 51 |
outputs=[
|
| 52 |
+
gr.Textbox(label="제목 주의 지수", interactive=False), # <-- [0]
|
| 53 |
+
gr.Textbox(label="요약유사도"), # <-- [1]
|
| 54 |
+
gr.Textbox(label="본문 일치도(Top5 평균)"), # <-- [2]
|
| 55 |
+
gr.Number(label="과장점수"), # <-- [3]
|
| 56 |
+
gr.Number(label="최종 기사 점수"), # <-- [4]
|
| 57 |
],
|
| 58 |
title="제목 주의 지수",
|
| 59 |
description=(
|
|
|
|
| 64 |
)
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
+
demo.launch()
|