Joshua1808 commited on
Commit
fc3e5ca
·
1 Parent(s): 33703fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -2
app.py CHANGED
@@ -68,7 +68,62 @@ def run():
68
  error=True
69
  elif ( termino == True and usuario == True):
70
  st.text('Error se han seleccionado los dos check')
71
- error=True
72
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  run()
 
68
  error=True
69
  elif ( termino == True and usuario == True):
70
  st.text('Error se han seleccionado los dos check')
71
+ error=True
72
+
73
+ if (error == False):
74
+ if (termino):
75
+ new_search = search_words + " -filter:retweets"
76
+ tweets =tw.Cursor(api.search_tweets,q=new_search,lang="es",since=date_since).items(number_of_tweets)
77
+ elif (usuario):
78
+ tweets = api.user_timeline(screen_name = search_words,count=number_of_tweets)
79
+
80
+ tweet_list = [i.text for i in tweets]
81
+ #tweet_list = [strip_undesired_chars(i.text) for i in tweets]
82
+ text= pd.DataFrame(tweet_list)
83
+ #text[0] = text[0].apply(preprocess)
84
+ text[0] = text[0].apply(preprocess_tweet)
85
+ text1=text[0].values
86
+ indices1=tokenizer.batch_encode_plus(text1.tolist(),
87
+ max_length=128,
88
+ add_special_tokens=True,
89
+ return_attention_mask=True,
90
+ pad_to_max_length=True,
91
+ truncation=True)
92
+ input_ids1=indices1["input_ids"]
93
+ attention_masks1=indices1["attention_mask"]
94
+ prediction_inputs1= torch.tensor(input_ids1)
95
+ prediction_masks1 = torch.tensor(attention_masks1)
96
+ # Set the batch size.
97
+ batch_size = 25
98
+ # Create the DataLoader.
99
+ prediction_data1 = TensorDataset(prediction_inputs1, prediction_masks1)
100
+ prediction_sampler1 = SequentialSampler(prediction_data1)
101
+ prediction_dataloader1 = DataLoader(prediction_data1, sampler=prediction_sampler1, batch_size=batch_size)
102
+ print('Predicting labels for {:,} test sentences...'.format(len(prediction_inputs1)))
103
+ # Put model in evaluation mode
104
+ model.eval()
105
+ # Tracking variables
106
+ predictions = []
107
+ # Predict
108
+ for batch in prediction_dataloader1:
109
+ batch = tuple(t.to(device) for t in batch)
110
+ # Unpack the inputs from our dataloader
111
+ b_input_ids1, b_input_mask1 = batch
112
+ # Telling the model not to compute or store gradients, saving memory and # speeding up prediction
113
+ with torch.no_grad():
114
+ # Forward pass, calculate logit predictions
115
+ outputs1 = model(b_input_ids1, token_type_ids=None,attention_mask=b_input_mask1)
116
+ logits1 = outputs1[0]
117
+ # Move logits and labels to CPU
118
+ logits1 = logits1.detach().cpu().numpy()
119
+ # Store predictions and true labels
120
+ predictions.append(logits1)
121
+ flat_predictions = [item for sublist in predictions for item in sublist]
122
+ flat_predictions = np.argmax(flat_predictions, axis=1).flatten()#p = [i for i in classifier(tweet_list)]
123
+ df = pd.DataFrame(list(zip(tweet_list, flat_predictions)),columns =['Últimos '+ str(number_of_tweets)+' Tweets'+' de '+search_words, 'Sexista'])
124
+ df['Sexista']= np.where(df['Sexista']== 0, 'No Sexista', 'Sexista')
125
+
126
+
127
+ st.table(df.reset_index(drop=True).head(20).style.applymap(color_survived, subset=['Sexista']))
128
 
129
  run()