Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import tweepy
|
| 2 |
-
from transformers import pipeline, GPT2LMHeadModel, GPT2Tokenizer
|
| 3 |
import os
|
| 4 |
import streamlit as st
|
| 5 |
from datetime import datetime
|
|
@@ -141,17 +141,27 @@ def main():
|
|
| 141 |
# Análise de sentimentos
|
| 142 |
with st.spinner('Analisando sentimentos...'):
|
| 143 |
debug_print("Iniciando análise de sentimentos...")
|
|
|
|
|
|
|
| 144 |
sentiment_pipeline = pipeline(
|
| 145 |
-
|
| 146 |
-
model=
|
|
|
|
| 147 |
)
|
| 148 |
|
| 149 |
sentiments = []
|
| 150 |
for tweet in tweets.data:
|
| 151 |
if hasattr(tweet, 'lang') and tweet.lang == 'pt':
|
| 152 |
result = sentiment_pipeline(tweet.text)
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
time.sleep(1)
|
| 157 |
|
|
|
|
| 1 |
import tweepy
|
| 2 |
+
from transformers import pipeline, GPT2LMHeadModel, GPT2Tokenizer, AutoModelForSequenceClassification, AutoTokenizer
|
| 3 |
import os
|
| 4 |
import streamlit as st
|
| 5 |
from datetime import datetime
|
|
|
|
| 141 |
# Análise de sentimentos
|
| 142 |
with st.spinner('Analisando sentimentos...'):
|
| 143 |
debug_print("Iniciando análise de sentimentos...")
|
| 144 |
+
|
| 145 |
+
# Inicializando o pipeline com modelo em português
|
| 146 |
sentiment_pipeline = pipeline(
|
| 147 |
+
"sentiment-analysis",
|
| 148 |
+
model="pierreguillou/bert-base-cased-gs-sentiment-pt",
|
| 149 |
+
tokenizer="pierreguillou/bert-base-cased-gs-sentiment-pt"
|
| 150 |
)
|
| 151 |
|
| 152 |
sentiments = []
|
| 153 |
for tweet in tweets.data:
|
| 154 |
if hasattr(tweet, 'lang') and tweet.lang == 'pt':
|
| 155 |
result = sentiment_pipeline(tweet.text)
|
| 156 |
+
# Mapeando os resultados para positive/negative/neutral
|
| 157 |
+
label = result[0]['label']
|
| 158 |
+
if label == 'POSITIVE':
|
| 159 |
+
sentiments.append('positive')
|
| 160 |
+
elif label == 'NEGATIVE':
|
| 161 |
+
sentiments.append('negative')
|
| 162 |
+
else:
|
| 163 |
+
sentiments.append('neutral')
|
| 164 |
+
debug_print(f"Sentimento analisado: {label}")
|
| 165 |
|
| 166 |
time.sleep(1)
|
| 167 |
|