820nam commited on
Commit
f8297ef
ยท
verified ยท
1 Parent(s): 58522ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
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
- ax.bar(labels, sizes, color=["blue", "red", "gray"])
115
- ax.set_xlabel('์„ฑํ–ฅ')
116
- ax.set_ylabel('๊ฑด์ˆ˜')
117
- ax.set_title('๋‰ด์Šค ์„ฑํ–ฅ ๋ถ„ํฌ')
 
 
 
 
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 ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