Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,9 @@ def fetch_naver_news(query, display=10, start=1, sort="date"):
|
|
22 |
|
23 |
response = requests.get(url, headers=headers, params=params)
|
24 |
if response.status_code == 200:
|
25 |
-
|
|
|
|
|
26 |
else:
|
27 |
raise Exception(f"Error: {response.status_code}, {response.text}")
|
28 |
|
@@ -31,9 +33,10 @@ def load_translation_model():
|
|
31 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
32 |
return translator
|
33 |
|
34 |
-
# Step 3: Hugging Face
|
35 |
def load_huggingface_model():
|
36 |
classifier = pipeline("text-classification", model="bucketresearch/politicalBiasBERT")
|
|
|
37 |
return classifier
|
38 |
|
39 |
# Step 4: 정치 성향 분류 함수
|
@@ -45,7 +48,7 @@ def classify_political_sentiment(text, classifier):
|
|
45 |
score = sentiment["score"]
|
46 |
|
47 |
# 점수화
|
48 |
-
sentiment_score = score if label == "
|
49 |
|
50 |
# 키워드 기반 분류 (진보/보수)
|
51 |
progressive_keywords = ["복지", "평등", "민주", "환경", "사회적 책임"]
|
@@ -70,9 +73,11 @@ def analyze_news_political_orientation(news_items, classifier, translator):
|
|
70 |
|
71 |
# 번역: 한국어 -> 영어
|
72 |
translated_text = translator(combined_text)[0]['translation_text']
|
|
|
73 |
|
74 |
# 정치 성향 분류
|
75 |
orientation, score = classify_political_sentiment(translated_text, classifier)
|
|
|
76 |
results[orientation] += 1
|
77 |
detailed_results.append({
|
78 |
"제목": title,
|
|
|
22 |
|
23 |
response = requests.get(url, headers=headers, params=params)
|
24 |
if response.status_code == 200:
|
25 |
+
news_data = response.json()
|
26 |
+
st.write("News Data:", news_data) # 응답 내용 확인
|
27 |
+
return news_data
|
28 |
else:
|
29 |
raise Exception(f"Error: {response.status_code}, {response.text}")
|
30 |
|
|
|
33 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
34 |
return translator
|
35 |
|
36 |
+
# Step 3: Hugging Face 감성 분석 모델 로드
|
37 |
def load_huggingface_model():
|
38 |
classifier = pipeline("text-classification", model="bucketresearch/politicalBiasBERT")
|
39 |
+
st.write("모델 로드 완료")
|
40 |
return classifier
|
41 |
|
42 |
# Step 4: 정치 성향 분류 함수
|
|
|
48 |
score = sentiment["score"]
|
49 |
|
50 |
# 점수화
|
51 |
+
sentiment_score = score if label == "POSITIVE" else -score
|
52 |
|
53 |
# 키워드 기반 분류 (진보/보수)
|
54 |
progressive_keywords = ["복지", "평등", "민주", "환경", "사회적 책임"]
|
|
|
73 |
|
74 |
# 번역: 한국어 -> 영어
|
75 |
translated_text = translator(combined_text)[0]['translation_text']
|
76 |
+
st.write("Translated Text:", translated_text) # 번역된 텍스트 확인
|
77 |
|
78 |
# 정치 성향 분류
|
79 |
orientation, score = classify_political_sentiment(translated_text, classifier)
|
80 |
+
st.write(f"Orientation: {orientation}, Score: {score}") # 성향 및 점수 확인
|
81 |
results[orientation] += 1
|
82 |
detailed_results.append({
|
83 |
"제목": title,
|