Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ def fetch_naver_news(query, display=5):
|
|
26 |
return response.json()
|
27 |
except requests.exceptions.RequestException as e:
|
28 |
st.error(f"API 호출 중 오류 발생: {e}")
|
29 |
-
return None
|
30 |
|
31 |
# 정치 성향 분류
|
32 |
def classify_sentiment(text, classifier):
|
@@ -77,33 +77,34 @@ if st.button("분석 시작"):
|
|
77 |
# 네이버 뉴스 데이터 수집
|
78 |
news_data = fetch_naver_news(query, display=10)
|
79 |
if news_data is None:
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
108 |
except Exception as e:
|
109 |
st.error(f"오류 발생: {e}")
|
|
|
26 |
return response.json()
|
27 |
except requests.exceptions.RequestException as e:
|
28 |
st.error(f"API 호출 중 오류 발생: {e}")
|
29 |
+
return None # 뉴스 데이터가 없으면 None 반환
|
30 |
|
31 |
# 정치 성향 분류
|
32 |
def classify_sentiment(text, classifier):
|
|
|
77 |
# 네이버 뉴스 데이터 수집
|
78 |
news_data = fetch_naver_news(query, display=10)
|
79 |
if news_data is None:
|
80 |
+
st.error("뉴스 데이터가 없습니다.")
|
81 |
+
else:
|
82 |
+
news_items = news_data["items"]
|
83 |
+
|
84 |
+
# 모델 로드
|
85 |
+
classifier = load_model()
|
86 |
+
|
87 |
+
# 뉴스 데이터 분석
|
88 |
+
results, detailed_results = analyze_news(news_items, classifier)
|
89 |
+
|
90 |
+
# 분석 결과 시각화
|
91 |
+
st.subheader("분석 결과 요약")
|
92 |
+
st.write(f"진보: {results['진보']}건")
|
93 |
+
st.write(f"보수: {results['보수']}건")
|
94 |
+
st.write(f"중립: {results['중립']}건")
|
95 |
+
|
96 |
+
# 파이 차트
|
97 |
+
st.subheader("성향 분포 차트")
|
98 |
+
st.bar_chart(pd.DataFrame.from_dict(results, orient='index', columns=["건수"]))
|
99 |
+
|
100 |
+
# 세부 결과 출력
|
101 |
+
st.subheader("세부 결과")
|
102 |
+
df = pd.DataFrame(detailed_results)
|
103 |
+
st.dataframe(df)
|
104 |
+
|
105 |
+
# 링크 포함한 뉴스 출력
|
106 |
+
st.subheader("뉴스 링크")
|
107 |
+
for index, row in df.iterrows():
|
108 |
+
st.write(f"- [{row['제목']}]({row['링크']}) (성향: {row['성향']}, 점수: {row['점수']:.2f})")
|
109 |
except Exception as e:
|
110 |
st.error(f"오류 발생: {e}")
|