Spaces:
Runtime error
Runtime error
Commit
·
6efc66a
1
Parent(s):
1bf00e3
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
import tweepy as tw
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
-
import torch
|
5 |
-
import numpy as np
|
6 |
import regex as re
|
7 |
import pysentimiento
|
8 |
import geopy
|
@@ -13,23 +11,10 @@ from pysentimiento.preprocessing import preprocess_tweet
|
|
13 |
from geopy.geocoders import Nominatim
|
14 |
from transformers import pipeline
|
15 |
|
16 |
-
from torch.utils.data import TensorDataset, DataLoader, RandomSampler, SequentialSampler
|
17 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification,AdamW
|
18 |
-
tokenizer = AutoTokenizer.from_pretrained('hackathon-pln-es/twitter_sexismo-finetuned-robertuito-exist2021')
|
19 |
-
model = AutoModelForSequenceClassification.from_pretrained("hackathon-pln-es/twitter_sexismo-finetuned-robertuito-exist2021")
|
20 |
|
21 |
model_checkpoint = "hackathon-pln-es/twitter_sexismo-finetuned-robertuito-exist2021"
|
22 |
pipeline_nlp = pipeline("text-classification", model=model_checkpoint)
|
23 |
|
24 |
-
import torch
|
25 |
-
if torch.cuda.is_available():
|
26 |
-
device = torch.device( "cuda")
|
27 |
-
print('I will use the GPU:', torch.cuda.get_device_name(0))
|
28 |
-
|
29 |
-
else:
|
30 |
-
print('No GPU available, using the CPU instead.')
|
31 |
-
device = torch.device("cpu")
|
32 |
-
|
33 |
|
34 |
consumer_key = "BjipwQslVG4vBdy4qK318KnoA"
|
35 |
consumer_secret = "3fzL70v9faklrPgvTi3zbofw9rwk92fgGdtAslFkFYt8kGmqBJ"
|
@@ -141,7 +126,6 @@ def tweets_localidad(buscar_localidad):
|
|
141 |
location = geolocator.geocode(buscar_localidad)
|
142 |
radius = "10km"
|
143 |
tweets = api.search_tweets(q="",lang="es",geocode=f"{location.latitude},{location.longitude},{radius}", count = 50, tweet_mode="extended")
|
144 |
-
|
145 |
tweet_list = [i.full_text for i in tweets]
|
146 |
text= pd.DataFrame(tweet_list)
|
147 |
text[0] = text[0].apply(preprocess_tweet)
|
@@ -157,6 +141,7 @@ def tweets_localidad(buscar_localidad):
|
|
157 |
result.append(etiqueta)
|
158 |
df = pd.DataFrame(result)
|
159 |
df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
|
|
|
160 |
#df['Probabilidad'] = df['Probabilidad'].apply(lambda x: '{:.2f}%'.format(x))
|
161 |
#df.sort_values(by='Probabilidad', ascending=False, inplace=True)
|
162 |
#df = df.sort_values(by=['Probabilidad', 'Prediccion'], ascending=[False, False])
|
|
|
1 |
import tweepy as tw
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
|
|
|
|
4 |
import regex as re
|
5 |
import pysentimiento
|
6 |
import geopy
|
|
|
11 |
from geopy.geocoders import Nominatim
|
12 |
from transformers import pipeline
|
13 |
|
|
|
|
|
|
|
|
|
14 |
|
15 |
model_checkpoint = "hackathon-pln-es/twitter_sexismo-finetuned-robertuito-exist2021"
|
16 |
pipeline_nlp = pipeline("text-classification", model=model_checkpoint)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
consumer_key = "BjipwQslVG4vBdy4qK318KnoA"
|
20 |
consumer_secret = "3fzL70v9faklrPgvTi3zbofw9rwk92fgGdtAslFkFYt8kGmqBJ"
|
|
|
126 |
location = geolocator.geocode(buscar_localidad)
|
127 |
radius = "10km"
|
128 |
tweets = api.search_tweets(q="",lang="es",geocode=f"{location.latitude},{location.longitude},{radius}", count = 50, tweet_mode="extended")
|
|
|
129 |
tweet_list = [i.full_text for i in tweets]
|
130 |
text= pd.DataFrame(tweet_list)
|
131 |
text[0] = text[0].apply(preprocess_tweet)
|
|
|
141 |
result.append(etiqueta)
|
142 |
df = pd.DataFrame(result)
|
143 |
df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
|
144 |
+
#df['Tweets'] = df['Tweets'].str.replace('RT|@', '')
|
145 |
#df['Probabilidad'] = df['Probabilidad'].apply(lambda x: '{:.2f}%'.format(x))
|
146 |
#df.sort_values(by='Probabilidad', ascending=False, inplace=True)
|
147 |
#df = df.sort_values(by=['Probabilidad', 'Prediccion'], ascending=[False, False])
|