Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import networkx as nx
|
|
| 9 |
from datetime import datetime, timedelta
|
| 10 |
import gradio as gr
|
| 11 |
|
| 12 |
-
# 中文顯示設置
|
| 13 |
plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei', 'Arial Unicode MS', 'SimHei', 'DejaVu Sans']
|
| 14 |
plt.rcParams['axes.unicode_minus'] = False
|
| 15 |
|
|
@@ -60,7 +60,7 @@ def run_analysis():
|
|
| 60 |
# 統計每日情緒
|
| 61 |
summary = all_df.groupby(['候選人', '情緒']).size().unstack(fill_value=0)
|
| 62 |
summary['總貼文'] = summary.sum(axis=1)
|
| 63 |
-
summary['正面比率'] = summary.get('positive', 0) / summary['總貼文'].replace(0, 1)
|
| 64 |
summary['負面比率'] = summary.get('negative', 0) / summary['總貼文'].replace(0, 1)
|
| 65 |
|
| 66 |
# 更新歷史資料
|
|
@@ -92,7 +92,7 @@ def run_analysis():
|
|
| 92 |
plt.legend()
|
| 93 |
img_b64_trend = plot_to_base64(fig2)
|
| 94 |
|
| 95 |
-
# 3. 社群情感趨勢
|
| 96 |
sentiment_trend = all_df.groupby([pd.Grouper(key='日期', freq='D'), '情緒']).size().unstack(fill_value=0)
|
| 97 |
sentiment_trend = sentiment_trend.div(sentiment_trend.sum(axis=1), axis=0).fillna(0)
|
| 98 |
fig3 = plt.figure(figsize=(8, 5))
|
|
@@ -105,7 +105,7 @@ def run_analysis():
|
|
| 105 |
plt.legend()
|
| 106 |
img_social_sentiment = plot_to_base64(fig3)
|
| 107 |
|
| 108 |
-
# 4. 各平台表現
|
| 109 |
platforms = ["X", "Facebook", "Instagram", "PTT", "Line"]
|
| 110 |
platform_counts = pd.Series({p: random.randint(10, 100) for p in platforms})
|
| 111 |
fig4 = plt.figure(figsize=(8, 5))
|
|
|
|
| 9 |
from datetime import datetime, timedelta
|
| 10 |
import gradio as gr
|
| 11 |
|
| 12 |
+
# 中文顯示設置
|
| 13 |
plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei', 'Arial Unicode MS', 'SimHei', 'DejaVu Sans']
|
| 14 |
plt.rcParams['axes.unicode_minus'] = False
|
| 15 |
|
|
|
|
| 60 |
# 統計每日情緒
|
| 61 |
summary = all_df.groupby(['候選人', '情緒']).size().unstack(fill_value=0)
|
| 62 |
summary['總貼文'] = summary.sum(axis=1)
|
| 63 |
+
summary['正面比率'] = summary.get('positive', 0) / summary['總貼文'].replace(0, 1)
|
| 64 |
summary['負面比率'] = summary.get('negative', 0) / summary['總貼文'].replace(0, 1)
|
| 65 |
|
| 66 |
# 更新歷史資料
|
|
|
|
| 92 |
plt.legend()
|
| 93 |
img_b64_trend = plot_to_base64(fig2)
|
| 94 |
|
| 95 |
+
# 3. 社群情感趨勢
|
| 96 |
sentiment_trend = all_df.groupby([pd.Grouper(key='日期', freq='D'), '情緒']).size().unstack(fill_value=0)
|
| 97 |
sentiment_trend = sentiment_trend.div(sentiment_trend.sum(axis=1), axis=0).fillna(0)
|
| 98 |
fig3 = plt.figure(figsize=(8, 5))
|
|
|
|
| 105 |
plt.legend()
|
| 106 |
img_social_sentiment = plot_to_base64(fig3)
|
| 107 |
|
| 108 |
+
# 4. 各平台表現
|
| 109 |
platforms = ["X", "Facebook", "Instagram", "PTT", "Line"]
|
| 110 |
platform_counts = pd.Series({p: random.randint(10, 100) for p in platforms})
|
| 111 |
fig4 = plt.figure(figsize=(8, 5))
|