Kingston Yip commited on
Commit
39a4d7e
·
1 Parent(s): 664aa80
Files changed (2) hide show
  1. app.py +12 -8
  2. saved_tweets.txt +0 -0
app.py CHANGED
@@ -5,7 +5,6 @@ import pandas as pd
5
  import comments
6
  from random import randint
7
 
8
-
9
  def predict_cyberbullying_probability(sentence, tokenizer, model):
10
  # Preprocess the input sentence
11
  inputs = tokenizer(sentence, padding='max_length', return_token_type_ids=False, return_attention_mask=True, truncation=True, max_length=512, return_tensors='pt')
@@ -79,16 +78,21 @@ with st.form("my_form"):
79
  default = "I'm nice at ping pong"
80
  tweet = st.text_area(label="Enter Text:",value=default)
81
  submitted = st.form_submit_button("Analyze textbox")
82
- random = st.form_submit_button("Analyze a random 😈😈😈 tweet")
83
 
84
  if random:
85
  tweet = comments.comments[randint(0, 354)]
86
  st.write(tweet)
87
-
88
-
89
- df = perform_cyberbullying_analysis(tweet)
90
-
91
- # Display the cached table
92
- st.table(df)
 
 
 
 
 
93
  else:
94
  perform_default_analysis(model_name)
 
5
  import comments
6
  from random import randint
7
 
 
8
  def predict_cyberbullying_probability(sentence, tokenizer, model):
9
  # Preprocess the input sentence
10
  inputs = tokenizer(sentence, padding='max_length', return_token_type_ids=False, return_attention_mask=True, truncation=True, max_length=512, return_tensors='pt')
 
78
  default = "I'm nice at ping pong"
79
  tweet = st.text_area(label="Enter Text:",value=default)
80
  submitted = st.form_submit_button("Analyze textbox")
81
+ random = st.form_submit_button("Generate and analyze a 😈 tweet (warning!!)")
82
 
83
  if random:
84
  tweet = comments.comments[randint(0, 354)]
85
  st.write(tweet)
86
+ submitted = True
87
+
88
+ if submitted:
89
+ # first write the tweet to a file
90
+ with open("saved_tweets.txt", "a") as f:
91
+ f.write(tweet)
92
+ f.write("\n")
93
+
94
+
95
+ df = perform_cyberbullying_analysis(tweet)
96
+ st.table(df)
97
  else:
98
  perform_default_analysis(model_name)
saved_tweets.txt ADDED
File without changes