820nam commited on
Commit
02d5bf8
·
verified ·
1 Parent(s): 4e47ea7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -33
app.py CHANGED
@@ -25,7 +25,8 @@ def fetch_naver_news(query, display=10, start=1, sort="date"):
25
  news_data = response.json()
26
  return news_data
27
  else:
28
- raise Exception(f"Error: {response.status_code}, {response.text}")
 
29
 
30
  # Step 2: Hugging Face 번역 모델 로드 (한국어 -> 영어)
31
  def load_translation_model():
@@ -99,39 +100,37 @@ if st.button("분석 시작"):
99
  # 네이버 뉴스 데이터 수집
100
  news_data = fetch_naver_news(query, display=10)
101
 
102
- # 데이터 수집된 상태 확인
103
- if not news_data or not news_data.get("items"):
104
  st.error("뉴스 데이터를 불러오는 데 실패했습니다.")
105
- return # 오류 발생 시, return을 대신하여 오류를 보여줍니다.
106
-
107
- news_items = news_data["items"]
108
-
109
- # Hugging Face 모델 로드
110
- classifier = load_huggingface_model()
111
- translator = load_translation_model()
112
-
113
- # 뉴스 데이터 분석
114
- results, detailed_results = analyze_news_political_orientation(news_items, classifier, translator)
115
-
116
- # 분석 결과 시각화
117
- st.subheader("분석 결과 요약")
118
- st.write(f"진보: {results['진보']}건")
119
- st.write(f"보수: {results['보수']}건")
120
- st.write(f"중립: {results['중립']}건")
121
-
122
- # 성향 분포 차트
123
- st.subheader("성향 분포 차트")
124
- st.bar_chart(pd.DataFrame.from_dict(results, orient='index', columns=["건수"]))
125
-
126
- # 세부 결과 출력
127
- st.subheader("세부 결과")
128
- df = pd.DataFrame(detailed_results)
129
- st.dataframe(df)
130
-
131
- # 링크 포함한 뉴스 출력
132
- st.subheader("뉴스 링크")
133
- for index, row in df.iterrows():
134
- st.write(f"- [{row['제목']}]({row['링크']}) (성향: {row['성향']}, 점수: {row['점수']:.2f})")
135
 
136
  except Exception as e:
137
  st.error(f"오류 발생: {e}")
 
25
  news_data = response.json()
26
  return news_data
27
  else:
28
+ st.error(f"Error: {response.status_code}, {response.text}")
29
+ return None
30
 
31
  # Step 2: Hugging Face 번역 모델 로드 (한국어 -> 영어)
32
  def load_translation_model():
 
100
  # 네이버 뉴스 데이터 수집
101
  news_data = fetch_naver_news(query, display=10)
102
 
103
+ if news_data is None:
 
104
  st.error("뉴스 데이터를 불러오는 데 실패했습니다.")
105
+ else:
106
+ news_items = news_data["items"]
107
+
108
+ # Hugging Face 모델 로드
109
+ classifier = load_huggingface_model()
110
+ translator = load_translation_model()
111
+
112
+ # 뉴스 데이터 분석
113
+ results, detailed_results = analyze_news_political_orientation(news_items, classifier, translator)
114
+
115
+ # 분석 결과 시각화
116
+ st.subheader("분석 결과 요약")
117
+ st.write(f"진보: {results['진보']}건")
118
+ st.write(f"보수: {results['보수']}건")
119
+ st.write(f"중립: {results['중립']}건")
120
+
121
+ # 성향 분포 차트
122
+ st.subheader("성향 분포 차트")
123
+ st.bar_chart(pd.DataFrame.from_dict(results, orient='index', columns=["건수"]))
124
+
125
+ # 세부 결과 출력
126
+ st.subheader("세부 결과")
127
+ df = pd.DataFrame(detailed_results)
128
+ st.dataframe(df)
129
+
130
+ # 링크 포함한 뉴스 출력
131
+ st.subheader("뉴스 링크")
132
+ for index, row in df.iterrows():
133
+ st.write(f"- [{row['제목']}]({row['링크']}) (성향: {row['성향']}, 점수: {row['점수']:.2f})")
 
134
 
135
  except Exception as e:
136
  st.error(f"오류 발생: {e}")