ezequiellopez commited on
Commit
3b86501
1 Parent(s): 95871f8

working version v1

Browse files
.env CHANGED
@@ -1,2 +1,3 @@
1
  REDIS_PORT=6379
2
- FASTAPI_PORT=7860
 
 
1
  REDIS_PORT=6379
2
+ FASTAPI_PORT=7860
3
+ REDIS_PASSWORD=""
app/data/boost_bank.csv ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ id,boost,target_topic,url_x,url_reddit,url_reddit_new,url_facebook,text,link_to_url,optional_image
2
+ 1,dont feed the trolls (critical ignoring),politics,https://twitter.com/boostingbank/status/1778379092653449713,https://www.reddit.com/user/boostingbank/comments/1c2c5t8/do_not_feed_the_troll/,https://www.reddit.com/user/expatincph/comments/1c4omw0/dont_feed_the_troll/,https://www.facebook.com/photo?fbid=122093041880287784&set=pb.61558633520114.-2207520000,"Do you know this guy? Thats a troll, he's just messing with you. Ignore him.
3
+
4
+ Here's why you shouldn't engage with trolls online: https://theconversation.com/dont-feed-the-trolls-really-is-good-advice-heres-the-evidence-63657
5
+
6
+ #ScienceofBoosting",https://theconversation.com/dont-feed-the-trolls-really-is-good-advice-heres-the-evidence-63657,https://drive.google.com/file/d/1FR3-e0_OXqGEl02mzI-fR_F9RegJQqs6/view?usp=share_link
7
+ 2,dont feed the trolls (critical ignoring),news,https://twitter.com/boostingbank/status/1778379092653449713,https://www.reddit.com/user/boostingbank/comments/1c2c5t8/do_not_feed_the_troll/,https://www.reddit.com/user/expatincph/comments/1c4omw0/dont_feed_the_troll/,https://www.facebook.com/photo?fbid=122093041880287784&set=pb.61558633520114.-2207520000,"Do you know this guy? 👹 That's a troll, he's just messing with you. Ignore him.
8
+
9
+ Here's why you shouldn't engage with trolls online: https://theconversation.com/dont-feed-the-trolls-really-is-good-advice-heres-the-evidence-63657
10
+
11
+ #ScienceofBoosting",https://theconversation.com/dont-feed-the-trolls-really-is-good-advice-heres-the-evidence-63657,https://drive.google.com/file/d/1FR3-e0_OXqGEl02mzI-fR_F9RegJQqs6/view?usp=share_link
12
+ 3,dont feed the trolls (critical ignoring),health,https://twitter.com/boostingbank/status/1778379092653449713,https://www.reddit.com/user/boostingbank/comments/1c2c5t8/do_not_feed_the_troll/,https://www.reddit.com/user/expatincph/comments/1c4omw0/dont_feed_the_troll/,https://www.facebook.com/photo?fbid=122093041880287784&set=pb.61558633520114.-2207520000,"Do you know this guy? Thats a troll, he's just messing with you. Ignore him.
13
+
14
+ Here's why you shouldn't engage with trolls online: https://theconversation.com/dont-feed-the-trolls-really-is-good-advice-heres-the-evidence-63657
15
+
16
+ #ScienceofBoosting",https://theconversation.com/dont-feed-the-trolls-really-is-good-advice-heres-the-evidence-63657,https://drive.google.com/file/d/1FR3-e0_OXqGEl02mzI-fR_F9RegJQqs6/view?usp=share_link
17
+ 4,general self-nudging (critical ignoring),politics,https://twitter.com/boostingbank/status/1778379451409047816,https://www.reddit.com/user/boostingbank/comments/1c2c9q6/selfnudging/,,https://www.facebook.com/photo?fbid=122093044130287784&set=a.122093041910287784,"Overwhelmed by all the political news theses days?
18
+
19
+ Learn to manage your news diet with this science-backed trick: self-nudging
20
+
21
+ https://scienceofboosting.org/project/self-nudging/
22
+
23
+ #ScienceofBoosting #CitizenChoiceArchitect",https://scienceofboosting.org/project/self-nudging/ ,https://drive.google.com/file/d/1rFQHzywbulNQ6qijyZ_uwzflj7k5luNe/view?usp=share_link
24
+ 5,general self-nudging (critical ignoring),news,https://twitter.com/boostingbank/status/1778751262613258682,https://www.reddit.com/user/boostingbank/comments/1c2c9q6/selfnudging/,https://www.reddit.com/user/expatincph/comments/1c4opy8/too_much_news_learn_to_block_out_unwanted/,,"Sometimes it feels like there's just too much news these days...
25
+
26
+ Learn to block out unwanted distractions with this science-backed trick: self-nudging
27
+
28
+ https://scienceofboosting.org/project/self-nudging/
29
+
30
+ #ScienceofBoosting #CitizenChoiceArchitect",https://scienceofboosting.org/project/self-nudging/ ,https://drive.google.com/file/d/1rFQHzywbulNQ6qijyZ_uwzflj7k5luNe/view?usp=share_link
31
+ 6,general self-nudging (critical ignoring),health,https://twitter.com/boostingbank/status/1778676445016993889,https://www.reddit.com/user/boostingbank/comments/1c2c9q6/selfnudging/,,,"Sick of all these people telling you what's good for you?
32
+
33
+ Learn to block out unwanted distractions with self-nudging.
34
+
35
+ https://scienceofboosting.org/project/self-nudging/
36
+
37
+ #ScienceofBoosting #CitizenChoiceArchitect",https://scienceofboosting.org/project/self-nudging/ ,https://drive.google.com/file/d/1rFQHzywbulNQ6qijyZ_uwzflj7k5luNe/view?usp=share_link
38
+ 7,lateral reading,politics,https://twitter.com/boostingbank/status/1778692955227697254,https://www.reddit.com/user/boostingbank/comments/1c2cco9/learn_how_to_fact_check_like_a_true_professional/,,https://www.facebook.com/photo?fbid=122093044448287784&set=a.122093041910287784,"It can be hard to know who to take seriously.
39
+
40
+ Practice lateral reading and evaluate information like a media professional
41
+
42
+ #ScienceofBoosting
43
+
44
+ https://cor.inquirygroup.org",https://cor.inquirygroup.org,https://drive.google.com/file/d/12cSw-71cX8JxG73YaCKF5IV_H3KOM5x0/view?usp=share_link
45
+ 8,lateral reading,news,https://twitter.com/boostingbank/status/1778032947091623987,https://www.reddit.com/user/boostingbank/comments/1c2cco9/learn_how_to_fact_check_like_a_true_professional/,,,"Does something seem too good or too weird to be true? Maybe it is!
46
+
47
+ Practice lateral reading and evaluate information like a media professional
48
+
49
+ #ScienceofBoosting
50
+
51
+ https://cor.inquirygroup.org",https://cor.inquirygroup.org,https://drive.google.com/file/d/12cSw-71cX8JxG73YaCKF5IV_H3KOM5x0/view?usp=share_link
52
+ 9,lateral reading,health,https://twitter.com/boostingbank/status/1778757338100367788,https://www.reddit.com/user/boostingbank/comments/1c2cco9/learn_how_to_fact_check_like_a_true_professional/,https://www.reddit.com/user/expatincph/comments/1c4or42/practice_lateral_reading_and_evaluate_information/,,"It seems like everyone's a doctor these days...
53
+
54
+ Practice lateral reading and evaluate information like a media professional
55
+
56
+ #ScienceofBoosting
57
+
58
+ https://cor.inquirygroup.org",https://cor.inquirygroup.org,https://drive.google.com/file/d/12cSw-71cX8JxG73YaCKF5IV_H3KOM5x0/view?usp=share_link
59
+ 10,media literacy tips,politics,https://twitter.com/boostingbank/status/1778677000120553942,https://www.reddit.com/user/boostingbank/comments/1c2cdbk/consider_these_tips_for_thinking_critically_about/,,https://www.facebook.com/photo?fbid=122093044532287784&set=a.122093041910287784,"Social media makes it easy to mislead.
60
+
61
+ Consider these tips for thinking critically about media online.
62
+
63
+ #ScienceofBoosting",,https://drive.google.com/file/d/1UZ47RJ3BcjNI9QDkDpAZZLm7YV8_uzK1/view?usp=share_link
64
+ 11,media literacy tips,news,https://twitter.com/boostingbank/status/1778047026153820206,https://www.reddit.com/user/boostingbank/comments/1c2cdbk/consider_these_tips_for_thinking_critically_about/,,,"Not all news is created equal
65
+
66
+ Consider these tips for thinking critically about media online.
67
+
68
+ #ScienceofBoosting",,https://drive.google.com/file/d/1UZ47RJ3BcjNI9QDkDpAZZLm7YV8_uzK1/view?usp=share_link
69
+ 12,media literacy tips,health,https://twitter.com/boostingbank/status/1778782653598117967,https://www.reddit.com/user/boostingbank/comments/1c2cdbk/consider_these_tips_for_thinking_critically_about/,,,"Health news is everywhere... how do you decide what to trust?
70
+
71
+ Consider these tips for thinking critically about media online.
72
+
73
+ #ScienceofBoosting",,https://drive.google.com/file/d/1UZ47RJ3BcjNI9QDkDpAZZLm7YV8_uzK1/view?usp=share_link
74
+ 13,bad news game (inoculation),politics,https://twitter.com/boostingbank/status/1778380229192433857,https://www.reddit.com/user/boostingbank/comments/1c2ce4s/are_you_a_target_of_political_manipulation/,,https://www.facebook.com/photo?fbid=122093044814287784&set=a.122093041910287784,"Are you a target of political manipulation?
75
+
76
+ Play the Bad News game and learn about common tactics used on social media to mislead you!
77
+
78
+ https://getbadnews.com/en/
79
+
80
+ #ScienceofBoosting",https://www.getbadnews.com/en,https://drive.google.com/file/d/1vLTZL1LFkASrNKZMpC7YK91djsuZmJCH/view?usp=share_link
81
+ 14,bad news game (inoculation),news,https://twitter.com/boostingbank/status/1778704085971010038,https://www.reddit.com/user/boostingbank/comments/1c2ce4s/are_you_a_target_of_political_manipulation/,https://www.reddit.com/user/expatincph/comments/1c4otmo/can_you_spot_fake_news_are_you_immune_to/,,"Can you spot fake news? Are you immune to manipulation?
82
+
83
+ Play the Bad News game and learn about common manipulation tactics used on social media!
84
+
85
+ https://getbadnews.com/en/
86
+
87
+ #ScienceofBoosting",https://www.getbadnews.com/en,https://drive.google.com/file/d/1vLTZL1LFkASrNKZMpC7YK91djsuZmJCH/view?usp=share_link
88
+ 15,harmony square game (inoculation),politics,https://twitter.com/boostingbank/status/1778380881847017708,https://www.reddit.com/user/boostingbank/comments/1c2chqx/want_to_build_up_your_psychological_defenses/,,https://www.facebook.com/photo?fbid=122093045432287784&set=a.122093041910287784,"Want to build up your psychological defenses against misinformation?
89
+
90
+ Harmony Square is a game that exposes the manipulation techniques that are used to mislead people online. Try it out!
91
+
92
+ https://harmonysquare.game/en
93
+
94
+ #ScienceofBoosting",https://harmonysquare.game,https://drive.google.com/file/d/1ANRR-CcdRL4f_zDqWi2S9TjcNY-iyjSg/view?usp=share_link
95
+ 16,harmony square game (inoculation),news,https://twitter.com/boostingbank/status/1778380881847017708,https://www.reddit.com/user/boostingbank/comments/1c2chqx/want_to_build_up_your_psychological_defenses/,,,"Want to build up your psychological defenses against misinformation?
96
+
97
+ Harmony Square is a game that exposes the manipulation techniques that are used to mislead people online. Try it out!
98
+
99
+ https://harmonysquare.game/en
100
+
101
+ #ScienceofBoosting",https://harmonysquare.game,https://drive.google.com/file/d/1ANRR-CcdRL4f_zDqWi2S9TjcNY-iyjSg/view?usp=share_link
102
+ 17,cranky uncle game (inoculation),politics,https://twitter.com/boostingbank/status/1778388428872147179,https://www.reddit.com/user/boostingbank/comments/1c2cibq/tired_of_debating_your_cranky_uncle_about/,,https://www.facebook.com/photo?fbid=122093045810287784&set=a.122093041910287784,"Tired of debating your cranky uncle about politics at the family get-together?
103
+
104
+ Try out this game to learn about his questionable debate tactics: https://app.crankyuncle.info/home
105
+
106
+ #ScienceofBoosting",https://crankyuncle.com/game/,https://drive.google.com/file/d/18nAPeKUnCpLWbDHiVh3W84jX8lmCL3yD/view?usp=share_link
107
+ 18,cranky uncle game (inoculation),news,https://twitter.com/boostingbank/status/1778788952956170381,https://www.reddit.com/user/boostingbank/comments/1c2cibq/tired_of_debating_your_cranky_uncle_about/,,,"Tired of debating your cranky uncle about the news at the family get-together?
108
+
109
+ Try out this game to learn about his questionable debate tactics: https://app.crankyuncle.info/home
110
+
111
+ #ScienceofBoosting",https://crankyuncle.com/game/,https://drive.google.com/file/d/18nAPeKUnCpLWbDHiVh3W84jX8lmCL3yD/view?usp=share_link
112
+ 19,cranky uncle game (inoculation),health,https://twitter.com/boostingbank/status/1778693821154402650,https://www.reddit.com/user/boostingbank/comments/1c2cibq/tired_of_debating_your_cranky_uncle_about/,,,"Tired of debating your cranky uncle about his COVID theory at the family get-together?
113
+
114
+ Try out this game to learn about his questionable debate tactics: https://app.crankyuncle.info/home
115
+
116
+ #ScienceofBoosting",https://crankyuncle.com/game/,https://drive.google.com/file/d/18nAPeKUnCpLWbDHiVh3W84jX8lmCL3yD/view?usp=share_link
117
+ 20,fast-and-frugal trees for info verification,politics,https://twitter.com/boostingbank/status/1778381396211298567,https://www.reddit.com/user/boostingbank/comments/1c2cjd0/is_spotting_fake_news_as_easy_as_123/,https://www.reddit.com/user/expatincph/comments/1c4osh7/is_spotting_fake_news_as_easy_as_123/,https://www.facebook.com/photo?fbid=122093046020287784&set=a.122093041910287784,"Is spotting fake news as easy as 1-2-3?
118
+
119
+ Try out these simple rules for deciding who to trust online.
120
+
121
+ https://www.scienceofboosting.org/project/decision-trees/
122
+
123
+ #ScienceofBoosting
124
+ ",https://www.scienceofboosting.org/project/decision-trees/,https://drive.google.com/file/d/1pRP08z6ZmWbpXf7OQ6PehAHSvziAmSGz/view?usp=share_link
125
+ 21,fast-and-frugal trees for info verification,news,https://twitter.com/boostingbank/status/1778381396211298567,https://www.reddit.com/user/boostingbank/comments/1c2cjd0/is_spotting_fake_news_as_easy_as_123/,,,"Is spotting fake news as easy as 1-2-3?
126
+
127
+ Try out these simple rules for deciding who to trust online.
128
+
129
+ https://www.scienceofboosting.org/project/decision-trees/
130
+
131
+ #ScienceofBoosting
132
+ ",https://www.scienceofboosting.org/project/decision-trees/,https://drive.google.com/file/d/1pRP08z6ZmWbpXf7OQ6PehAHSvziAmSGz/view?usp=share_link
133
+ 22,fast-and-frugal trees for info verification,health,https://twitter.com/boostingbank/status/1778751823500706258,https://www.reddit.com/user/boostingbank/comments/1c2cjd0/is_spotting_fake_news_as_easy_as_123/,,,"Will the real experts please stand up?
134
+
135
+ Try out these simple rules for deciding who to trust online.
136
+
137
+ https://www.scienceofboosting.org/project/decision-trees/
138
+
139
+ #ScienceofBoosting",https://www.scienceofboosting.org/project/decision-trees/,https://drive.google.com/file/d/1pRP08z6ZmWbpXf7OQ6PehAHSvziAmSGz/view?usp=share_link
140
+ 23,emotional language (inoculation),politics,https://twitter.com/boostingbank/status/1778388918028636670,https://www.reddit.com/user/boostingbank/comments/1c2ck2p/tip_1_be_aware_of_emotional_language/,,https://www.facebook.com/photo?fbid=122093046224287784&set=a.122093041910287784,"Learn to recognize bad political arguments!
141
+
142
+ Tip #1: Be aware of emotional language
143
+
144
+ Learn more: https://www.youtube.com/watch?v=ER64qa_qnWg
145
+
146
+ #ScienceofBoosting",https://www.youtube.com/watch?v=ER64qa_qnWg,https://drive.google.com/file/d/135rv4bBRLznjSL8DS95besgaxS4AF7xa/view?usp=share_link
147
+ 24,emotional language (inoculation),news,https://twitter.com/boostingbank/status/1778782095046758757,https://www.reddit.com/user/boostingbank/comments/1c2ck2p/tip_1_be_aware_of_emotional_language/,,,"Learn to recognize misleading news!
148
+
149
+ Tip #1: Be aware of emotional language
150
+
151
+ Learn more: https://www.youtube.com/watch?v=ER64qa_qnWg
152
+
153
+ #ScienceofBoosting",https://www.youtube.com/watch?v=ER64qa_qnWg,https://drive.google.com/file/d/135rv4bBRLznjSL8DS95besgaxS4AF7xa/view?usp=share_link
154
+ 25,emotional language (inoculation),health,https://twitter.com/boostingbank/status/1779429403606364620,https://www.reddit.com/user/boostingbank/comments/1c2ck2p/tip_1_be_aware_of_emotional_language/,,,"Learn to recognize bad medical advice!
155
+
156
+ Tip #1: Be aware of emotional language
157
+
158
+ Learn more: https://www.youtube.com/watch?v=ER64qa_qnWg
159
+
160
+ #ScienceofBoosting",https://www.youtube.com/watch?v=ER64qa_qnWg,https://drive.google.com/file/d/135rv4bBRLznjSL8DS95besgaxS4AF7xa/view?usp=share_link
161
+ 26,ad hominem (inoculation),politics,https://twitter.com/boostingbank/status/1778394806802063773,https://www.reddit.com/user/boostingbank/comments/1c2cm49/tip_5_look_out_for_ad_hominem_attacks/,,https://www.facebook.com/photo?fbid=122093046626287784&set=a.122093041910287784,"Learn to recognize bad political arguments!
162
+
163
+ Tip #5: Look out for ad hominem attacks
164
+
165
+ Learn more: https://inoculation.science/inoculation-videos/ad-hominem-attack/
166
+
167
+
168
+ #ScienceofBoosting",https://inoculation.science/inoculation-videos/ad-hominem-attack/,https://drive.google.com/file/d/1QkHX8837Y9VfjVOQJTxWvoAtcW9UxpDD/view?usp=share_link
169
+ 27,ad hominem (inoculation),news,https://twitter.com/boostingbank/status/1779760371454087399,https://www.reddit.com/user/boostingbank/comments/1c2cm49/tip_5_look_out_for_ad_hominem_attacks/,,,"Learn to recognize misleading news!
170
+
171
+ Tip #5: Look out for ad hominem attacks
172
+
173
+ Learn more: https://inoculation.science/inoculation-videos/ad-hominem-attack/
174
+
175
+ #ScienceofBoosting",https://inoculation.science/inoculation-videos/ad-hominem-attack/,https://drive.google.com/file/d/1QkHX8837Y9VfjVOQJTxWvoAtcW9UxpDD/view?usp=share_link
176
+ 28,ad hominem (inoculation),health,https://twitter.com/boostingbank/status/1778720055452119173,https://www.reddit.com/user/boostingbank/comments/1c2cm49/tip_5_look_out_for_ad_hominem_attacks/,,,"Learn to recognize bad arguments about health and science!
177
+
178
+ Tip #5: Look out for ad hominem attacks
179
+
180
+ Learn more: https://inoculation.science/inoculation-videos/ad-hominem-attack/
181
+
182
+
183
+ #ScienceofBoosting",https://inoculation.science/inoculation-videos/ad-hominem-attack/,https://drive.google.com/file/d/1QkHX8837Y9VfjVOQJTxWvoAtcW9UxpDD/view?usp=share_link
184
+ 29,false dichotomies (inoculation),politics,https://twitter.com/boostingbank/status/1778783215022375108,https://www.reddit.com/user/boostingbank/comments/1c2cmu2/tip_3_dont_fall_for_a_false_dichotomy/,,https://www.facebook.com/photo?fbid=122093046836287784&set=a.122093041910287784,"Learn to recognize bad political arguments!
185
+
186
+ Tip #3: Don't fall for a false dichotomy
187
+
188
+ Learn more: https://inoculation.science/inoculation-videos/false-dichotomy/
189
+
190
+
191
+ #ScienceofBoosting",https://inoculation.science/inoculation-videos/false-dichotomy/,https://drive.google.com/file/d/1giM-EnLdHj76msV6_v7eNW6zLpCMrRfY/view?usp=share_link
192
+ 30,false dichotomies (inoculation),news,https://twitter.com/boostingbank/status/1778449606285672508,https://www.reddit.com/user/boostingbank/comments/1c2cmu2/tip_3_dont_fall_for_a_false_dichotomy/,,,"Learn to recognize misleading news!
193
+
194
+ Tip #3: Don't fall for a false dichotomy
195
+
196
+ Learn more: https://inoculation.science/inoculation-videos/false-dichotomy/
197
+
198
+
199
+ #ScienceofBoosting",https://inoculation.science/inoculation-videos/false-dichotomy/,https://drive.google.com/file/d/1giM-EnLdHj76msV6_v7eNW6zLpCMrRfY/view?usp=share_link
200
+ 31,false dichotomies (inoculation),health,https://twitter.com/boostingbank/status/1779760719078019184,https://www.reddit.com/user/boostingbank/comments/1c2cmu2/tip_3_dont_fall_for_a_false_dichotomy/,,,"Learn to recognize bad medical advice!
201
+
202
+ Tip #3: Don't fall for a false dichotomy
203
+
204
+ Learn more: https://inoculation.science/inoculation-videos/false-dichotomy/
205
+
206
+
207
+ #ScienceofBoosting",https://inoculation.science/inoculation-videos/false-dichotomy/,https://drive.google.com/file/d/1giM-EnLdHj76msV6_v7eNW6zLpCMrRfY/view?usp=share_link
208
+ 32,scapegoating (inoculation),politics,https://twitter.com/boostingbank/status/1778704788437319869,https://www.reddit.com/user/boostingbank/comments/1c2cnf0/tip_4_recognize_scapegoating/,,https://www.facebook.com/photo?fbid=122093047184287784&set=a.122093041910287784,"Learn to spot bad political arguments!
209
+
210
+ Tip #4: Recognize scapegoating
211
+
212
+ Learn more: https://inoculation.science/inoculation-videos/scapegoating/
213
+
214
+
215
+ #ScienceofBoosting",https://inoculation.science/inoculation-videos/scapegoating/,https://drive.google.com/file/d/10uXRbiHKOl3t7PnXo_P10oRua0XpA0vw/view?usp=share_link
216
+ 33,scapegoating (inoculation),news,https://twitter.com/boostingbank/status/1779429712990785623,https://www.reddit.com/user/boostingbank/comments/1c2cnf0/tip_4_recognize_scapegoating/,,,"Learn to spot misleading news!
217
+
218
+ Tip #4: Recognize scapegoating
219
+
220
+ Learn more: https://inoculation.science/inoculation-videos/scapegoating/
221
+
222
+ #ScienceofBoosting",https://inoculation.science/inoculation-videos/scapegoating/,https://drive.google.com/file/d/10uXRbiHKOl3t7PnXo_P10oRua0XpA0vw/view?usp=share_link
223
+ 34,jaqing off (inoculation),politics,https://twitter.com/boostingbank/status/1778382614606291195,https://www.reddit.com/user/boostingbank/comments/1c2co0p/is_that_really_a_question_or_an_excuse_to_make_a/,,https://www.facebook.com/photo?fbid=122093047298287784&set=a.122093041910287784,"Is that really a question? Or an excuse to make a controversial statement?
224
+
225
+ Next time someone doubts some political news, ask yourself: Is this person JAQing off? (""just asking questions"")
226
+
227
+ https://en.wiktionary.org/wiki/JAQ_off",https://en.wiktionary.org/wiki/JAQ_off,https://drive.google.com/file/d/1plCzqH76Jk6plJpXwCo3XEZygAP_yJEz/view?usp=share_link
228
+ 35,jaqing off (inoculation),news,https://twitter.com/boostingbank/status/1778789520504217835,https://www.reddit.com/user/boostingbank/comments/1c2co0p/is_that_really_a_question_or_an_excuse_to_make_a/,,,"Is that really a question? Or an excuse to make a controversial statement?
229
+
230
+ Next time someone doubts what you saw on the news, ask yourself: Is this person JAQing off? (""just asking questions"")
231
+
232
+ https://en.wiktionary.org/wiki/JAQ_off",https://en.wiktionary.org/wiki/JAQ_off,https://drive.google.com/file/d/1plCzqH76Jk6plJpXwCo3XEZygAP_yJEz/view?usp=share_link
233
+ 36,jaqing off (inoculation),health,https://twitter.com/boostingbank/status/1778694714910179506,https://www.reddit.com/user/boostingbank/comments/1c2co0p/is_that_really_a_question_or_an_excuse_to_make_a/,,,"Is that really a question? Or an excuse to make a controversial statement?
234
+
235
+ Next time someone doubts accepted medical advice, ask yourself: Is this person JAQing off? (""just asking questions"")
236
+
237
+ https://en.wiktionary.org/wiki/JAQ_off",https://en.wiktionary.org/wiki/JAQ_off,https://drive.google.com/file/d/1plCzqH76Jk6plJpXwCo3XEZygAP_yJEz/view?usp=share_link
238
+ 37,one sec app (self-nudging),politics,https://twitter.com/boostingbank/status/1778389956492243301,https://www.reddit.com/user/boostingbank/comments/1c2cplb/aaaaaaaand_breathe_out_all_the_news_these_days/,,https://www.facebook.com/photo?fbid=122093047400287784&set=a.122093041910287784,"Aaaaaaaand breathe out 🧘‍♂️
239
+
240
+ All the politics these days can be overwhelming. Sometimes, we just need to take a break.
241
+
242
+ Check out https://one-sec.app to stop the doomscrolling and take control of your own time.
243
+
244
+ #ScienceofBoosting",https://one-sec.app,https://drive.google.com/file/d/17p8FyhDqF-KfSJ78IRzDG52HqTpUys8k/view?usp=share_link
245
+ 38,one sec app (self-nudging),news,https://twitter.com/boostingbank/status/1778719328843575437,https://www.reddit.com/user/boostingbank/comments/1c2cplb/aaaaaaaand_breathe_out_all_the_news_these_days/,,,"Aaaaaaaand breathe out 🧘‍♂️
246
+
247
+ All the news these days can be overwhelming. Sometimes, we just need to take a break.
248
+
249
+ Check out https://one-sec.app to stop the doomscrolling and take control of your own time.
250
+
251
+ #ScienceofBoosting",https://one-sec.app,https://drive.google.com/file/d/17p8FyhDqF-KfSJ78IRzDG52HqTpUys8k/view?usp=share_link
252
+ 39,deepfake cues,politics,https://twitter.com/boostingbank/status/1778390860331139553,https://www.reddit.com/user/boostingbank/comments/1c2cqav/you_would_never_fall_for_a_deepfake_would_you/,,https://www.facebook.com/photo?fbid=122093047664287784&set=a.122093041910287784,"You would never fall for a deepfake... would you?
253
+
254
+ Check out these tips for spotting deepfakes: https://www.snopes.com/articles/423004/how-to-spot-a-deepfake/",https://www.snopes.com/articles/423004/how-to-spot-a-deepfake/,https://drive.google.com/file/d/1wiuVFiwa-Dc6i3J3pmissgvP5tI6CEMY/view?usp=share_link
255
+ 40,deepfake cues,news,https://twitter.com/boostingbank/status/1778390860331139554 ,https://www.reddit.com/user/boostingbank/comments/1c2cqav/you_would_never_fall_for_a_deepfake_would_you/,,,"You would never fall for a deepfake... would you?
256
+
257
+ Check out these tips for spotting deepfakes: https://www.snopes.com/articles/423004/how-to-spot-a-deepfake/",https://www.snopes.com/articles/423004/how-to-spot-a-deepfake/,https://drive.google.com/file/d/1wiuVFiwa-Dc6i3J3pmissgvP5tI6CEMY/view?usp=share_link
258
+ 41,AI-generated images,politics,https://twitter.com/boostingbank/status/1778382202830475536,https://www.reddit.com/user/boostingbank/comments/1c2cqt2/have_you_ever_wondered_if_an_image_is_real_or_if/,,https://www.facebook.com/photo?fbid=122093048138287784&set=a.122093041910287784,"Have you ever wondered if an image is real, or if it was generated by AI?
259
+
260
+ Here is how you can learn to tell the difference: https://tech.co/news/ways-detect-ai-images-examples ",https://tech.co/news/ways-detect-ai-images-examples,https://drive.google.com/file/d/1ct77MnVwn_hjmAUsuwKUDT8ED_vFUDeb/view?usp=share_link
261
+ 42,AI-generated images,news,https://twitter.com/boostingbank/status/1778382202830475536,https://www.reddit.com/user/boostingbank/comments/1c2cqt2/have_you_ever_wondered_if_an_image_is_real_or_if/,,,"Have you ever wondered if an image is real, or if it was generated by AI?
262
+
263
+ Here is how you can learn to tell the difference: https://tech.co/news/ways-detect-ai-images-examples ",https://tech.co/news/ways-detect-ai-images-examples,https://drive.google.com/file/d/1ct77MnVwn_hjmAUsuwKUDT8ED_vFUDeb/view?usp=share_link
app/main.py CHANGED
@@ -1,12 +1,14 @@
1
  # Import required libraries
