Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import matplotlib.pyplot as plt
|
|
|
|
| 4 |
from transformers import pipeline
|
| 5 |
import openai
|
| 6 |
import os
|
|
@@ -8,6 +9,11 @@ import os
|
|
| 8 |
# OpenAI API ํค ์ค์ (ํ๊ฒฝ๋ณ์์์ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ)
|
| 9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# ๋ค์ด๋ฒ ๋ด์ค API๋ฅผ ํตํด ์ค์ ๋ด์ค ๊ธฐ์ฌ ๊ฐ์ ธ์ค๊ธฐ
|
| 12 |
def fetch_naver_news(query, display=5):
|
| 13 |
client_id = "I_8koTJh3R5l4wLurQbG" # ๋ค์ด๋ฒ ๊ฐ๋ฐ์ ์ผํฐ์์ ๋ฐ๊ธ๋ฐ์ Client ID
|
|
@@ -108,13 +114,17 @@ def analyze_news_political_viewpoint(query):
|
|
| 108 |
|
| 109 |
# ์ฑํฅ ๋ถํฌ ์๊ฐํ (๋ง๋ ๊ทธ๋ํ)
|
| 110 |
def visualize_sentiment_distribution(sentiment_counts):
|
| 111 |
-
fig, ax = plt.subplots()
|
| 112 |
labels = list(sentiment_counts.keys())
|
| 113 |
sizes = list(sentiment_counts.values())
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
st.pyplot(fig)
|
| 119 |
|
| 120 |
# Streamlit ์ ํ๋ฆฌ์ผ์ด์
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
+
import seaborn as sns
|
| 5 |
from transformers import pipeline
|
| 6 |
import openai
|
| 7 |
import os
|
|
|
|
| 9 |
# OpenAI API ํค ์ค์ (ํ๊ฒฝ๋ณ์์์ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ)
|
| 10 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 11 |
|
| 12 |
+
# ํ๊ธ ํฐํธ ์ค์
|
| 13 |
+
import matplotlib
|
| 14 |
+
matplotlib.rcParams['font.family'] = 'NanumGothic' # ํ๊ธ ํฐํธ๋ฅผ ์ค์ ํฉ๋๋ค.
|
| 15 |
+
matplotlib.rcParams['axes.unicode_minus'] = False # ๋ง์ด๋์ค ๊ธฐํธ ๊นจ์ง ๋ฐฉ์ง
|
| 16 |
+
|
| 17 |
# ๋ค์ด๋ฒ ๋ด์ค API๋ฅผ ํตํด ์ค์ ๋ด์ค ๊ธฐ์ฌ ๊ฐ์ ธ์ค๊ธฐ
|
| 18 |
def fetch_naver_news(query, display=5):
|
| 19 |
client_id = "I_8koTJh3R5l4wLurQbG" # ๋ค์ด๋ฒ ๊ฐ๋ฐ์ ์ผํฐ์์ ๋ฐ๊ธ๋ฐ์ Client ID
|
|
|
|
| 114 |
|
| 115 |
# ์ฑํฅ ๋ถํฌ ์๊ฐํ (๋ง๋ ๊ทธ๋ํ)
|
| 116 |
def visualize_sentiment_distribution(sentiment_counts):
|
| 117 |
+
fig, ax = plt.subplots(figsize=(8, 5))
|
| 118 |
labels = list(sentiment_counts.keys())
|
| 119 |
sizes = list(sentiment_counts.values())
|
| 120 |
+
|
| 121 |
+
# ์์ ์ค์ (๋ถ๋๋ฌ์ด ํ๋ ํธ)
|
| 122 |
+
color_palette = sns.color_palette("pastel")[0:len(sizes)]
|
| 123 |
+
|
| 124 |
+
ax.bar(labels, sizes, color=color_palette)
|
| 125 |
+
ax.set_xlabel('์ฑํฅ', fontsize=14)
|
| 126 |
+
ax.set_ylabel('๊ฑด์', fontsize=14)
|
| 127 |
+
ax.set_title('๋ด์ค ์ฑํฅ ๋ถํฌ', fontsize=16)
|
| 128 |
st.pyplot(fig)
|
| 129 |
|
| 130 |
# Streamlit ์ ํ๋ฆฌ์ผ์ด์
|