Update app.py
Browse files
app.py
CHANGED
@@ -83,6 +83,7 @@ def analyze_news_political_viewpoint(query):
|
|
83 |
for item in news_items:
|
84 |
title = item["title"]
|
85 |
description = item["description"]
|
|
|
86 |
combined_text = f"{title}. {description}"
|
87 |
|
88 |
# 기사 성향 분석
|
@@ -99,7 +100,8 @@ def analyze_news_political_viewpoint(query):
|
|
99 |
"원본 기사": description,
|
100 |
"성향": sentiment,
|
101 |
"성향 점수": score,
|
102 |
-
"대조 관점 기사": opposite_article
|
|
|
103 |
})
|
104 |
|
105 |
return results, sentiment_counts
|
@@ -114,11 +116,16 @@ def visualize_sentiment_distribution(sentiment_counts):
|
|
114 |
st.pyplot(fig)
|
115 |
|
116 |
# Streamlit 애플리케이션
|
117 |
-
st.
|
|
|
|
|
118 |
st.markdown("뉴스 기사의 정치 성향 분석과 반대 관점 기사를 생성하여 비교합니다.")
|
119 |
|
|
|
120 |
query = st.text_input("검색 키워드를 입력하세요", value="정치")
|
121 |
-
|
|
|
|
|
122 |
with st.spinner("분석 중..."):
|
123 |
analysis_results, sentiment_counts = analyze_news_political_viewpoint(query)
|
124 |
|
@@ -126,16 +133,18 @@ if st.button("분석 시작"):
|
|
126 |
st.success("뉴스 분석이 완료되었습니다.")
|
127 |
|
128 |
# 성향 분포 시각화
|
129 |
-
st.subheader("성향 분포 시각화")
|
130 |
visualize_sentiment_distribution(sentiment_counts)
|
131 |
|
132 |
# 상세 분석 결과 출력
|
133 |
-
st.subheader("상세 분석 결과")
|
134 |
for result in analysis_results:
|
135 |
-
st.write(f"####
|
136 |
st.write(f"- **원본 기사**: {result['원본 기사']}")
|
137 |
st.write(f"- **성향**: {result['성향']} (점수: {result['성향 점수']:.2f})")
|
138 |
st.write(f"- **대조 관점 기사**: {result['대조 관점 기사']}")
|
|
|
139 |
st.write("---")
|
140 |
else:
|
141 |
st.error("분석된 뉴스 데이터가 없습니다.")
|
|
|
|
83 |
for item in news_items:
|
84 |
title = item["title"]
|
85 |
description = item["description"]
|
86 |
+
link = item["link"] # 뉴스 링크 가져오기
|
87 |
combined_text = f"{title}. {description}"
|
88 |
|
89 |
# 기사 성향 분석
|
|
|
100 |
"원본 기사": description,
|
101 |
"성향": sentiment,
|
102 |
"성향 점수": score,
|
103 |
+
"대조 관점 기사": opposite_article,
|
104 |
+
"뉴스 링크": link # 링크 추가
|
105 |
})
|
106 |
|
107 |
return results, sentiment_counts
|
|
|
116 |
st.pyplot(fig)
|
117 |
|
118 |
# Streamlit 애플리케이션
|
119 |
+
st.set_page_config(page_title="정치적 관점 분석", page_icon="📰", layout="wide")
|
120 |
+
|
121 |
+
st.title("📰 정치적 관점 비교 분석 도구")
|
122 |
st.markdown("뉴스 기사의 정치 성향 분석과 반대 관점 기사를 생성하여 비교합니다.")
|
123 |
|
124 |
+
# 사용자로부터 검색어 입력 받기
|
125 |
query = st.text_input("검색 키워드를 입력하세요", value="정치")
|
126 |
+
|
127 |
+
# 분석 시작 버튼
|
128 |
+
if st.button("🔍 분석 시작"):
|
129 |
with st.spinner("분석 중..."):
|
130 |
analysis_results, sentiment_counts = analyze_news_political_viewpoint(query)
|
131 |
|
|
|
133 |
st.success("뉴스 분석이 완료되었습니다.")
|
134 |
|
135 |
# 성향 분포 시각화
|
136 |
+
st.subheader("📊 성향 분포 시각화")
|
137 |
visualize_sentiment_distribution(sentiment_counts)
|
138 |
|
139 |
# 상세 분석 결과 출력
|
140 |
+
st.subheader("📝 상세 분석 결과")
|
141 |
for result in analysis_results:
|
142 |
+
st.write(f"#### {result['제목']}")
|
143 |
st.write(f"- **원본 기사**: {result['원본 기사']}")
|
144 |
st.write(f"- **성향**: {result['성향']} (점수: {result['성향 점수']:.2f})")
|
145 |
st.write(f"- **대조 관점 기사**: {result['대조 관점 기사']}")
|
146 |
+
st.write(f"- **뉴스 링크**: [링크]({result['뉴스 링크']})") # 링크 출력
|
147 |
st.write("---")
|
148 |
else:
|
149 |
st.error("분석된 뉴스 데이터가 없습니다.")
|
150 |
+
|