2
  from fastapi import FastAPI, HTTPException
3
- from pydantic import BaseModel
4
- from typing import List
5
  #import redis
6
- from transformers import BartForSequenceClassification, BartTokenizer, AutoTokenizer, AutoConfig, pipeline
7
  from dotenv import load_dotenv
8
  import os
9
 
 
 
 
 
 
10
  # Load environment variables from .env file
11
  load_dotenv('../.env')
12
 
@@ -18,49 +20,10 @@ fastapi_port = os.getenv("FASTAPI_PORT")
18
  print("Redis port:", redis_port)
19
  print("FastAPI port:", fastapi_port)
20
 
21
-
22
- # Initialize FastAPI app and Redis client
23
  app = FastAPI()
24
- #redis_client = redis.Redis(host='redis', port=6379)
25
-
26
- # Load BART model and tokenizer
27
- #model = BartForSequenceClassification.from_pretrained("facebook/bart-large-mnli")
28
- #tokenizer = BartTokenizer.from_pretrained("facebook/bart-large-mnli")
29
-
30
- model = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
31
-
32
- def score_text_with_labels(model, text: list, labels: list, multi: bool=True):
33
- #candidate_labels = ['travel', 'cooking', 'dancing', 'exploration']
34
- results = [result['scores'] for result in model(text, labels, multi_label=multi)]
35
- #return dict(zip(labels, results['scores']))
36
- return results
37
-
38
- def smooth_sequence(tweets_scores, window_size):
39
- # Calculate the sum of scores for both labels for each tweet
40
- tweet_sum_scores = [(sum(scores), index) for index, scores in enumerate(tweets_scores)]
41
- # Sort tweets based on their sum scores, then by their original index to stabilize
42
- sorted_tweets = sorted(tweet_sum_scores, key=lambda x: (x[0], x[1]))
43
- # Extract the original indices of tweets after sorting
44
- sorted_indices = [index for _, index in sorted_tweets]
45
- # Create a new sequence based on sorted indices
46
- smoothed_sequence = [tweets_scores[index] for index in sorted_indices]
47
- return smoothed_sequence
48
-
49
- def rerank_on_label(label: str):
50
- return 200
51
-
52
-
53
- # Define Pydantic models
54
- class Item(BaseModel):
55
- #id: str
56
- #title: str = None
57
- text: str
58
- #type: str
59
- #engagements: dict
60
-
61
- class RerankedItems(BaseModel):
62
- ranked_ids: List[str]
63
- new_items: List[dict]
64
 
