ifisch commited on
Commit
c0285dc
·
verified ·
1 Parent(s): 8e91224

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -17
app.py CHANGED
@@ -3,22 +3,22 @@ import torch
3
  from transformers import GPT2Tokenizer, GPT2LMHeadModel
4
  import base64
5
  from datetime import datetime
6
-
7
 
8
 
9
  party_dict = {
10
- 'AfD':'./afd_gpt2',
11
- 'Die Grünen':'./gruene_gpt2',
12
- 'CDU/CSU':'./cdu_csu_gpt2',
13
- 'die Linke':'./linke_gpt2',
14
  }
15
 
16
  picture_paths = {
17
- 'blue_check': "./app_pictures/Twitter_Verified_Badge.png",
18
- 'AfD' : "./app_pictures/afd_logo.png",
19
- 'CDU/CSU' : "./app_pictures/cdu_logo.png",
20
- 'Die Grünen' : "./app_pictures/gruene_logo.png",
21
- 'die Linke' : "./app_pictures/linke_logo.png"
22
  }
23
 
24
  party_info = {
@@ -28,7 +28,22 @@ party_info = {
28
  "die Linke": ("Die Linke", "@dieLinke")
29
  }
30
 
 
 
 
 
 
 
31
 
 
 
 
 
 
 
 
 
 
32
 
33
  def generate_tweet(party, prompt):
34
  device = torch.device("cpu")
@@ -59,7 +74,7 @@ def get_base64_image(image_path):
59
 
60
  def main():
61
  st.title("Tweet GPT")
62
- st.sidebar.header("**Analyzing Rhetorical Styles of German Political Parties**")
63
  st.sidebar.write("This project analyzes rhetorical differences among major German parties by generating tweets tailored to their communication styles. Our motivation was to understand the nuances in language and messaging strategies, particularly the effective use of social media by right-wing parties to disseminate messages. We aimed to raise awareness of this issue and contribute to a better understanding of varying rhetorical approaches.")
64
  st.sidebar.markdown("#### Motivation")
65
  st.sidebar.markdown("- Understand language and messaging nuances")
@@ -67,6 +82,12 @@ def main():
67
  st.sidebar.markdown("- Provide insights into crafting messages for supporters")
68
  st.sidebar.markdown("- Raise awareness of right-wing parties' social media use")
69
  st.sidebar.write("Reference: https://www.zdf.de/nachrichten/politik/deutschland/afd-tiktok-erfolg-strategie-jugendliche-100.html")
 
 
 
 
 
 
70
 
71
  tweet = ""
72
  prompt = ""
@@ -91,16 +112,16 @@ def main():
91
  current_date = datetime.now().strftime("%B %d, %Y")
92
  blue_check_base64 = get_base64_image(picture_paths['blue_check'])
93
  party_logo_base64 = get_base64_image(picture_paths[party])
94
- party, username = party_info[party]
95
 
96
  if tweet:
97
  tweet_display = f'''
98
  <div style="background-color: white; padding: 10px; font-family: Helvetica Neue, sans-serif; border: 1px solid #ccc; color: black; border-radius: 10px;">
99
  <div style="display: flex; align-items: center;">
100
- <img src="data:image/png;base64,{party_logo_base64}" alt="{party} Logo" style="width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;">
101
  <div style="display: flex; align-items: center;">
102
  <div style="display: flex; align-items: center; margin-right: 5px;">
103
- <p style="font-weight: bold; color: black;">{party}<img src="data:image/png;base64,{blue_check_base64}" alt="checkmark" style="width: 20px; height: 20px; vertical-align: middle; margin-left: 2px; margin-right: 2px;"><span style="font-weight: normal; color: gray;"> {username}</span> <span style="font-weight: normal; color: gray;">{current_date}</span></p>
104
  </div>
105
  </div>
106
  </div>
@@ -109,9 +130,35 @@ def main():
109
  '''
110
  st.markdown(tweet_display, unsafe_allow_html=True)
111
 
112
- st.write("## Our Insights")
113
- st.write("We developed a tweet generator that analyzes the dataset for each party. To view the insights, select the button to see the most common topics each party wrote about.")
114
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  if __name__ == "__main__":
 
117
  main()
 
3
  from transformers import GPT2Tokenizer, GPT2LMHeadModel
4
  import base64
5
  from datetime import datetime
6
+ import streamlit.components.v1 as components
7
 
8
 
9
  party_dict = {
10
+ 'AfD': './afd_gpt2',
11
+ 'Die Grünen': './gruene_gpt2',
12
+ 'CDU/CSU': './cdu_csu_gpt2',
13
+ 'die Linke': './linke_gpt2',
14
  }
15
 
16
  picture_paths = {
17
+ 'blue_check': "./app_pictures//Twitter_Verified_Badge.png",
18
+ 'AfD': "./app_pictures//afd_logo.png",
19
+ 'CDU/CSU': "./app_pictures//cdu_logo.png",
20
+ 'Die Grünen': "./app_pictures//gruene_logo.png",
21
+ 'die Linke': "./app_pictures//linke_logo.png"
22
  }
23
 
24
  party_info = {
 
28
  "die Linke": ("Die Linke", "@dieLinke")
29
  }
30
 
31
+ topic_analysis_screenshots = {
32
+ 'AfD': './topic_analysis//afd_topic_analysis.png',
33
+ 'CDU/CSU': './topic_analysis//cdu_csu_topic_analysis.png',
34
+ 'Die Grünen': './topic_analysis//gruene_topic_analysis.png',
35
+ 'die Linke': './topic_analysis//linke_topic_analysis.png'
36
+ }
37
 
38
+ def initialize_session_state():
39
+ if 'show_afd' not in st.session_state:
40
+ st.session_state['show_afd'] = False
41
+ if 'show_cdu_csu' not in st.session_state:
42
+ st.session_state['show_cdu_csu'] = False
43
+ if 'show_gruene' not in st.session_state:
44
+ st.session_state['show_gruene'] = False
45
+ if 'show_linke' not in st.session_state:
46
+ st.session_state['show_linke'] = False
47
 
48
  def generate_tweet(party, prompt):
49
  device = torch.device("cpu")
 
74
 
75
  def main():
76
  st.title("Tweet GPT")
77
+ st.sidebar.header("Analyzing Rhetorical Styles of German Political Parties")
78
  st.sidebar.write("This project analyzes rhetorical differences among major German parties by generating tweets tailored to their communication styles. Our motivation was to understand the nuances in language and messaging strategies, particularly the effective use of social media by right-wing parties to disseminate messages. We aimed to raise awareness of this issue and contribute to a better understanding of varying rhetorical approaches.")
79
  st.sidebar.markdown("#### Motivation")
80
  st.sidebar.markdown("- Understand language and messaging nuances")
 
82
  st.sidebar.markdown("- Provide insights into crafting messages for supporters")
83
  st.sidebar.markdown("- Raise awareness of right-wing parties' social media use")
84
  st.sidebar.write("Reference: https://www.zdf.de/nachrichten/politik/deutschland/afd-tiktok-erfolg-strategie-jugendliche-100.html")
85
+ st.sidebar.write("")
86
+ st.sidebar.write("")
87
+ st.sidebar.write("## W&B Training Evaluation Report")
88
+ st.sidebar.markdown("The W&B reports provide a detailed assessment of our Tweet Generator's training process. They include various metrics and visualizations to analyze model performance, track its progress over time, and identify any weaknesses. ")
89
+ with st.sidebar.expander("W&B Training Evaluation Report"):
90
+ components.iframe("https://wandb.ai/ifisch/Tweet_Gen_v2_GPT2/reports/TweetGPT-Training-Evaluation-Process--Vmlldzo4MTU1NjU2?accessToken=4qiq23z5xycyyylaass0xge959em11ldry0deqqp6cr53ugqujfsh3xrzb1r8lsq", height=600, scrolling=True)
91
 
92
  tweet = ""
93
  prompt = ""
 
112
  current_date = datetime.now().strftime("%B %d, %Y")
113
  blue_check_base64 = get_base64_image(picture_paths['blue_check'])
114
  party_logo_base64 = get_base64_image(picture_paths[party])
115
+ party_name, username = party_info[party]
116
 
117
  if tweet:
118
  tweet_display = f'''
119
  <div style="background-color: white; padding: 10px; font-family: Helvetica Neue, sans-serif; border: 1px solid #ccc; color: black; border-radius: 10px;">
120
  <div style="display: flex; align-items: center;">
121
+ <img src="data:image/png;base64,{party_logo_base64}" alt="{party_name} Logo" style="width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;">
122
  <div style="display: flex; align-items: center;">
123
  <div style="display: flex; align-items: center; margin-right: 5px;">
124
+ <p style="font-weight: bold; color: black;">{party_name}<img src="data:image/png;base64,{blue_check_base64}" alt="checkmark" style="width: 20px; height: 20px; vertical-align: middle; margin-left: 2px; margin-right: 2px;"><span style="font-weight: normal; color: gray;"> {username}</span> <span style="font-weight: normal; color: gray;">{current_date}</span></p>
125
  </div>
126
  </div>
127
  </div>
 
130
  '''
131
  st.markdown(tweet_display, unsafe_allow_html=True)
132
 
133
+ st.write("## Our Insights")
134
+ st.write("We developed a tweet generator that analyzes the dataset for each party. To view the insights, select the button to see the most common topics each party wrote about.")
135
+
136
+
137
+
138
+
139
+
140
+ col1, col2, col3, col4 = st.columns(4)
141
+
142
+ if col1.button("Die AfD Topic Analysis" ):
143
+ st.session_state['show_afd'] = not st.session_state['show_afd']
144
+ if col2.button("CDU/CSU Topic Analysis"):
145
+ st.session_state['show_cdu_csu'] = not st.session_state['show_cdu_csu']
146
+ if col3.button("Die Grünen Topic Analysis"):
147
+ st.session_state['show_gruene'] = not st.session_state['show_gruene']
148
+ if col4.button("Die Linke Topic Analysis"):
149
+ st.session_state['show_linke'] = not st.session_state['show_linke']
150
+
151
+
152
+ if st.session_state['show_afd']:
153
+ st.image(topic_analysis_screenshots['AfD'], caption='AfD Topic Analysis')
154
+ if st.session_state['show_cdu_csu']:
155
+ st.image(topic_analysis_screenshots['CDU/CSU'], caption='CDU/CSU Topic Analysis')
156
+ if st.session_state['show_gruene']:
157
+ st.image(topic_analysis_screenshots['Die Grünen'], caption='Die Grünen Topic Analysis')
158
+ if st.session_state['show_linke']:
159
+ st.image(topic_analysis_screenshots['die Linke'], caption='die Linke Topic Analysis')
160
+
161
 
162
  if __name__ == "__main__":
163
+ initialize_session_state()
164
  main()