-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization.py
More file actions
42 lines (35 loc) · 1006 Bytes
/
visualization.py
File metadata and controls
42 lines (35 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import pandas as pd
import streamlit as st
#WORD CLOUD
def show_wordcloud(text):
if not text.strip():
st.warning("No text available for Word Cloud.")
return
wordcloud = WordCloud(
width=400,
height=200,
background_color="white"
).generate(text)
fig, ax = plt.subplots()
ax.imshow(wordcloud, interpolation="bilinear")
ax.axis("off")
st.pyplot(fig)
#SENTIMENT DISTRIBUTION CHART
def show_sentiment_chart(download_list):
sentiments = {
"Positive": 0,
"Neutral": 0,
"Negative": 0
}
for item in download_list:
score = item["compound_score"]
if score > 0.05:
sentiments["Positive"] += 1
elif score < -0.05:
sentiments["Negative"] += 1
else:
sentiments["Neutral"] += 1
df = pd.DataFrame.from_dict(sentiments, orient="index", columns=["Count"])
st.bar_chart(df)