65
  # Define a health check endpoint
66
  @app.get("/")
@@ -69,59 +32,74 @@ async def health_check():
69
 
70
  # Define FastAPI routes and logic
71
  @app.post("/rerank/")
72
- async def rerank_items(items: List[Item]) -> RerankedItems:
73
- reranked_ids = []
74
-
75
- # Process each item
76
- for item in items:
77
- # Classify the item using Hugging Face BART model
78
- labels = classify_item(item.text)
79
-
80
- # Save the item with labels in Redis
81
- #redis_client.hset(item.id, mapping={"title": item.title, "text": item.text, "labels": ",".join(labels)})
82
-
83
- # Add the item id to the reranked list
84
- reranked_ids.append(item.id)
85
-
86
- # Sort the items based on model confidence
87
- #reranked_ids.sort(key=lambda x: redis_client.zscore("classified_items", x), reverse=True)
88
-
89
- # Return the reranked items
90
- return {"ranked_ids": reranked_ids, "new_items": []} # Ignore "new_items" for now
91
-
92
- # Define an endpoint to classify items and save them in Redis
93
- @app.post("/classify/")
94
- async def classify_and_save(items: List[Item]) -> None:
95
- print("new 1")
96
- #labels = ["factful", "civic", "constructive", "politics", "health", "news"]
97
- #labels = ["factful", "politics"]
98
- labels = ["something else", "news feed, news articles, breaking news", "politics and polititians", "healthcare and health"]
99
- #labels = ["health", "politics", "news", "non-health non-politics non-news"]
100
- texts = [item.text for item in items]
101
- print(texts)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
- labels = score_text_with_labels(model=model, text=texts, labels=labels, multi=True)
104
- print(labels)
105
- return labels
106
- #for item in items:
107
- # print(item)
108
- # Classify the item using Hugging Face BART model
109
- #labels = classify_item(item.text)
110
- #return score_text_with_labels(model, item.text, labels)
111
- # Save the item with labels in Redis
112
- #redis_client.hset(item.id, mapping={"title": item.title, "text": item.text, "labels": ",".join(labels)})
113
- #return labels
114
- #return None
115
-
116
- # Function to classify item text using Hugging Face BART model
117
- def classify_item(text: str) -> List[str]:
118
- # Tokenize input text
119
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
120
- print(1)
121
- # Perform inference
122
- outputs = model(**inputs)
123
- print(2)
124
- # Get predicted label
125
- predicted_label = tokenizer.decode(outputs.logits.argmax())
126
-
127
- return [predicted_label]
 
 
1
  # Import required libraries
