selbl commited on
Commit
5a08021
β€’
1 Parent(s): 97ed632

Upload 3_πŸ“”_Demos.py

Browse files
Files changed (1) hide show
  1. pages/3_πŸ“”_Demos.py +124 -0
pages/3_πŸ“”_Demos.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+
4
+ def main():
5
+ st.title("Demo Images")
6
+
7
+ st.write("This is a demo of the app using the sample group chat from the repository. "
8
+ "The sample chat is a conversation between three users: Person, Persona, Hito.")
9
+
10
+ st.subheader("Trends in the number of messages")
11
+
12
+ st.write("The first output from the app is the trend in the number of messages. "
13
+ "The image to the left shows a breakdown per user of the number of messages they have sent during their whole stay in the group. "
14
+ "The image to the right shows the evolution of messages by each calendar year.")
15
+
16
+ # Load images for trends in the number of messages
17
+ img1_path = "Imgs/DemoImages/NumberOfMessages.png"
18
+ img2_path = "Imgs/DemoImages/EvolutionNumberOfMessages.png"
19
+
20
+ img1 = Image.open(img1_path)
21
+ img2 = Image.open(img2_path)
22
+
23
+ # Keep img1 as is and resize img2 to match img1's dimensions while maintaining its aspect ratio
24
+ img2_resized = img2.resize(img1.size)
25
+
26
+ # Display trends in the number of messages
27
+ col1, col2 = st.columns(2)
28
+ with col1:
29
+ st.image(img1, caption='Number of Messages per User', use_column_width=True)
30
+ with col2:
31
+ st.image(img2_resized, caption='Evolution of Number of Messages by Year', use_column_width=True)
32
+
33
+ st.subheader("Word Cloud")
34
+
35
+ st.write("The app generates a word cloud for you to find patterns or repeated words in your conversations. "
36
+ "The image in the upper-left corner shows the word cloud for all of the members of the group. "
37
+ "The rest of the pictures show the word clouds per each member.")
38
+
39
+ # Load word cloud images
40
+ wordcloud_group_path = "Imgs/DemoImages/WordCloudGroup.png"
41
+ wordcloud_hito_path = "Imgs/DemoImages/WordCloudHito.png"
42
+ wordcloud_person_path = "Imgs/DemoImages/WordCloudPerson.png"
43
+ wordcloud_persona_path = "Imgs/DemoImages/WordCloudPersona.png"
44
+
45
+ wordcloud_group = Image.open(wordcloud_group_path)
46
+ wordcloud_hito = Image.open(wordcloud_hito_path)
47
+ wordcloud_person = Image.open(wordcloud_person_path)
48
+ wordcloud_persona = Image.open(wordcloud_persona_path)
49
+
50
+ # Resize images to match the dimensions of the first word cloud
51
+ wordcloud_hito_resized = wordcloud_hito.resize(wordcloud_group.size)
52
+ wordcloud_person_resized = wordcloud_person.resize(wordcloud_group.size)
53
+ wordcloud_persona_resized = wordcloud_persona.resize(wordcloud_group.size)
54
+
55
+ # Display word cloud images in a 2x2 grid
56
+ col1, col2 = st.columns(2)
57
+ with col1:
58
+ st.image(wordcloud_group, caption='Word Cloud for All Members', use_column_width=True)
59
+ st.image(wordcloud_person_resized, caption='Word Cloud for Person', use_column_width=True)
60
+ with col2:
61
+ st.image(wordcloud_hito_resized, caption='Word Cloud for Hito', use_column_width=True)
62
+ st.image(wordcloud_persona_resized, caption='Word Cloud for Persona', use_column_width=True)
63
+
64
+ st.subheader("Sentiment Analysis")
65
+
66
+ st.write("Another important metric is the sentiment underneath the messages in the group. "
67
+ "Maybe someone is more positive or negative than the rest? "
68
+ "The images below show the breakdown in the sentiments of the messages each user has sent. "
69
+ "The code categorizes each message as positive, neutral or negative. "
70
+ "I provide a bar graph and a line graph version to satisfy both preferences.")
71
+
72
+ # Load sentiment analysis images
73
+ sentiment_hito_path = "Imgs/DemoImages/SentimentHito.png"
74
+ sentiment_person_path = "Imgs/DemoImages/SentimentPerson.png"
75
+ sentiment_persona_path = "Imgs/DemoImages/SentimentPersona.png"
76
+ sentiment_graph_hito_path = "Imgs/DemoImages/SentimentGraphHito.png"
77
+ sentiment_graph_person_path = "Imgs/DemoImages/SentimentGraphPerson.png"
78
+ sentiment_graph_persona_path = "Imgs/DemoImages/SentimentGraphPersona.png"
79
+
80
+ sentiment_hito = Image.open(sentiment_hito_path)
81
+ sentiment_person = Image.open(sentiment_person_path)
82
+ sentiment_persona = Image.open(sentiment_persona_path)
83
+ sentiment_graph_hito = Image.open(sentiment_graph_hito_path)
84
+ sentiment_graph_person = Image.open(sentiment_graph_person_path)
85
+ sentiment_graph_persona = Image.open(sentiment_graph_persona_path)
86
+
87
+ # Display sentiment analysis images side by side
88
+ col1, col2, col3 = st.columns(3)
89
+ with col1:
90
+ st.image(sentiment_hito, caption='Sentiment for Hito', use_column_width=True)
91
+ with col2:
92
+ st.image(sentiment_person, caption='Sentiment for Person', use_column_width=True)
93
+ with col3:
94
+ st.image(sentiment_persona, caption='Sentiment for Persona', use_column_width=True)
95
+
96
+ # Display sentiment analysis graph images side by side
97
+ col4, col5, col6 = st.columns(3)
98
+ with col4:
99
+ st.image(sentiment_graph_hito, caption='Sentiment Graph for Hito', use_column_width=True)
100
+ with col5:
101
+ st.image(sentiment_graph_person, caption='Sentiment Graph for Person', use_column_width=True)
102
+ with col6:
103
+ st.image(sentiment_graph_persona, caption='Sentiment Graph for Persona', use_column_width=True)
104
+
105
+ st.subheader("Activation Times")
106
+
107
+ st.write("We also care when the group is more or less active, the following figures show when the group is more active as a whole as well as a breakdown per user.")
108
+
109
+ # Load activation times images
110
+ activation_all_path = "Imgs/DemoImages/ActivationAll.png"
111
+ activation_per_user_path = "Imgs/DemoImages/ActivationPerUser.png"
112
+
113
+ activation_all = Image.open(activation_all_path)
114
+ activation_per_user = Image.open(activation_per_user_path)
115
+
116
+ # Display activation times images side by side
117
+ col1, col2 = st.columns(2)
118
+ with col1:
119
+ st.image(activation_all, caption='Activation Times for All Members', use_column_width=True)
120
+ with col2:
121
+ st.image(activation_per_user, caption='Activation Times per User', use_column_width=True)
122
+
123
+ if __name__ == "__main__":
124
+ main()