Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,6 @@ def fetch_naver_news(query, display=10, start=1, sort="date"):
|
|
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}")
|
@@ -36,7 +35,6 @@ def load_translation_model():
|
|
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: ์ ์น ์ฑํฅ ๋ถ๋ฅ ํจ์
|
@@ -73,17 +71,16 @@ def analyze_news_political_orientation(news_items, classifier, translator):
|
|
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,
|
84 |
"์์ฝ": description,
|
85 |
"์ฑํฅ": orientation,
|
86 |
"์ ์": score,
|
|
|
87 |
})
|
88 |
|
89 |
return results, detailed_results
|
@@ -127,7 +124,7 @@ if st.button("๋ถ์ ์์"):
|
|
127 |
# ๋งํฌ ํฌํจํ ๋ด์ค ์ถ๋ ฅ
|
128 |
st.subheader("๋ด์ค ๋งํฌ")
|
129 |
for index, row in df.iterrows():
|
130 |
-
st.write(f"- [{row['์ ๋ชฉ']}] (์ฑํฅ: {row['์ฑํฅ']}, ์ ์: {row['์ ์']:.2f})")
|
131 |
|
132 |
except Exception as e:
|
133 |
st.error(f"์ค๋ฅ ๋ฐ์: {e}")
|
|
|
23 |
response = requests.get(url, headers=headers, params=params)
|
24 |
if response.status_code == 200:
|
25 |
news_data = response.json()
|
|
|
26 |
return news_data
|
27 |
else:
|
28 |
raise Exception(f"Error: {response.status_code}, {response.text}")
|
|
|
35 |
# Step 3: Hugging Face ์ ์น ์ฑํฅ ๋ถ์ ๋ชจ๋ธ ๋ก๋
|
36 |
def load_huggingface_model():
|
37 |
classifier = pipeline("text-classification", model="bucketresearch/politicalBiasBERT")
|
|
|
38 |
return classifier
|
39 |
|
40 |
# Step 4: ์ ์น ์ฑํฅ ๋ถ๋ฅ ํจ์
|
|
|
71 |
|
72 |
# ๋ฒ์ญ: ํ๊ตญ์ด -> ์์ด
|
73 |
translated_text = translator(combined_text)[0]['translation_text']
|
|
|
74 |
|
75 |
# ์ ์น ์ฑํฅ ๋ถ๋ฅ
|
76 |
orientation, score = classify_political_sentiment(translated_text, classifier)
|
|
|
77 |
results[orientation] += 1
|
78 |
detailed_results.append({
|
79 |
"์ ๋ชฉ": title,
|
80 |
"์์ฝ": description,
|
81 |
"์ฑํฅ": orientation,
|
82 |
"์ ์": score,
|
83 |
+
"๋งํฌ": item["link"]
|
84 |
})
|
85 |
|
86 |
return results, detailed_results
|
|
|
124 |
# ๋งํฌ ํฌํจํ ๋ด์ค ์ถ๋ ฅ
|
125 |
st.subheader("๋ด์ค ๋งํฌ")
|
126 |
for index, row in df.iterrows():
|
127 |
+
st.write(f"- [{row['์ ๋ชฉ']}]({row['๋งํฌ']}) (์ฑํฅ: {row['์ฑํฅ']}, ์ ์: {row['์ ์']:.2f})")
|
128 |
|
129 |
except Exception as e:
|
130 |
st.error(f"์ค๋ฅ ๋ฐ์: {e}")
|