2
  from fastapi import FastAPI, HTTPException
 
 
3
  #import redis
 
4
  from dotenv import load_dotenv
5
  import os
6
 
7
+ from modules.redistribute import redistribute, insert_element_at_position
8
+ from modules.models.api import Input, Output, NewItem, UUID
9
+ from modules.database import BoostDatabase, UserDatabase, User
10
+
11
+
12
  # Load environment variables from .env file
13
  load_dotenv('../.env')
14
 
 
20
  print("Redis port:", redis_port)
21
  print("FastAPI port:", fastapi_port)
22
 
 
 
23
  app = FastAPI()
24
+ boost_db = BoostDatabase('data/boost_bank.csv')
25
+ user_db = UserDatabase()
26
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  # Define a health check endpoint
29
  @app.get("/")
 
32
 
33
  # Define FastAPI routes and logic
34
  @app.post("/rerank/")
35
+ async def rerank_items(input_data: Input) -> Output:
36
+ # who is the user?
37
+ user = input_data.session.user_id
38
+ date = input_data.session.current_time
39
+ platform = input_data.session.platform
40
+ items = input_data.items
41
+ # TODO consider sampling them?
42
+
43
+ print(items)
44
+ reranked_ids, first_topic, insertion_pos = redistribute(items=items)
45
+ #reranked_ids = [ for id_ in reranked_ids]
46
+ print("here!")
47
+ print(reranked_ids)
48
+
49
+ user_in_db = user_db.get_user(user_id=user)
50
+
51
+ # if user already exists -> has boosting records
52
+ if user_in_db:
53
+ # has been boosted today?
54
+ if user_in_db.is_boosted_today():
55
+ # return only reranked items, no insertion
56
+ return Output(reranked_ids=reranked_ids, new_items=[])
57
+ # user exists and not boosted today yet
58
+ else:
59
+ new_items = []
60
+ boosts_received = user_in_db.boosts
61
+ # there was some civic content in the batch
62
+ if first_topic != "non-civic":
63
+ fetched_boost = boost_db.get_random_boost(topic=first_topic,
64
+ platform=platform,
65
+ blacklist_ids=boosts_received)
66
+ user_db.add_boost_to_user(user_id=user, boost=fetched_boost)
67
+ user_db.update_user_boosted_today(user_id=user, date=date)
68
+
69
+ # insert boost before first civic in batch
70
+ reranked_ids = insert_element_at_position(lst=reranked_ids,
71
+ element=UUID(fetched_boost['id']),
72
+ position=insertion_pos)
73
+
74
+ return Output(ranked_ids=reranked_ids, new_items=[NewItem(id=UUID(fetched_boost["id"]), url=fetched_boost["url"])])
75
+
76
+ # no civic content to boost on
77
+ else:
78
+ return Output(ranked_ids=reranked_ids, new_items=[])
79
 
