DSJA commited on
Commit
9e91550
·
1 Parent(s): 047b5ad

UI 폰트 수정 재시도

Browse files
Files changed (1) hide show
  1. app.py +35 -74
app.py CHANGED
@@ -1,14 +1,9 @@
1
- # app.py
2
  import gradio as gr
3
  from news_analyzer import run_once, title_attention_index
4
- import math
5
 
6
- # [NEW] ✨ 점수를 텍스트로 변환하는 헬퍼 함수
7
  def convert_sim_to_text(score: float, threshold: float = 0.5) -> str:
8
- """
9
- 유사도 점수를 기준으로 텍스트 등급을 반환합니다.
10
- threshold (기본값 0.5) 이상이면 '유사', 미만이면 '유사하지 않음'으로 판단합니다.
11
- """
12
  if score is None or (isinstance(score, float) and math.isnan(score)):
13
  return "판단 불가" # nan 값 처리
14
 
@@ -25,83 +20,49 @@ def predict(title, body):
25
  final_score = r["최종 기사 점수"]
26
  grade = title_attention_index(final_score)
27
 
28
- # [NEW] 텍스트 변환 로직을 predict 함수에 직접 추가
29
  summary_sim_text = convert_sim_to_text(r["요약유사도"], threshold=0.45)
30
  body_sim_text = convert_sim_to_text(r["본문 일치도(Top5 평균)"], threshold=0.5)
31
 
32
- # [수정] return 순서를 outputs 순서와 정확히 일치시킵니다.
33
  return (
34
- grade, # [0] -> output_grade
35
- summary_sim_text, # [1] -> output_summary_sim
36
- body_sim_text, # [2] -> output_body_sim
37
- r["과장점수"], # [3] -> output_exag_score
38
- final_score, # [4] -> output_final_score
39
  )
40
 
41
- # [NEW] ✨ CSS 스타일 정의
42
- # 'output-label' 클래스를 가진 컴포넌트 내부의 라벨 텍스트(.label-text)를
43
- # 18px 크기와 굵은 글씨(bold)로 만듭니다.
44
- CUSTOM_CSS = """
45
- .output-label .label-text {
46
- font-size: 18px !important;
47
- font-weight: bold !important;
48
- }
49
- """
50
-
51
- # [MODIFIED] 💡 gr.Interface -> gr.Blocks
52
- with gr.Blocks(css=CUSTOM_CSS, title="제목 주의 지수") as demo:
53
- # 앱의 전체 제목과 설명
54
- gr.Markdown("# 제목 주의 지수")
55
- gr.Markdown(
56
- "원하는 기사의 제목과 본문을 아래에 입력하면 제목-본문 유사도, 과장 점수를 바탕으로 '제목 주의 지수'를 계산합니다.\n\n"
57
- "ℹ️ **자세한 설명이 궁금하다면 "
58
- "[여기를 클릭하세요](https://www.notion.so/25cb058cee088026badfcab340e9966d?source=copy_link)**"
59
- )
60
-
61
- # UI 레이아웃 (2단으로 나눔)
62
- with gr.Row():
63
- with gr.Column(scale=1): # 왼쪽 입력(Input) 칸
64
- title_input = gr.Textbox(label="제목", lines=2)
65
- body_input = gr.Textbox(label="본문", lines=18, placeholder="여기에 기사 본문을 붙여넣으세요")
66
- with gr.Row():
67
- clear_btn = gr.Button("Clear")
68
- submit_btn = gr.Button("Submit", variant="primary")
69
-
70
- with gr.Column(scale=1): # 오른쪽 출력(Output) 칸
71
- # [MODIFIED] elem_classes="output-label"를 추가하여 CSS를 적용합니다.
72
- output_grade = gr.Textbox(
73
- label="제목 주의 지수",
74
- interactive=False,
75
- elem_classes="output-label" # CSS 적용 클래스
76
- )
77
- output_summary_sim = gr.Textbox(
78
  label="요약 유사도",
79
- info="기사 제목과 기사의 요약된 내용이 일치할까?",
80
- elem_classes="output-label" # CSS 적용 클래스
81
- )
82
- output_body_sim = gr.Textbox(
83
  label="본문 일치도(Top5 평균)",
84
- info="기사 내용을 잘 함축한 제목일까?",
85
- elem_classes="output-label" # CSS 적용 클래스
86
- )
87
- output_exag_score = gr.Number(
88
  label="과장점수",
89
- info="기사의 제목이 얼마나 과장되어 있을까?",
90
- elem_classes="output-label" # CSS 적용 클래스
91
- )
92
- output_final_score = gr.Number(
93
  label="최종 기사 점수",
94
- info=" 기사를 점수 매겨본다면?",
95
- elem_classes="output-label" # CSS 적용 클래스
96
- )
97
-
98
- # 버튼 클릭 시 동작 정의
99
- inputs = [title_input, body_input]
100
- outputs = [output_grade, output_summary_sim, output_body_sim, output_exag_score, output_final_score]
101
-
102
- submit_btn.click(fn=predict, inputs=inputs, outputs=outputs)
103
- # Clear 버튼: 입력 2개, 출력 5개를 모두 비움
104
- clear_btn.click(lambda: [None, None] + [None] * len(outputs), outputs=inputs + outputs)
105
 
