Update app.py
Browse files
app.py
CHANGED
@@ -52,12 +52,20 @@ def generate_article_gpt4(prompt):
|
|
52 |
st.error(f"Error generating text: {e}")
|
53 |
return "GPT-4 ํ
์คํธ ์์ฑ ์คํจ"
|
54 |
|
55 |
-
|
|
|
56 |
def analyze_article_sentiment(text, classifier):
|
57 |
result = classifier(text[:512]) # ๋๋ฌด ๊ธด ํ
์คํธ๋ ์๋ผ์ ๋ถ์
|
58 |
label = result[0]["label"]
|
59 |
score = result[0]["score"]
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
# ์ ์น์ ๊ด์ ๋น๊ต ๋ฐ ๋ฐ๋ ๊ด์ ์์ฑ
|
63 |
def analyze_news_political_viewpoint(query):
|
@@ -68,7 +76,7 @@ def analyze_news_political_viewpoint(query):
|
|
68 |
|
69 |
classifier = load_sentiment_model()
|
70 |
results = []
|
71 |
-
sentiment_counts = {"์ง๋ณด": 0, "๋ณด์": 0, "์ค๋ฆฝ": 0}
|
72 |
|
73 |
for item in news_items:
|
74 |
title = item["title"]
|
@@ -77,7 +85,7 @@ def analyze_news_political_viewpoint(query):
|
|
77 |
|
78 |
# ๊ธฐ์ฌ ์ฑํฅ ๋ถ์
|
79 |
sentiment, score = analyze_article_sentiment(combined_text, classifier)
|
80 |
-
sentiment_counts[sentiment] += 1
|
81 |
|
82 |
# ๋ฐ๋ ๊ด์ ๊ธฐ์ฌ ์์ฑ
|
83 |
opposite_perspective = "๋ณด์์ " if sentiment == "์ง๋ณด" else "์ง๋ณด์ "
|
@@ -94,6 +102,7 @@ def analyze_news_political_viewpoint(query):
|
|
94 |
|
95 |
return results, sentiment_counts
|
96 |
|
|
|
97 |
# ์ฑํฅ ๋ถํฌ ์๊ฐํ
|
98 |
def visualize_sentiment_distribution(sentiment_counts):
|
99 |
fig, ax = plt.subplots()
|
|
|
52 |
st.error(f"Error generating text: {e}")
|
53 |
return "GPT-4 ํ
์คํธ ์์ฑ ์คํจ"
|
54 |
|
55 |
+
|
56 |
+
# ์ ์น ์ฑํฅ ๋ถ์
|
57 |
def analyze_article_sentiment(text, classifier):
|
58 |
result = classifier(text[:512]) # ๋๋ฌด ๊ธด ํ
์คํธ๋ ์๋ผ์ ๋ถ์
|
59 |
label = result[0]["label"]
|
60 |
score = result[0]["score"]
|
61 |
+
|
62 |
+
# ๋ชจ๋ธ์์ ๋ฐํํ๋ ๋ผ๋ฒจ์ "์ง๋ณด", "๋ณด์", "์ค๋ฆฝ"์ผ๋ก ๋งคํ
|
63 |
+
if label == "LEFT":
|
64 |
+
return "์ง๋ณด", score
|
65 |
+
elif label == "RIGHT":
|
66 |
+
return "๋ณด์", score
|
67 |
+
else:
|
68 |
+
return "์ค๋ฆฝ", score
|
69 |
|
70 |
# ์ ์น์ ๊ด์ ๋น๊ต ๋ฐ ๋ฐ๋ ๊ด์ ์์ฑ
|
71 |
def analyze_news_political_viewpoint(query):
|
|
|
76 |
|
77 |
classifier = load_sentiment_model()
|
78 |
results = []
|
79 |
+
sentiment_counts = {"์ง๋ณด": 0, "๋ณด์": 0, "์ค๋ฆฝ": 0} # ๋งคํ๋ ๋ผ๋ฒจ์ ๋ง๊ฒ ์ด๊ธฐํ
|
80 |
|
81 |
for item in news_items:
|
82 |
title = item["title"]
|
|
|
85 |
|
86 |
# ๊ธฐ์ฌ ์ฑํฅ ๋ถ์
|
87 |
sentiment, score = analyze_article_sentiment(combined_text, classifier)
|
88 |
+
sentiment_counts[sentiment] += 1 # ๋งคํ๋ ํค๋ก ์นด์ดํธ ์ฆ๊ฐ
|
89 |
|
90 |
# ๋ฐ๋ ๊ด์ ๊ธฐ์ฌ ์์ฑ
|
91 |
opposite_perspective = "๋ณด์์ " if sentiment == "์ง๋ณด" else "์ง๋ณด์ "
|
|
|
102 |
|
103 |
return results, sentiment_counts
|
104 |
|
105 |
+
|
106 |
# ์ฑํฅ ๋ถํฌ ์๊ฐํ
|
107 |
def visualize_sentiment_distribution(sentiment_counts):
|
108 |
fig, ax = plt.subplots()
|