80
+ # user doesn't exist
81
+ else:
82
+ print(first_topic)
83
+ print(platform)
84
+ if first_topic != "non-civic":
85
+ fetched_boost = boost_db.get_random_boost(topic=first_topic,
86
+ platform=platform,
87
+ blacklist_ids=[])
88
+ print(fetched_boost)
89
+ print(type(fetched_boost))
90
+ user_db.add_user(user_id=user,
91
+ user=User(user_id=user, last_boost=date, boosts=[fetched_boost]))
92
+
93
+ # insert boost before first civic in batch
94
+ reranked_ids = insert_element_at_position(lst=reranked_ids,
95
+ element=UUID(fetched_boost['id']),
96
+ position=insertion_pos)
97
+
98
+
99
+ return Output(ranked_ids=reranked_ids, new_items=[NewItem(id=UUID(fetched_boost["id"]), url=fetched_boost["url"])])
100
+
101
+ # no civic content to boost on
102
+ else:
103
+ print("there")
104
+ return Output(ranked_ids=reranked_ids, new_items=[])
105
+
app/modules/__init__.py ADDED
File without changes
app/modules/classify.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import BartForSequenceClassification, BartTokenizer, AutoTokenizer, AutoConfig, pipeline
2
+ from typing import List
3
+
4
+ model = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
5
+
6
+
7
+ label_map = {
8
+ "something else": "non-civic",
9
+ "headlines, news channels, news articles, breaking news": "news",
10
+ "politics, policy and politicians": "politics",
11
+ "health are and public health": "health",
12
+ "religious": "news" # CONSCIOUS DECISION
13
+ }
14
+
15
+ def map_scores(predicted_labels: List[dict], default_label: str):
16
+ mapped_scores = [item['scores'][0] if item['labels'][0]!= default_label else 0 for item in predicted_labels]
17
+ return mapped_scores
18
+
19
+ def get_first_relevant_label(predicted_labels, mapped_scores: List[float], default_label: str):
20
+ for i, value in enumerate(mapped_scores):
21
+ if value != 0:
22
+ return label_map[predicted_labels[i]['labels'][0]], i
23
+ return label_map[default_label], i # Return if all values are zero or the list is empty
24
+
25
+
26
+ def classify(texts: List[str], labels: List[str]):
27
+ predicted_labels = model(texts, labels, multi_label=False)
28
+ print(predicted_labels)
29
+ return predicted_labels
30
+
app/modules/database.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #import redis
2
+ from modules.utils import compare_date_with_today
3
+ import pandas as pd
4
+ import random
5
+ import uuid
6
+
7
+ #load_dotenv('../../.env')
8
+
9
+ #redis_pw = os.getenv("REDIS_PASSWORD")
10
+
11
+ #try:
12
+ # r = redis.Redis(
13
+ # host='redis-12097.c328.europe-west3-1.gce.cloud.redislabs.com',
14
+ # port=12097,
15
+ # password=redis_pw)
16
+ #except:
17
+ # print("Redis not available - working with memory alone")
18
+ # r = None
19
+ #on_memory_user_bank = {}
20
+ #on_memory_boost_bank = load_csv_to_dict('../data/boost_bank.csv')
21
+
22
+ class BoostDatabase:
23
+ def __init__(self, csv_path):
24
+ """Initialize the database by loading boosts from a CSV file."""
25
+ self.boosts_bank = {}
26
+ boosts = pd.read_csv(csv_path)
27
+ for target_topic in boosts['target_topic'].unique():
28
+ subset = boosts.query('target_topic == @target_topic')
29
+ self.boosts_bank[target_topic] = {
30
+ 'twitter': [{'id': str(uuid.uuid4()), 'url': url} for url in subset['url_x'].dropna()],
31
+ 'facebook': [{'id': str(uuid.uuid4()), 'url': url} for url in subset['url_facebook'].dropna()],
32
+ 'reddit': [{'id': str(uuid.uuid4()), 'url': url} for url in subset['url_reddit_new'].dropna()],
33
+ }
34
+
35
+ def get_random_boost(self, topic, platform, blacklist_ids):
36
+ """
37
+ Retrieve a random boost item (URL and UUID) for a given topic and platform,
38
+ excluding any items with UUIDs in the blacklist.
39
+ """
40
+ if topic in self.boosts_bank and platform in self.boosts_bank[topic]:
41
+ # Filter out any items that have an ID in the blacklist
42
+ valid_items = [item for item in self.boosts_bank[topic][platform] if item['id'] not in blacklist_ids]
43
+ if valid_items:
44
+ return random.choice(valid_items)
45
+ else:
46
+ return "No available boosts that haven't been seen."
47
+ else:
48
+ return "Topic or platform not found."
49
+
50
+ class User:
51
+ def __init__(self, user_id: str, last_boost: str, boosts=None):
52
+ if boosts is None:
53
+ boosts = []
54
+ self.user_id = user_id
55
+ self.boosts = boosts
56
+ self.last_boost = last_boost
57
+
58
+ def add_boost(self, boost):
59
+ """Append a new boost to the list of boosts."""
60
+ self.boosts.append(boost)
61
+
62
+ def is_boosted_today(self):
63
+ self.is_boosted_today = compare_date_with_today(self.last_boost)
64
+
65
+ def update_boosted_today(self, status):
66
+ """Update the boosted_today status."""
67
+ self.boosted_today = status
68
+
69
+ def __repr__(self):
70
+ return f"User(boosts={self.boosts}, boosted_today={self.boosted_today})"
71
+
72
+ class UserDatabase:
73
+ def __init__(self):
74
+ self.users = {} # Stores user_id mapped to User objects
75
+
76
+ def add_user(self, user_id, user):
77
+ """Add a new user to the database."""
78
+ if user_id not in self.users:
79
+ self.users[user_id] = user
80
+ else:
81
+ print("User already exists with this ID")
82
+
83
+ def get_user(self, user_id):
84
+ """Retrieve a user by user_id."""
85
+ return self.users.get(user_id, None)
86
+
87
+ def add_boost_to_user(self, user_id, boost):
88
+ """Append a boost to a user's list of boosts."""
89
+ user = self.get_user(user_id)
90
+ if user:
91
+ user.add_boost(boost)
92
+ else:
93
+ print("User not found")
94
+
95
+ def update_user_boosted_today(self, user_id, date):
96
+ """Update the boosted_today status for a user."""
97
+ user = self.get_user(user_id)
98
+ if user:
99
+ user.update_boosted_today(date)
100
+ else:
101
+ print("User not found")
app/modules/load_boost_data.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ def load_csv_to_dict(filename):
2
+ """Loads a CSV file into a list of dictionaries."""
3
+ with open(filename, mode='r', newline='', encoding='utf-8') as file:
4
+ # Create a DictReader object
5
+ dict_reader = csv.DictReader(file)
6
+ # Convert DictReader to a list of dictionaries
7
+ data_list = list(dict_reader)
8
+ return data_list
app/modules/models/api.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from pydantic import BaseModel, Field
3
+ from typing import List, Optional
4
+ from uuid import UUID
5
+
6
+
7
+ class Engagement(BaseModel):
8
+ upvote: int
9
+ downvote: int
10
+ comment: int
11
+ award: int
12
+
13
+ class Item(BaseModel):
14
+ id: UUID
15
+ post_id: Optional[UUID] = None
16
+ parent_id: Optional[UUID] = None
17
+ title: Optional[str] = None
18
+ text: Optional[str] = None
19
+ author_name_hash: str
20
+ type: str
21
+ created_at: str
22
+ engagements: Engagement
23
+
24
+ class Session(BaseModel):
25
+ user_id: UUID
26
+ user_name_hash: str
27
+ platform: str
28
+ current_time: str
29
+
30
+ class Input(BaseModel):
31
+ session: Session
32
+ items: List[Item]
33
+
34
+ class NewItem(BaseModel):
35
+ id: UUID
36
+ url: str
37
+
38
+ class Output(BaseModel):
39
+ ranked_ids: List[UUID]
40
+ new_items: List[Optional[NewItem]]
app/modules/redistribute.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+ from modules.classify import classify, map_scores, get_first_relevant_label
3
+
4
+ labels = ["something else", "headlines, news channels, news articles, breaking news", "politics, policy and politicians", "health care and public health", "religious"]
5
+
6
+
7
+ def redistribute(items):
8
+ predicted_labels = classify(texts=[item.text for item in items], labels=labels)
9
+ mapped_scores = map_scores(predicted_labels=predicted_labels, default_label="something else")
10
+ first_topic, insertion_pos = get_first_relevant_label(predicted_labels=predicted_labels, mapped_scores=mapped_scores, default_label="something else")
11
+ # TODO include parent linking
12
+ print("OK?")
13
+ reranked_ids, _ = distribute_evenly(ids=[item.id for item in items], scores=mapped_scores)
14
+ print(reranked_ids)
15
+ return reranked_ids, first_topic, insertion_pos
16
+
17
+
18
+ def distribute_evenly(ids: List[str], scores: List[float]):
19
+ """
20
+ This method receives a list of ids and a list of scores. Scores distinct to zero get distributed evenly along the list, preserving cardinality.
21
+ """
22
+ # Indices of non-zero scores and total scores length
23
+ non_zero_indices = [i for i, score in enumerate(scores) if score != 0]
24
+ non_zero_count = len(non_zero_indices)
25
+ total_scores = len(scores)
26
+
27
+ if non_zero_count == 0:
28
+ return ids[:], scores[:] # Return copies if no non-zero scores
29
+
30
+ # Calculate new positions for non-zero scores evenly distributed
31
+ interval = total_scores // non_zero_count
32
+ new_positions = [(i * interval) for i in range(non_zero_count)]
33
+
34
+ # Initialize new scores and ids arrays
35
+ new_scores = [0] * total_scores
36
+ new_objects_order = [None] * total_scores
37
+
38
+ # Place the non-zero scores and corresponding objects in the new positions
39
+ for new_pos, old_pos in zip(new_positions, non_zero_indices):
40
+ new_scores[new_pos] = scores[old_pos]
41
+ new_objects_order[new_pos] = ids[old_pos]
42
+
43
+ # Fill in the gaps in the objects list
44
+ used_indices = set(non_zero_indices) # Set for quick lookup
45
+ fill_index = 0 # Tracker for filling positions
46
+
47
+ for i in range(total_scores):
48
+ if new_objects_order[i] is None:
49
+ # Skip indices that have been used
50
+ while fill_index in used_indices:
51
+ fill_index += 1
52
+ if fill_index < total_scores:
53
+ new_objects_order[i] = ids[fill_index]
54
+ fill_index += 1
55
+
56
+ return new_objects_order, new_scores
57
+
58
+
59
+ def insert_element_at_position(lst, element, position):
60
+ """
61
+ Inserts an element at a specific position in the list.
62
+
63
+ Args:
64
+ lst (list): The list to insert the element into.
65
+ element (any): The element to insert into the list.
66
+ position (int): The index at which to insert the element.
67
+
68
+ Returns:
69
+ list: The list with the element inserted.
70
+ """
71
+ # Ensure the position is within the bounds of the list plus one for appending
72
+ position = min(position, len(lst))
73
+
74
+ # Insert the element at the specified position
75
+ lst.insert(position, element)
76
+
77
+ return lst
app/modules/utils.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ from datetime import datetime
3
+
4
+ def load_csv_to_dict(filename):
5
+ """Loads a CSV file into a list of dictionaries."""
6
+ with open(filename, mode='r', newline='', encoding='utf-8') as file:
7
+ # Create a DictReader object
8
+ dict_reader = csv.DictReader(file)
9
+ # Convert DictReader to a list of dictionaries
10
+ data_list = list(dict_reader)
11
+ return data_list
12
+
13
+ def get_stringified_date(date):
14
+ """
15
+ Gets a date like 2024-04-09T19:29:38.072017Z and returns the day
16
+ """
17
+ return str(datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ").date())
18
+
19
+ def compare_date_with_today(date_str):
20
+ # Parse the input date string
21
+ input_date = datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S.%fZ")
22
+
23
+ # Get today's date (without time component)
24
+ today_date = datetime.now().date()
25
+
26
+ # Compare the input date's date component with today's date
27
+ if input_date.date() == today_date:
28
+ return True
29
+ else:
30
+ return False
requirements.txt CHANGED
@@ -6,4 +6,5 @@ python-dotenv
6
  dotenv-cli
7
  pandas
8
  uvicorn
9
- pydantic
 
 
6
  dotenv-cli
7
  pandas
8
  uvicorn
9
+ pydantic
10
+ redis