106
  if __name__ == "__main__":
107
  demo.launch()
 
 
1
  import gradio as gr
2
  from news_analyzer import run_once, title_attention_index
3
+ import math
4
 
 
5
  def convert_sim_to_text(score: float, threshold: float = 0.5) -> str:
6
+
 
 
 
7
  if score is None or (isinstance(score, float) and math.isnan(score)):
8
  return "판단 불가" # nan 값 처리
9
 
 
20
  final_score = r["최종 기사 점수"]
21
  grade = title_attention_index(final_score)
22
 
 
23
  summary_sim_text = convert_sim_to_text(r["요약유사도"], threshold=0.45)
24
  body_sim_text = convert_sim_to_text(r["본문 일치도(Top5 평균)"], threshold=0.5)
25
 
 
26
  return (
27
+ grade,
28
+ summary_sim_text,
29
+ body_sim_text,
30
+ r["과장점수"],
31
+ final_score,
32
  )
33
 
34
+ demo = gr.Interface(
35
+ fn=predict,
36
+ inputs=[
37
+ gr.Textbox(label="제목", lines=2),
38
+ gr.Textbox(label="본문", lines=18, placeholder="여기에 기사 본문을 붙여넣으세요"),
39
+ ],
40
+ outputs=[
41
+ gr.Textbox(label="제목 주의 지수", interactive=False), # <-- [0]
42
+ gr.Textbox(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  label="요약 유사도",
44
+ info="기사 제목과 기사의 요약된 내용이 일치할까?"
45
+ ), # <-- [1]
46
+ gr.Textbox(
 
47
  label="본문 일치도(Top5 평균)",
48
+ info="기사 내용을 잘 함축한 제목일까?"
49
+ ), # <-- [2]
50
+ gr.Number(
 
51
  label="과장점수",
52
+ info="기사의 제목이 얼마나 과장되어 있을까?"
53
+ ), # <-- [3]
54
+ gr.Number(
 
55
  label="최종 기사 점수",
56
+ info="기사의 제목을 점수 매겨본다면?"
57
+ ), # <-- [4]
58
+ ],
59
+ title="제목 주의 지수",
60
+ description=(
61
+ "원하는 기사의 제목과 본문을 아래에 입력하면 제목-본문 유사도, 과장 점수를 바탕으로 '제목 주의 지수'를 계산합니다.\n\n"
62
+ "ℹ️ **자세한 설명이 궁금하다면 "
63
+ "[여기를 클릭하세요](https://www.notion.so/25cb058cee088026badfcab340e9966d?source=copy_link)**"
64
+ ),
65
+ )
 
66
 
67
  if __name__ == "__main__":
68
  demo.launch()